最近在Ubuntu14.04 LTS 安裝 LNMP 一鍵安裝包的時候出現(xiàn)了問題,PHP 5 服務沒有啟動,只好使用 Ubuntu 官方源進行安裝:
Nginx (讀音 “engine x”)免費、開源、高效的 HTTP 服務。Nginx 是以穩(wěn)定著稱,功能豐富,結構簡單,低資源消耗。本教程將演示如何在ubuntu 14.04 服務器中安裝 nginx、PHP5(php-fpm)、MySQL。
----------------------------------------分割線----------------------------------------
Ubuntu 13.04 安裝 LAMP/Vsftpd/Webmin/phpMyAdmin 服務及設置http://www.linuxidc.com/Linux/2013-06/86250.htm
CentOS6.4 下的LNMP 生產環(huán)境搭建及安裝腳本http://www.linuxidc.com/Linux/2013-11/92428.htm
生產環(huán)境實用之LNMP架構的編譯安裝+SSL加密實現(xiàn)http://www.linuxidc.com/Linux/2013-05/85099.htm
LNMP 全功能編譯安裝 for CentOS 6.3筆記http://www.linuxidc.com/Linux/2013-05/83788.htm
CentOS 6.3 安裝LNMP (PHP 5.4,MyySQL5.6)http://www.linuxidc.com/Linux/2013-04/82069.htm
在部署LNMP的時候遇到Nginx啟動失敗的2個問題http://www.linuxidc.com/Linux/2013-03/81120.htm
Ubuntu安裝Nginx php5-fpm MySQL(LNMP環(huán)境搭建)http://www.linuxidc.com/Linux/2012-10/72458.htm
----------------------------------------分割線----------------------------------------
本文采用的主機名稱:server1.example.com,IP地址:192.168.0.100??赡芘c你的主機有所不同,自行修改。
安裝中我們使用root賬戶,先進行用戶切換:
sudo su
安裝 MySQL 運行命令:
apt-get install mysql-server mysql-client
安裝過程中會詢問建立 Root 賬戶密碼,連續(xù)輸入兩次:
New password for the MySQL “root” user:<– 輸入你的密碼
Repeat password for the MySQL “root” user:<– 再輸入一次
在安裝 Nginx 之前,如果你已經安裝 Apache2 先刪除在安裝 nginx:
service apache2 stop
update-rc.d -f apache2 remove
apt-get remove apache2
apt-get install nginx
啟動 nginx 服務:
service nginx start
試試安裝是否成功,在瀏覽器輸入IP或主機地址 (e.g.http://192.168.0.100),如下圖所示,說明安裝成功:
在 Ubuntu 14.04 中默認的根目錄為/usr/share/nginx/html.
我們必須通過PHP-FPM才能讓PHP5正常工作,安裝命令:
apt-get install php5-fpm
php-fpm是一個守護進程。
使用Vi打開配置文件/etc/nginx/nginx.conf:
vi /etc/nginx/nginx.conf
配置不是很容易明白,可以參考:http://wiki.nginx.org/NginxFullExample和http://wiki.nginx.org/NginxFullExample2
我們需要調整工作進程數設置,如下面的值設置:
[...]worker_processes4;[...]keepalive_timeout 2;[...] |
默認虛擬主機設置文件/etc/nginx/sites-available/default按如下設置:
vi /etc/nginx/sites-available/default
[...]server { listen 80; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.php index.html index.htm; # Make site accessible from http://localhost/ server_name _; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ /index.html; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } location /doc/ { alias /usr/share/doc/; autoindex on; allow 127.0.0.1; allow ::1; deny all; } # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests #location /RequestDenied { # proxy_pass http://127.0.0.1:8080; #} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ .php$ { try_files $uri =404; fastcgi_split_path_info ^(.+.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # With php5-cgi alone: #fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /.ht { deny all; }}[...] |
取消同時偵聽 IPv4和IPv6 的80端口。
server_name _;默認主機名 (當然你可以修改,例如修改為:www.example.com).
index主頁這一行我們加入index.php。
PHP 重要配置配置location ~ .php$ {}這幾行我們需要啟動,反注釋掉。另外再添加一行:try_files $uri =404。
(其他配置查看http://wiki.nginx.org/Pitfalls#Passing_Uncontrolled_Requests_to_PHP和http://forum.nginx.org/read.php?2,88845,page=3).
保存文件并重新加載 nginx 命令:
service nginx reload
如果加載失敗,直接用刪除所有配置內容,用上面的信息替換。
更多詳情見請繼續(xù)閱讀下一頁的精彩內容:http://www.linuxidc.com/Linux/2014-05/102351p2.htm
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com