前言

很久没更了,首先悼念公司人士变动又走了两位大神同事jl,crvv。

我也因此有机会做些其它的事情,比如前后端代码的锻炼以及这几天公司主页迁移和部署。

Install WordPress with LAMP on Ubuntu 16.04

过程比较曲折,因为先后在 AWS, Azure cn, RackSpace 上部署 WordPress,优先考虑的都是从各平台现有的 Image Market 上找现成的 Image 来直接生成部署好的 Server,然而除了 AWS,其它都不太好用,比如服务器登陆不好使,WordPress 登陆不好使,MySQL 登陆不好使之类的,因为最终生成的这些用户名和密码可能跟你初始化时设置的不一样(Azure cnServer 的登陆密码就和我设的不一样,我反复试了三次,确认不是自己的问题),或者根本就没给你机会设置(RackSpaceWordPress的登陆密码就没有地方初始化,之后尝试通过邮箱找回密码也是跪的)。

为了全部在自己掌控之中,避免后续其它尴尬的问题的出现,我还是决定自己从头搞。

Set Up Linux Server ( Ubuntu 16.04)

随便找个云平台撸一台 Ubuntu 16.04 主机就好了。
Azure 可以在装机时初始化用户名称,但是公司域名 hold 在国内服务器必须要备案,所以我用的 RackSpace,但RackSpace默认只有 root 用户。基于不要随便 root 给自己挖坑的良好习惯,新建 Sudo 用户好了。

Install AMP

这篇文章比较靠谱,照着撸一遍就好了,重点摘要如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
# install apache2

sudo -S -p '' apt-get update
sudo -S -p '' apt-get install apache2

# install MySQL
sudo -S -p '' apt-get install mysql-server

# install PHP
sudo -S -p '' apt-get install php libapache2-mod-php php-mcrypt php-mysql

# restart Apache to implement changes
sudo -S -p '' systemctl restart apache2

Install WordPress

主要综合这两篇文章的内容:

具体如下:

Create a MySQL Database and User for WordPress

WordPress添加 数据库用户

1
mysql -u root -p
1
2
3
4
5
6
7
8
9
CREATE DATABASE wordpress;

CREATE USER changetoyouruser@localhost IDENTIFIED BY 'changetoyourpwd';

GRANT ALL PRIVILEGES ON wordpress.* TO changetoyouruser@localhost;

FLUSH PRIVILEGES;

exit

Install Additional PHP Extensions

安装 PHP 插件

1
2
3
sudo -S -p '' apt-get update
sudo -S -p '' apt-get install php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc
sudo -S -p '' systemctl restart apache2

Adjust Apache’s Configuration to Allow for .htaccess Overrides and Rewrites

编辑 apache2 的配置文件

1
2
# Enable .htaccess Overrides
sudo -S -p '' vi /etc/apache2/apache2.conf

在文件末尾加上:

1
2
3
<Directory /var/www/html/>
AllowOverride All
</Directory>

其它操作

1
2
3
4
5
6
7
8
# Enable the Rewrite Module
sudo -S -p '' a2enmod rewrite

# Enable the Changes
sudo -S -p '' apache2ctl configtest

# Restart Apache to implement the changes
sudo -S -p '' systemctl restart apache2

Download WordPress

下载WordPress

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Change into a writable directory and then download the compressed release by typing
cd /tmp
curl -O https://wordpress.org/latest.tar.gz

# Extract the compressed file to create the WordPress directory structure
tar xzvf latest.tar.gz

# add a dummy .htaccess file
touch /tmp/wordpress/.htaccess

# Copy over the sample configuration file to the filename that WordPress actually reads
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

# Create the upgrade directory, so that WordPress won't run into permissions issues when trying to do this on its own following an update to its software
mkdir /tmp/wordpress/wp-content/upgrade

# Copy the entire contents of the directory into our document root.
# Using the -a flag to make sure our permissions are maintained.
sudo -S -p '' cp -a /tmp/wordpress/. /var/www/html

# 这里 user 和 group 一定要是 www-data,不然权限会有问题
# 这里一定要 755, 644会有问题
sudo -S -p '' chown -R www-data:www-data /var/www/html
sudo -S -p '' chmod 755 -R /var/www/html/

# To grab secure values from the WordPress secret key generator EACH TIME!
curl -s https://api.wordpress.org/secret-key/1.1/salt/

curl 结果类似如下:

1
2
3
4
5
6
7
8
define('AUTH_KEY',         '1jl/vqfs<XhdXoAPz9 DO NOT COPY THESE VALUES c_j{iwqD^<+c9.k<J@4H');
define('SECURE_AUTH_KEY', 'E2N-h2]Dcvp+aS/p7X DO NOT COPY THESE VALUES {Ka(f;rv?Pxf})CgLi-3');
define('LOGGED_IN_KEY', 'W(50,{W^,OPB%PB<JF DO NOT COPY THESE VALUES 2;y&,2m%3]R6DUth[;88');
define('NONCE_KEY', 'll,4UC)7ua+8<!4VM+ DO NOT COPY THESE VALUES #`DXF+[$atzM7 o^-C7g');
define('AUTH_SALT', 'koMrurzOA+|L_lG}kf DO NOT COPY THESE VALUES 07VC*Lj*lD&?3w!BT#-');
define('SECURE_AUTH_SALT', 'p32*p,]z%LZ+pAu:VY DO NOT COPY THESE VALUES C-?y+K0DK_+F|0h{!_xY');
define('LOGGED_IN_SALT', 'i^/G2W7!-1H2OQ+t$3 DO NOT COPY THESE VALUES t6**bRVFSD[Hi])-qS`|');
define('NONCE_SALT', 'Q6]U:K?j4L%Z]}h^q7 DO NOT COPY THESE VALUES 1% ^qUswWgn+6&xqHN&%');

请不要直接复制以上例子,以实际curl结果为准,粘贴到wp-config.php中适当位置

1
vi /var/www/html/wp-config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
. . .

define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');

. . .

在该文件中继续配置数据库相关内容:

1
2
3
4
5
6
7
8
9
10
11
. . .

define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'changetoyouruser');

/** MySQL database password */
define('DB_PASSWORD', 'changetoyourpwd');

. . .

在该文件最后添加如下配置,给 Web Server 写权限

1
define('FS_METHOD', 'direct');

最后,在浏览器中登陆服务器的ip或域名,通过GUI完成后续初始化。