安装nginx
$ sudo apt-get update
$ sudo apt-get install nginx
ubuntu 安装nginx,默认配置如下
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#}
安装mysql
$ sudo apt-get install mysql-server
To secure the installation, we can run a simple security script that will ask whether we want to modify some insecure defaults. Begin the script by typing:
$ mysql_secure_installation
注意:此步是做一些安全配置,可以不执行。比如VALIDATE PASSWORD PLUGIN,设置密码复杂度等。
默认启动监听是127.0.0.1地址。可以注释掉
# vim /etc/mysql/mysql.conf.d/mysqld.cnf
#bind-address = 127.0.0.1
安装PHP
$ sudo apt-get install php-fpm php-mysql
默认安装是PHP7.0版本,此版本cgi.fix_pathinfo已发现有漏洞。需更改配置
$ sudo vim /etc/php/7.0/fpm/php.ini
找到cgi.fix_pathinfo此行
更改为cgi.fix_pathinfo=0
然后重启php
$ sudo systemctl restart php7.0-fpm
php-fpm 启动默认是监听socket文件,链接PHP也只能通过sock文件链接。需要更改为端口
找到/etc/php/7.0/fpm/pool.d/www.conf
;listen = /run/php/php7.0-fpm.sock
listen = 127.0.0.1:9000
配置nginx链接PHP
$ vim /etc/nginx/conf.d/test.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name server_domain_or_IP;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass 127.0.0.1:9000;
}
}
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
$ nginx -s reload
编辑/var/www/html/info.php
<?php
phpinfo();
?>
访问http://ip:port/info.php
出现下图正常
[站外图片上传中...(image-5e8700-1533613517538)]
正常后删除
$ sudo rm /var/www/html/info.php
网友评论