在CentOS系统上从零开始搭建WordPress博客的全流程记录
<p><strong>概述</strong></p>
<p>
最近买了台服务器,准备搭建个人博客,来持续更新自己的博客,</p>
<p>
<strong>环境</strong></p>
<ul>
<li>
服务器操作系统:CentOS 7.0</li>
<li>
博客部署服务器:Apache</li>
<li>
后台语言:PHP</li>
<li>
数据库:MySql</li>
<li>
前端框架:WordPress
</li>
</ul>
<p>
<strong>步骤</strong></p>
<p>
<strong>一、安装Apache</strong></p>
<p>
安装 Apache 很简单,只需要在终端输入以下命令就可以了:</p>
<div>
<div>
<div id="highlighter_401154">
<div>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>sudo</code> <code>yum </code><code>install</code> <code>httpd</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
sudo 的意思是用 root 用户做什么操作,yum install 是在线安装;然后输入 yes 就确认下载安装了。</p>
<p>
安装完毕之后我们需要启动服务:</p>
<div>
<div>
<div id="highlighter_615465">
<div>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>sudo</code> <code>service httpd start</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
当启动服务器完成之后,先别着急往下弄,可以直接在浏览器中输入服务器的 ip 地址,应该就可以看到 Apache 的欢迎页面了。</p>
<p>
This page is used to test the operation of the Apache HTTP server after it has been installed………等等</p>
<p>
如果你的 ip 地址已经和域名绑定了,那么在浏览器中输入你的域名也可以访问了,是不是很酷,就是这么简单,咱们继续。</p>
<p>
<strong>二、安装 MySql</strong></p>
<p>
安装 MySql,并启动 MySql</p>
<div>
<div>
<div id="highlighter_128425">
<div>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
<div>
2</div>
<div>
3</div>
</td>
<td>
<div>
<div>
<code>sudo</code> <code>yum </code><code>install</code> <code>mysql-server</code>
</div>
<div>
<code> </code>
</div>
<div>
<code>sudo</code> <code>service mysqld start</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
通过上面的命令就可以安装并启动了 mysql,安装 mysql 的时候会询问你一些简单的配置,输入 enter 和 yes 一路下来就 OK 了。</p>
<p>
<strong>三、安装 PHP 以及相关 PHP 组件</strong></p>
<p>
先安装 PHP</p>
<div>
<div>
<div id="highlighter_591179">
<div>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>sudo</code> <code>yum </code><code>install</code> <code>php php-mysql</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
安装 PHP 相关组件</p>
<div>
<div>
<div id="highlighter_426581">
<div>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>yum </code><code>install</code> <code>php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
我先安装了这几个组件,为以后使用,你要想了解所有的 PHP 组件的话,可以使用如下命令搜索:</p>
<div>
<div>
<div id="highlighter_570399">
<div>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>yum search php-</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
<strong>四、开机默认启动 Apache 和 Mysql 服务</strong></p>
<p>
使用如下命令即可选择开机启动 Apache 和 Mysql:</p>
<div>
<div>
<div id="highlighter_73423">
<div>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
<div>
2</div>
<div>
3</div>
</td>
<td>
<div>
<div>
<code>sudo</code> <code>chkconfig http on</code>
</div>
<div>
</div>
<div>
<code>sudo</code> <code>chkconfig mysql on</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
<strong>五、测试 PHP 是否安装成功</strong></p>
<p>
建立一个 info.php 文件:</p>
<div>
<div>
<div id="highlighter_69162">
<div>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>sudo</code> <code>vim </code><code>/var/www/html/info</code><code>.php</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
然后输入 i 进入编辑模式,在文件中写入下面的 PHP 命令:</p>
<div>
<div>
<div id="highlighter_530437">
<div>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
<div>
2</div>
<div>
3</div>
</td>
<td>
<div>
<div>
<code><php</code>
</div>
<div>
<code>phpinfo();</code>
</div>
<div>
<code>></code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
然后按 esc 键进入命令模式, 按下 Shift 键和两次 z 键,就退出保存文件。</p>
<p>
在浏览器中输入 IP地址/info.php,例如:123.56.183.34/info.php 回车,就可以看到 PHP 的信息了。</p>
<p>
<strong>六、下载 WordPress</strong></p>
<p>
可以到https://wordpress.org/官网上去翻,或通过下面的命令下载:</p>
<div>
<div>
<div id="highlighter_353753">
<div>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>wget http:</code><code>//cn</code><code>.wordpress.org</code><code>/wordpress-3</code><code>.9-zh_CN.zip</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
<strong>七、解压</strong></p>
<p>
使用 unzip 来解压文件:</p>
<div>
<div>
<div id="highlighter_416681">
<div>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>unzip wordpress-3.8-zh_CN.zip</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
<strong>八、在 Mysql 中新建数据库</strong></p>
<div>
<div>
<div id="highlighter_485040">
<div>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>mysql -u root -p</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
通过上面的命令进入数据库,然后输入密码:password</p>
<p>
然后创建一个叫 wordpress 的数据库</p>
<div>
<div>
<div id="highlighter_247930">
<div>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>create</code> <code>database</code> <code>wordpress;</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
<strong>九、修改 wp-content.php 文件</strong></p>
<p>
按照下面的形式修改 wp-content.php 文件,</p>
<div>
<div>
<div id="highlighter_272724">
<div>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
<div>
2</div>
<div>
3</div>
<div>
4</div>
<div>
5</div>
<div>
6</div>
<div>
7</div>
<div>
8</div>
</td>
<td>
<div>
<div>
<code>/** MySQL数据库名:wordpress */</code>
</div>
<div>
<code>define(‘DB_NAME</code><code>', ‘wordpress'</code><code>); </code>
</div>
<div>
<code>/** MySQL数据库用户名 :root*/</code>
</div>
<div>
<code>define(‘DB_USER</code><code>', ‘root'</code><code>); </code>
</div>
<div>
<code>/** MySQL数据库密码 :password*/</code>
</div>
<div>
<code>define(‘DB_PASSWORD</code><code>', ‘password'</code><code>);</code>
</div>
<div>
<code>/** MySQL主机(不用修改) */</code>
</div>
<div>
<code>define(‘DB_HOST</code><code>', ‘localhost'</code><code>);</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
<strong>十、把文件复制到 /var/www/html 目录下</strong></p>
<div>
<div>
<div id="highlighter_767299">
<div>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>cp</code> <code>-rf wordpress/* </code><code>/var/www/html/</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
<strong>十一、测试</strong></p>
<p>
在浏览器中输入服务器的 ip 即可查看到自己主页。</p>
頁:
[1]