这里说的是本身从 wordpress 源码开始搭建一个我的博客系统。固然,不少云端已经直接提供了在线安装的方式,这个就不在本文的讨论范围以内了。php
wordpress是一款我的博客系统,并逐步演化成一款内容管理系统软件,它是使用PHP语言和MySQL数据库开发的,用户能够在支持 PHP 和 MySQL数据库的服务器上使用本身的博客。html
总之是为众多的开源博客系统之一,也绝对是一部良心之做。在这里向做者以及贡献者致敬。本文主要讲述的是从 wordpress 源码进行安装,固然是要从 wordpress 官网这里去将其下载下来的。下载下来的是一个压约缩包,须要咱们本身将其解压出来。mysql
wordpress 虽然只是一个我的博客系统,但其也是一个服务端系统。要安装 wordpress 就须要先安装相应的基础设施,php,mysql 以及 apache。不过这些在 Mac 上已经安装好了。咱们要作的是执行相应的命令行查看一下版本是否符合。web
查看Apache版本sql
$ apachectl -version
Server version: Apache/2.4.34 (Unix)
Server built: Feb 22 2019 19:30:04
复制代码
相看php版本数据库
$ php -v
PHP 7.1.23 (cli) (built: Feb 22 2019 22:08:13) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
复制代码
启动 Apacheapache
$ sudo apachectl start
复制代码
关闭 Apachevim
$ sudo apachectl stop
复制代码
重启 Apache浏览器
$ sudo apachectl restart
复制代码
起用 php 开启PHP,须要修改Apache配置文件,终端下(固然,你也能够直接在 Finder 中找到路径并用文本编辑器进行):bash
sudo vim /etc/apache2/httpd.conf
复制代码
去掉以下配置的注释即为起动 php。
LoadModule php7_module libexec/apache2/libphp7.so
复制代码
结果以下图
默认状况下 Apache 的目录为 /Library/WebServer/Documents,咱们固然但愿 wordpress 应该工做在本身的独立目录下。假设咱们已经把面下载并解压好的 wordpress 目录拷贝到 /Library/WebServer/Documents。那咱们只要在 /etc/apache2/httpd.conf 再修改 DocumentRoot 的配置。
DocumentRoot "/Library/WebServer/Documents/wordpress"
<Directory "/Library/WebServer/Documents/wordpress">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options FollowSymLinks Multiviews
MultiviewsMatch Any
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
复制代码
如上,咱们在 /Library/WebServer/Documents 后面添加本身的目录 wordpress。而后再重启一下 Apache 服务。
apachectl restart
复制代码
重启服务后,在浏览器的地址栏输入:
localhost
复制代码
便可出现以下页面,就表明已经配置成功了。
注意,此响应的实际上是
http://localhost/index.php
复制代码
而且它会自动跳转到/wp-admin/setup-config.php。
http://localhost/wp-admin/setup-config.php
复制代码
上面图中,告诉了咱们要安装 wordpress ,所须要的 Mysql 服务及相关的配置
Database name Database username Database password Database host Table prefix (if you want to run more than one WordPress in a single database)
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 复制代码
查看一下Mysql
$ mysql --version
mysql Ver 14.14 Distrib 5.7.20, for osx10.13 (x86_64) using EditLine wrapper
复制代码
但这个并非 Mysql 的服务端,这是客户端。咱们应该这样来看是否已经安装了服务端。
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
复制代码
若是你不能进入到 Mysql 的控制台,说明你尚未安装好Mysql,那若是没有安装好的话就请去Mysql的官网下载吧。下载免费的社区版便可知足需求。若是已经安装就经过“系统偏好设置”来启动Mysql服务。固然要启动了该服务,才能进入到上面所说的Mysql控制台。
新建并配置数据库 新建数据库这个就不在这里讲述了,假设咱们建立了一个数据库为 wordpress,空的就行。而后用 subline 等纯文本编辑工具打开以前存放在/Library/WebServer/Documents下面的 wordpress/wp-config-sample.php。并修改以下内容。
Database name Database username Database password Database host
样例以下:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );
/** MySQL database username */
define( 'DB_USER', 'wordpress' );
/** MySQL database password */
define( 'DB_PASSWORD', 'wordpress123456' );
/** MySQL hostname */
define( 'DB_HOST', '127.0.0.1:/var/run/mysqld/mysqld.sock' );
复制代码
注意上面的 DB_HOST 最好和做者改为同样的,不要直接用 localhost ,否则可能会链接不上。 而后将修改后的文件另存为 wp-config.php。这就完成了数据库的配置。
前面啰嗦了一大堆,终于把要准备的环境准备好了,接下就在浏览器的地址栏输入http://localhost/wp-admin/install.php ,而后按照向导完成安装便可大功告成了。
WordPress 是一款很是优秀的我的博客系统,而且仍是开源的,可谓是很是良心了。而其实其安装也是很是简单的,总结下来就是: 1.安装好 php。 2.安装好 Mysql,固然,主要是指服务端。创建一个空的数据库,如 wordpress。 3.安装一个 HTTP 服务器,如 Apache。
文章很是简单,但愿能给有须要的同窗一些帮助,谢谢。