先删除掉之前安装的奇怪的东西

apt-get remove apache2
apt-get remove php5
apt-get remove mysql-server mysql-client

然后依次执行下面这些,有Yes打Yes,有Y打Y,有回车按回车……

apt-get update
apt-get install software-properties-common
add-apt-repository ppa:nginx/stable
add-apt-repository ppa:ondrej/php
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/10.1/ubuntu trusty main'
apt-get update
apt-get install nginx-extras
apt-get install php7.0-fpm php7.0-gd php7.0-mysql php7.0-mcrypt php7.0-mbstring php7.0-curl
apt-get install mariadb-server

注意最后一行执行时会要求输入密码,选一个强度高的密码作为数据库密码

然后来配置数据库,执行后输入密码回车

mysql -u root -p

进入新的控制界面输入下面三行,注意替换掉自己的密码,3处的wordpress字符可以自己替换成想要的名字,作为数据库名和用户名

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY '你的密码';
FLUSH PRIVILEGES;

全部完成后应该提示如下:

MariaDB [(none)]> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY '我的密码';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

然后输入exit回车退出

在/etc/nginx/sites-enabled/下新建一个文件,比如我叫wordpress,内容如下(注意替换域名、文件夹):

server {
		listen 80;
		server_name 域名;
		root /var/www/文件夹;

		index index.html index.htm index.php;

		location / {
				try_files $uri $uri/ /index.php?$args;
		}

		location ~ \.php$ {
				include snippets/fastcgi-php.conf;
				fastcgi_pass unix:/run/php/php7.0-fpm.sock;
		}
}

然后去/var/www目录下新建个文件夹作为网站根目录,目录名字要和上面文件夹名一样,把解压出来的wordpress或者其他什么东西扔进这个文件夹里。此时/var/www目录下应该是这样

root@iZwz92h5ju8ndx9mwktamzZ:/var/www# ll
total 16
drwxr-xr-x  4 root   root    4096 Mar 22 21:48 ./
drwxr-xr-x 12 root   root    4096 Mar 22 21:14 ../
drwxr-xr-x  2 root   root    4096 Mar 22 21:14 html/
drwxr-xr-x  5 nobody nogroup 4096 Mar  7 13:14 wordpress/

修改文件夹权限:

chown -R www-data:www-data /var/www/wordpress

最后重启一下nginx和php:

restart php7.0-fpm
restart nginx

打开你的网站吧~