步骤一:安装Nginx
$ sudo apt update
$ sudo apt install nginx
步骤二:安装PHP和配置Nginx使用PHP处理器。
$ sudo apt install php-fpm php-mysql
步骤三:配置Nginx使用PHP处理器
Nginx.conf配置文件
server {
listen 80;
server_name 127.0.0.1;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /var/www/html;
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/html;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
server{
listen 80 default_server;
server_name _;
return 403;
}
步骤四:安装MySQL数据库
$ sudo apt install mysql-server-5.7
1,查看用户:select user,authentication_string,plugin,host from mysql.user;
2,设置密码及更改验证方式:
alter user `root`@`localhost` identified with mysql_native_password by '密码';
3,修改任何主机可连接:
update mysql.user set host='%' where user='root';
4,flush privileges;
5,修改配置文件:
找到bind-address = 127.0.0.1这一行
改为bind-address = 0.0.0.0即可
步骤五:允许远程连接mysql
一,修改/etc/mysql/my.conf
找到bind-address = 127.0.0.1这一行
改为bind-address = 0.0.0.0即可
二、为需要远程登录的用户赋予权限
1、新建用户远程连接mysql数据库
grant all on *.* to admin@'%' identified by '123456' with grant option;
flush privileges;
允许任何ip地址(%表示允许任何ip地址)的电脑用admin帐户和密码(123456)来访问这个mysql server。
注意admin账户不一定要存在。
2、支持root用户允许远程连接mysql数据库
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
flush privileges;
3,登陆mysql数据库,修改表。
update user set host='%' where user='root';
flush privileges;