2017 ubuntu 安装 Nginx PHP MySQL

前端之家收集整理的这篇文章主要介绍了2017 ubuntu 安装 Nginx PHP MySQL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


忠告:放弃慢吞吞的Apache吧,少年!



我的系统环境:

chunli@Linux:~$date
2017年02月14日星期二23:18:52CST

chunli@Linux:~$lsb_release-a
NoLSBmodulesareavailable.
DistributorID:	Ubuntu
Description:	Ubuntu14.04.5LTS
Release:	14.04
Codename:	trusty
chunli@Linux:~$


更新源

chunli@Linux:~$sudoapt-getupdate


1,安装Nginx

chunli@Linux:~$sudoapt-getinstallNginx

检查80端口的监听
chunli@Linux:~$sudonetstat-tnlp
激活Internet连接(仅服务器)
ProtoRecv-QSend-QLocalAddressForeignAddressStatePID/Programname
tcp00127.0.1.1:530.0.0.0:*LISTEN1062/dnsmasq
tcp000.0.0.0:220.0.0.0:*LISTEN972/sshd
tcp00127.0.0.1:6310.0.0.0:*LISTEN1727/cupsd
tcp000.0.0.0:800.0.0.0:*LISTEN2253/Nginx
tcp600:::22:::*LISTEN972/sshd
tcp600::1:631:::*LISTEN1727/cupsd
tcp600:::80:::*LISTEN2253/Nginx
chunli@Linux:~$


2,安装MysqL

提示设置root的密码,我设置为"chunli"
chunli@Linux:~$sudoapt-getinstallMysqL-server

检查3306端口的监听
chunli@Linux:~$sudonetstat-tnlp
激活Internet连接(仅服务器)
ProtoRecv-QSend-QLocalAddressForeignAddressStatePID/Programname
tcp00127.0.1.1:530.0.0.0:*LISTEN1062/dnsmasq
tcp000.0.0.0:220.0.0.0:*LISTEN972/sshd
tcp00127.0.0.1:6310.0.0.0:*LISTEN1727/cupsd
tcp00127.0.0.1:33060.0.0.0:*LISTEN6285/MysqLd
tcp000.0.0.0:800.0.0.0:*LISTEN2253/Nginx
tcp600:::22:::*LISTEN972/sshd
tcp600::1:631:::*LISTEN1727/cupsd
tcp600:::80:::*LISTEN2253/Nginx
chunli@Linux:~$

3,安装PHP

chunli@Linux:~$sudoapt-getinstallPHP5-fpmPHP5-MysqL

浏览器访问,验证Nginx是否在干活

chunli@Linux:~$ifconfigeth0
eth0Linkencap:以太网硬件地址00:0c:29:29:0f:49
inet地址:11.11.11.7广播:11.11.11.255掩码:255.255.255.0
inet6地址:fe80::20c:29ff:fe29:f49/64Scope:Link
UPBROADCASTRUNNINGMULTICASTMTU:1500跃点数:1
接收数据包:15607错误:0丢弃:0过载:0帧数:0
发送数据包:4664错误:0丢弃:0过载:0载波:0
碰撞:0发送队列长度:1000
接收字节:20324484(20.3MB)发送字节:511060(511.0KB)

chunli@Linux:~$

浏览器访问:http://11.11.11.7/ 可以看到Nginx在干活

wKiom1ijIL6QtITdAAA0gLTYKkI862.png


修改配置,让NginxPHP配合干活

chunli@Linux:~$cd/etc/Nginx/sites-available/
chunli@Linux:/etc/Nginx/sites-available$sudocpdefaultdefault.bak
chunli@Linux:/etc/Nginx/sites-available$sudovimdefault
搜索:fastcgi_pass
修改好如下:

修改好如下:

wKioL1ijIOmDofEYAAAsq_d1RNM044.png

重启Nginx

serviceNginx{stop|start|restart|reload}经常不靠谱,总是启动不了

Nginx启动的停止方式:
chunli@Linux:/etc/Nginx/sites-available$sudoserviceNginxstop
chunli@Linux:/etc/Nginx/sites-available$sudonetstat-tnlp|grep80

Nginx启动的正确方式:可以报出配置文件哪儿有错
chunli@Linux:/etc/Nginx/sites-available$sudoNginx
chunli@Linux:/etc/Nginx/sites-available$sudonetstat-tnlp|grep80
tcp000.0.0.0:800.0.0.0:*LISTEN7879/Nginx:master
tcp600:::80:::*LISTEN7879/Nginx:master
chunli@Linux:/etc/Nginx/sites-available$

验证Nginx配置PHP

chunli@Linux:~$sudovim/var/www/html/index.PHP
<?PHP
echoMysqL_connect('localhost','root','chunli')?"connectMysqLsuccess":"connectMysqLfail";
echoPHPinfo();
?>

浏览器访问:http://11.11.11.7/index.PHP

wKiom1ijIUngZ0J1AACWhXz7bTc400.png


好了,到此接下来才能正式干活了.

猜你在找的Ubuntu相关文章