Fork me on GitHub

Apache2部署WordPress

WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站。功能强大、扩展性强,这主要得益于其插件众多,易于扩充功能,基本上一个完整网站该有的功能,通过其第三方插件都能实现所有功能。


环境及版本

1
2
3
4
Ubuntu 14.04 LTS x64
MySQL 5.5
Apache 2.4.7
WordPress 4.5.2-zh_CN

安装MySQL

1
sudo apt-get install mysql-server

安装过程中会有几个设置选项:

  • New password for the MySQL “root” user:

  • Repeat password for the MySQL “root” user:

测试MySQL安装成功:

1
mysql -u root -p
1
2
3
4
5
6
7
8
9
10
11
12
13
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 42
Server version: 5.5.49-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2016, 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>

安装Apache2

1
sudo apt-get install apache2

浏览器地址中输入:

http://localhost/ 或者 http://127.0.0.1

看到Apache2主页

  • 常见问题:

Apache2重启时遇到

1
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message

解决:

1
2
3
4
5
6
7
sudo vim /etc/apache2/apache2.conf

# 输入一下内容
ServerName 127.0.0.1

# 重启Apache2
sudo service apache2 restart

安装php5

1
sudo apt-get install php5

安装PHP其他模块

1
2
# MySQL连接
sudo apt-get install php5-mysql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 安装phpMyAdmin
sudo apt-get install phpMyAdmin

# Web server to reconfigure automatically
# 选择Apache2

# Configure database for phpmyadmin with dbconfig-common? # Yes

# Password of the database's administrative user:
# MySQL application password for phpmyadmin:
# Password confirmation:

# 创建连接
sudo ln -s /usr/share/phpmyadmin /var/www/html

测试PHP和phpMyAdmin安装成功

  • PHP测试
1
2
3
4
5
cd /var/www/html

sudo vim test.php

# 加入Hello PHP! 保存退出

浏览器输入:

1
http://localhost/test.php
  • phpMyAdmin测试

浏览器输入:

1
2
3
http://localhost/phpmyadmin

# 进入登录页面

安装WordPress

官网下载WordPress

  • 解压WordPress
1
sudo tar -zxvf wordpress-4.5.2-zh_CN.tar.gz -C /var/www/html/
  • 创建数据库
1
2
3
4
5
6
7
8
9
# 登录MySQL
mysql -u root -p

# 创建数据库
create database db_wp;

# 查看数据库

show databases;
  • 配置WordPress

浏览器输入:

http://localhost/wordpress

  • 现在就开始
1
2
3
4
5
数据库名
数据库用户名
数据库密码
数据库主机
数据库表前缀
  • 抱歉,我不能写入wp-config.php文件
  • 您可以手工创建wp-config.php文件并将以下信息贴入其中
1
2
3
4
5
6
7
8
9
sudo vim /var/www/html/wordpress/wp-config.php

# 将浏览器上的内容复制进去

# 将编码格式改成utf8
/** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8');

# 保存退出,浏览器进行安装
  • 设置WordPress基本信息
1
2
3
4
站点标题
用户名
密码
电子邮箱
  • 登录后进入后台仪表盘,安装结束!

转载请注明出处


Thank you for your support.