参考:https://ubuntu.com/tutorials/install-and-configure-wordpress

Install Dependencies

以下均为以root身份直接运行。先用apt更新一下包列表和已安装的包,然后安装apache2、mysql和php。

apt update
apt upgrade
apt install apache2 \
    ghostscript \
    libapache2-mod-php \
    mysql-server \
    php \
    php-bcmath \
    php-curl \
    php-imagick \
    php-intl \
    php-json \
    php-mbstring \
    php-mysql \
    php-xml \
    php-zip

Install WordPress

这一步就是创建一个新的目录,用chown把它送给www-data用户,然后用curl下载wordpress压缩包并且直接解压到/srv/www目录里去,这之后会多出一个/srv/www/wordpress目录,里面包括wordpress的各种php文件们。

mkdir -p /srv/www
chown www-data: /srv/www
curl https://wordpress.org/latest.tar.gz | sudo -u www-data tar zx -C /srv/www

Configure Apache for WordPress

vim /etc/apache2/sites-available/wordpress.conf

内容为:

<VirtualHost *:80>
    DocumentRoot /srv/www/wordpress
    <Directory /srv/www/wordpress>
        Options FollowSymLinks
        AllowOverride Limit Options FileInfo
        DirectoryIndex index.php
        Require all granted
    </Directory>
    <Directory /srv/www/wordpress/wp-content>
        Options FollowSymLinks
        Require all granted
    </Directory>
</VirtualHost>

禁止原来的默认网站根目录,将WordPress目录设为默认的网站根目录

a2ensite wordpress
a2enmod rewrite
a2dissite 000-default
service apache2 reload
# systemctl reload apache2

Configure database

这一步主要是创建一个叫wordpress的数据库和一个叫wordpress@localhost的用户,记得给用户设个密码(此处用<your-password>代替)。然后把wordpress数据库的所有编辑权限授予给wordpress@localhost用户。退出就好了。

mysql -u root

$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)

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> CREATE DATABASE wordpress;
Query OK, 1 row affected (0,00 sec)

mysql> CREATE USER wordpress@localhost IDENTIFIED BY '<your-password>';
Query OK, 1 row affected (0,00 sec)

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
    -> ON wordpress.*
    -> TO wordpress@localhost;
Query OK, 1 row affected (0,00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 1 row affected (0,00 sec)

mysql> quit
Bye

启动mysql

service mysql start

Configure WordPress to connect to the database

编辑或修改/srv/www/wordpress/wp-config.php文件(注意把<your-password>替换成你在mysql里设置的真实的密码)。其实这一步就是把wp-config-sample.php复制成wp-config.php文件,然后把里面预设的三个信息改成真实的:数据库名字、用户名、用户密码。

sudo -u www-data cp /srv/www/wordpress/wp-config-sample.php /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/database_name_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/username_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/password_here/<your-password>/' /srv/www/wordpress/wp-config.php

sudo -u www-data vim /srv/www/wordpress/wp-config.php(可以先不执行)

修改如下内容:

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' );

Configure WordPress

在云服务器控制台添加80端口到安全组

在浏览器访问主机ip可图形化配置

注意用设置好的电子邮箱登录