2017 ubuntu 14.04 安裝 Nginx PHP MySQL


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



個人系統環境ubuntu 14.04,
html

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的,就不要往下看了。。。。
mysql


個人IPnginx

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的源sql

chunli@Linux:~$ sudo apt-get update


2, 安裝nginxubuntu

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在幹活vim

wKiom1ijIL6QtITdAAA0gLTYKkI862.png




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, 安裝PHPbash

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
修改好以下:

修改好以下:

wKioL1ijIOmDofEYAAAsq_d1RNM044.png


重啓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

wKiom1ijIUngZ0J1AACWhXz7bTc400.png


好了,到此接下來才能正式幹活了.

相關文章
相關標籤/搜索