安装Nginx

我安装的是lite版官方镜像,默认预装了Apache2,所以这里先卸载Apache2,然后安装Nginx

apt-get remove –purge apache* -y
apt-get autoremove –purge -y
apt-get install nginx

安装PHP7及插件

apt-get install php7.0 php7.0-fpm php7.0-mysql php7.0-common

安装MySQL(MariaDB)

反正差不多,就直接用了

apt-get install mysql-server

查看Nginx连接到php服务的形式

这里主要是查看连接形式是tcp模式还是socket模式。
找到www.conf文件,位置:/etc/php/7.0/fpm/pool.d/
找到listen =这一行,如果是xxx.sock则是socket模式,如果是27.0.0.1则是TCP模式,可自行更改

配置Nginx

路径:/etc/nginx/sites-available/
找到对应的行数,该加的加,该改的改,可百度更加详细的配置

index index.php
location ~ .php$ {
include snippets/fastcgi-php.conf;
root /var/www/html;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000; #因为我使用的是socket模式,所以注释这一句
}

配置MySQL(MariaDB)

首先解决远程问题

编辑/etc/mysql/mariadb.conf.d/50-server.cnf文件,将bind-address = 127.0.0.1改为bind-address = 0.0.0.0

修改密码

控制台输入mysql -u root
进入mysql控制台
输入命令修改密码

use mysql;
update user set authentication_string=password(‘123456’) where user=’root’;

如果远程还是无法登陆的话,尝试如下

update user set host = ‘%’ where user = ‘root’;
update user set plugin=’mysql_native_password’ where user=’root’;

最后

重启服务