忠告: 放弃慢吞吞的 Apache 吧, 少年!
我的系统环境:
- :~$ date
- 2017年 02月 14日 星期二 23:18:52 CST
- :~$ lsb_release -a
- No LSB modules are available.
- Distributor ID: Ubuntu
- Description: Ubuntu 14.04.5 LTS
- Release: 14.04
- Codename: trusty
- :~$
更新源
- :~$ sudo apt-get update
1, 安装 nginx
- :~$ sudo apt-get install nginx
- 检查80端口的监听
- :~$ 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
- :~$
2, 安装 MySQL
- 会提示设置root的密码,我设置为"chunli"
- :~$ sudo apt-get install mysql-server
- 检查3306端口的监听
- :~$ 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
- :~$
3, 安装 PHP
- :~$ sudo apt-get install php5-fpm php5-mysql
浏览器访问, 验证 nginx 是否在干活
- :~$ 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)
- :~$
浏览器访问: http://11.11.11.7/ 可以看到 Nginx 在干活
修改配置, 让 Nginx 与 PHP 配合干活
- : ~$ cd / etc / nginx / sites - available / :/etc/nginx / sites - available$ sudo cp
- default
- default.bak:
- /etc/nginx / sites - available$ sudo vim
- default搜索:
- fastcgi_pass修改好如下:
修改好如下:
重启 nginx
- service nginx {stop|start|restart|reload}经常不靠谱,总是启动不了
- nginx启动的停止方式:
- :/etc/nginx/sites-available$ sudo service nginx stop
- :/etc/nginx/sites-available$ sudo netstat -tnlp |grep 80
- nginx启动的正确方式:可以报出配置文件哪儿有错
- :/etc/nginx/sites-available$ sudo nginx
- :/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
- :/etc/nginx/sites-available$
验证 Nginx 配置 PHP
- :~$ sudo vim /var/www/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
好了, 到此接下来才能正式干活了.
来源: