忠告:放弃慢吞吞的Apache吧,少年!
我的系统环境ubuntu 14.04,
chunli@Linux:~$ date 2017年 02月 14日 星期二 23:18:52 CST chunli@Linux:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.5 LTS Release: 14.04 Codename: trusty chunli@Linux:~$
系统版本不是ubuntu 14.04的,就不要往下看了。。。。
我的IP
chunli@Linux:~$ ifconfig eth0 eth0 Link encap:以太网 硬件地址 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/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1 接收数据包:15607 错误:0 丢弃:0 过载:0 帧数:0 发送数据包:4664 错误:0 丢弃:0 过载:0 载波:0 碰撞:0 发送队列长度:1000 接收字节:20324484 (20.3 MB) 发送字节:511060 (511.0 KB) chunli@Linux:~$
1,更新源,我用网易163的源
chunli@Linux:~$ sudo apt-get update
2, 安装nginx
chunli@Linux:~$ sudo apt-get install nginx 检查80端口的监听 chunli@Linux:~$ sudo netstat -tnlp 激活Internet连接 (仅服务器) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN 1062/dnsmasq tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 972/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1727/cupsd tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2253/nginx tcp6 0 0 :::22 :::* LISTEN 972/sshd tcp6 0 0 ::1:631 :::* LISTEN 1727/cupsd tcp6 0 0 :::80 :::* LISTEN 2253/nginx chunli@Linux:~$
浏览器访问:http://11.11.11.7/ 可以看到Nginx在干活
3, 安装MySQL
会提示设置root的密码,我设置为"chunli" chunli@Linux:~$ sudo apt-get install mysql-server 检查3306端口的监听 chunli@Linux:~$ sudo netstat -tnlp 激活Internet连接 (仅服务器) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN 1062/dnsmasq tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 972/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1727/cupsd tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 6285/mysqld tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2253/nginx tcp6 0 0 :::22 :::* LISTEN 972/sshd tcp6 0 0 ::1:631 :::* LISTEN 1727/cupsd tcp6 0 0 :::80 :::* LISTEN 2253/nginx chunli@Linux:~$
4, 安装PHP
chunli@Linux:~$ sudo apt-get install php5-fpm php5-mysql
修改配置,Nginx与PHP组合
chunli@Linux:~$ cd /etc/nginx/sites-available/ chunli@Linux:/etc/nginx/sites-available$ sudo cp default default.bak chunli@Linux:/etc/nginx/sites-available$ sudo vim default 搜索:fastcgi_pass 修改好如下:
修改好如下:
重启nginx
service nginx {stop|start|restart|reload}经常不靠谱,总是启动不了 nginx启动的停止方式: chunli@Linux:/etc/nginx/sites-available$ sudo service nginx stop chunli@Linux:/etc/nginx/sites-available$ sudo netstat -tnlp |grep 80 nginx启动的正确方式:可以报出配置文件哪儿有错 chunli@Linux:/etc/nginx/sites-available$ sudo nginx chunli@Linux:/etc/nginx/sites-available$ sudo netstat -tnlp |grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7879/nginx: master tcp6 0 0 :::80 :::* LISTEN 7879/nginx: master chunli@Linux:/etc/nginx/sites-available$
验证Nginx配置PHP
chunli@Linux:~$ sudo vim /usr/share/nginx/html/index.php
<?php
echo mysql_connect('localhost','root','chunli')?"connect MySQL success":"connect MySQL fail";
echo phpinfo();
?>
浏览器访问:http://11.11.11.7/index.php
好了,到此接下来才能正式干活了.
转载于:https://blog.51cto.com/990487026/1897847