https://blog.csdn.net/qq_19004627/article/details/80520622
完全卸载apache2
sudo apt update
sudo apt upgrade
sudo apt remove apache2*
sudo apt autoremove
安装Nginx
sudo apt install nginx
sudo service nginx start
测试Nginx,首先使用如下命令获取本机IP地址
ifconfig
使用浏览器访问本地IP。
http://10.102.7.193
返回如下页面,则安装Nginx成功。
This example is the default nginx web page on Ubuntu 16.04
安装MySQL
sudo apt install mysql-server
安装过程中需要输入两次密码。
Insert your secure password for your new MySQL root password
Retype your MySQL password
安装MySQL安全组件
sudo mysql_secure_installation
安装过程中首先需要输入MYSQL的root密码.
当询问“Change the root password?”时,输入“N”
剩下的问题可以敲击回车键,选择默认选项。
安装PHP
sudo apt install php php-fpm php7.0-mysql
为使Nginx支持PHP,需要修改Nginx的配置文件,首先备份原始配置文件。
sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.old
编辑/etc/nginx/sites-available文件,作为Nginx的配置文件。
sudo vim /etc/nginx/sites-available/default
向/etc/nginx/sites-available输入以下内容
在底下可以配置php服务的根目录与初始界面
server {
listen 80;
server_name your_site_name.com;
root /usr/share/nginx/html;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
修改完Nginx配置,需要重启Nginx
sudo service nginx restart
在/usr/share/nginx/html/目录创建info.php文件,测试PHP
sudo nano /usr/share/nginx/html/info.php
输入以下内容
<?php
phpinfo();
?>
在浏览器打开http://本地IP/info.php
例如http://10.102.7.193/info.php.
返回如下内容,则Nginx能够支持PHP
An example of the info.php web page
最后,可以选择删除创建的info.php文件,避免被攻击者利用。
sudo rm /usr/share/nginx/html/info.php