在 Ubuntu 16.04上安装 Nginx, MySQL, PHP (LEMP)
2016-07-06 09:03
1271 查看
原文链接https://www.atlantic.net/community/howto/install-lemp-stack-on-ubuntu-16-04/
完全卸载apache2
sudo apt updatesudo apt upgrade
sudo apt remove apache2*
sudo apt autoremove
安装Nginx
sudo apt install nginxsudo service nginx start
测试Nginx,首先使用如下命令获取本机IP地址
ifconfig
使用浏览器访问本地IP。
http://10.102.7.193
返回如下页面,则安装Nginx成功。
![](https://www.atlantic.net/community/wp-content/uploads/2016/03/anet-install-lemp-on-ubuntu-16-04-02.png)
安装MySQL
sudo apt install mysql-server安装过程中需要输入两次密码。
![](https://www.atlantic.net/community/wp-content/uploads/2016/03/anet-installing-lemp-ubuntu-16-03.png)
![](https://www.atlantic.net/community/wp-content/uploads/2016/03/anet-installing-lemp-ubuntu-16-04.png)
安装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输入以下内容
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
![](https://www.atlantic.net/community/wp-content/uploads/2016/03/anet-installing-lemp-ubuntu-16-05.png)
最后,可以选择删除创建的info.php文件,避免被攻击者利用。
sudo rm /usr/share/nginx/html/info.php
相关文章推荐
- nginx1.4.7+uwsgi+django1.9.2项目部署,liunx系统为ubuntu14.0.4。
- nginx1.4.7+uwsgi+django1.9.2+gridfs 在ubuntu14.0.4上部署
- MacOS + Linux + Nginx
- nginx expires控制页面缓存
- CentOS7.0安装Nginx 1.7.4
- nginx的启动、停止、平滑重启
- Win7配置Nginx+PHP7
- Nginx安装启动
- 查看mysql apache php nginx的编译参数
- nginx启动停止
- puppet报告系统dashboard以及puppet+nginx
- rtmp-nginx hls模式 m3u8文件丢失问题
- centOS 6.5采用python+nginx+uwsgi实现爬金十财经日历
- nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
- nginx.conf配置
- nginx SSL双向认证
- Nginx优化use参数epoll,kqueue,rtsig,eventport,poll
- Nginx源码分析 - 主流程篇 - Nginx的启动流程
- 使用nginx lua实现网站统计中的数据收集
- web安全——代理(nginx)