當前位置:首頁 » 編程語言 » ubuntuphpnginx

ubuntuphpnginx

發布時間: 2022-09-23 17:50:59

A. 如何在ubuntu 搭建虛擬環境

在FreeBsd上搭建nginx + php環境,雖然難度不小,可是由於使用歷史的問題,網路關於這方面的經驗文章還是比較多的,隨著Ubuntu的逐漸推廣,研究下如何在ubuntu下搭建nginx + php環境還是有必要的,方便有這方面需求的朋友,並且可以推動Ubuntu的普及,其實,在Ubuntu下搭建nginx + php環境比FreeBsd下速度要快得多,因為在FreeBsd我是用ports方式安裝,需要編譯,Ubuntu下直接apt-get install 的方式安裝,速度很快,下面就來開始安裝吧!1,安裝nginx,執行以下命令,很快完成,不過目前apg-get方式安裝默認是0;index index$fastcgi_script_name;include /etc/nginx/fastcgi_params;}} 2,安裝php-cgi模塊執行sudo apt-get install php5-cgi配置文件默認安裝位置:php-cgi: /usr/bin/php-cgiphp5-cgi: /usr/bin/php5-cgicgi config: /usr/bin/cgi/php.ini 修改php.ini文件的cgi.fix_pathinfo數據為1,默認為0 cgi.fix_pathinfo=1; 這樣php-cgi方能正常使用SCRIPT_FILENAME這個變數3,安裝spawn-fcgi spawn-fcgi是lighttpd的一個用來控制php-cgi的工具.如果系統沒有安裝GCC編譯環境,剛需要在安裝lighttpd之前要安裝build-essential工具包,執行以下命令 sudo apt-get install build-essentialwget /download/lighttpd-1.4.19.tar.gztar -xvf lighttpd-1.4.19.tar.gzcd lighttpd-1.4.19/sudo apt-get install libpcre3-dev./configure –without-zlib –without-bzip2makesudo cp src/spawn-fcgi /usr/local/bin/spawn-fcgi 這樣cgi控制器就安裝完成.4.啟動測試系統.啟動fast_cgi:spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php-cgi注意:ip,埠與nginx伺服器中的cgi-pass要對應. -C表示打開幾個cgi進程啟動nginxsudo /etc/init.d/nginx start好了,如果沒有出錯信息,則說明配置成功了,現在寫個phpinfo測試下吧!最後,附上我的/etc/nginx/sites-enable/default的配置文件,此配置文件啟用了rewrite功能server {listen 80;server_name localhost;access_log /var/log/nginx/localhost.access.log;location / {root /var/www/nginx-default;index index.php;if (-f $request_filename/index.html){rewrite (.*) $1/index.html break;}if (-f $request_filename/index.php){rewrite (.*) $1/index.php;}if (!-f $request_filename){rewrite (.*) /index.php;}} #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 /var/www/nginx-default;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ .php$ {#proxy_pass 127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ .php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;include /etc/nginx/fastcgi_params;}# deny access to .htaccess files, if Apache’s document root# concurs with nginx’s one##location ~ /.ht {#deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#listen 8000;#listen somename:8080;#server_name somename alias another.alias;#location / {#root html;#index index.html index.htm;#}#}# HTTPS server##server {#listen 443;#server_name localhost;#ssl on;#ssl_certificate cert.pem;#ssl_certificate_key cert.key;#ssl_session_timeout 5m;#ssl_protocols SSLv2 SSLv3 TLSv1;#ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;#ssl_prefer_server_ciphers on;#location / {#root html;#index index.html index.htm;#}#}怎麼樣?是不是快速又方便,快試試吧,打算做WordPress的朋友可以試試哦,nginx + php效率可比Apache + php高哦!

B. Ubuntu14.04 安裝nginx+php5-fpm 後訪問php頁面空白,怎麼解決

先看位置對不對,可能nginx解析的地址不對
再看日誌
我估計,你是nginx配置錯了!
測試方法
比如再你訪問的頁面裡面隨便寫點東西 不過要確定不是404 如果是404 你還是乖乖去看下nginx配置到哪了。。。。
要注意nginx的訪問許可權

C. 如何在ubuntu上裝nginx+php+mysql

1、先更新ubuntu系統
更新命令
sudo apt-get update
sudo apt-get upgrade
2
添加ubuntu nginx更新源鏡像
cd /etc/apt/
sudo cp sources.list sources.list_bak
將如下代碼添加到sources.list文件中
deb http://nginx.org/packages/ubuntu/ precise nginx
deb-src http://nginx.org/packages/ubuntu/ precise nginx
使用
sudo vi sources.list
如果提示: W: GPG error: http://nginx.org precise Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY ABF5BD827BD9BF62 由於官方不信任該源
解決方法: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABF5BD827BD9BF62
3
3、更新和安裝update and install
sudo apt-get update
sudo apt-get install nginx
4、啟動nginx
sudo /etc/init.d/nginx start
5、check version
nginx -v
6、配置php+mysql
sudo apt-get install php5-cli php5-cgi mysql-server php5-mysql
7、安裝FastCgi
sudo apt-get install spawn-fcgi
8、配置nginx
8.1、修改nginx的配置文件:/etc/nginx/sites-available/default 修改主機名
server_name localhost;
8.2、修改index的一行,添加index.php
index index.php index.html index.htm;
8.3、去掉下面部分的注釋用於支持 php 腳本
location ~ .php$ { include /etc/nginx/fastcgi_params; #需放在第一行,否則會出錯 fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name; }
9、 重新啟動nginx
/etc/init.d/nginx stop
/etc/init.d/nginx start
10、啟動fastcgi php
spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi
11、nginx提示502 錯誤
nginx 502 Bad Gateway沒有啟動,啟動命令是:
spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi
12、設置開機自啟動
Ubuntu開機之後會執行/etc/rc.local文件中的腳本
所以我們可以直接在/etc/rc.local中添加啟動腳本。
spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi 添加到語句: exit 0
前面才行
13、no input file specified錯誤
sudo vi /etc/nginx/sites-available/default
其中這個欄位
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
include fastcgi_params;
}
注意
fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
/var/www/nginx-default 改為你的網站根目錄,一般就是改成這個。
server 欄位下root 目錄和網站根目錄保持一致

D. Ubuntu14.04安裝lnmp(nginx+php-fpm+mysql), nginx reload總是fail,附操作步驟,請指點,謝謝。

nginx和php配置需要nginx和php-fpm,確保安裝php-fpm並正確啟動,另外貼出nginx啟動日誌才能知道具體原因。

E. ubuntu 下剛裝完nginx+php+mysql要測試的時候發現var目錄下無www目錄,求解決方法

自己修改一下配置文件,nginx的配置文件你能否找到呢?可以用
ps -elf |grep nginx
找到nginx的配置文件,然後修改nginx.conf 中
server{} 段的 root 後面的目錄。

F. ubuntu怎麼安裝nginx+mysql+php

1、更新 1 sudo apt-get update 2、安裝nginx 1 sudo apt-get intsall nginx Ubuntu安裝之後的文件結構大致為: * 所有的配置文件都在/etc/nginx下,並且每個虛擬主機已經安排在了/etc/nginx/sites-available下 *程序文件在/usr/sbin/nginx * 日誌放在了/var/log/nginx中 *並已經在/etc/init.d/下創建了啟動腳本nginx * 默認的虛擬主機的目錄設置在了/var/www/nginx-default 下面可以啟動nginx來看看效果(請確保80埠沒有其他服務在使用): 1 sudo /etc/init.d/nginx start #或者簡單的 1 service nginx start 然後打開瀏覽器,查看localhost/ 看看是否看到了」Welcome to nginx!」 如果看到了,說明安裝成功. 當然,基本上,這塊兒都不會出問題. 如果運行不成功,可以先 1 sudo killall apache2 殺掉apache進程 3、安裝php sudo apt-get install php5 php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-tidy php5-xmlrpc php5-sqlite php5-xsl 4、安裝spawn-fcgi 為什麼要安裝spawn-fcgi呢,它用來控制php-cgi進程,以防止進程崩潰或是單進程的效率太低. 網上很多人都說要使用spawn-fcgi必須得安裝lighttpd,實際上不必要,可以直接安裝spawn-fcgi 運行: 1 sudo apt-get install spawn-fcgi 5、配置 接下來就是最讓人頭疼的配置. 配置Nginx和spawn-fcgi配合運行 (1).在/etc/nginx/fastcgi_params 文件最後,加入一行,可以用 1 sudo vi /etc/nginx/fastcgi_params 加入此行: 1 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; (2).另外需要在PHP-CGI的配置文件(Ubuntu 上此配置文件位於/etc/php5/cgi/php.ini)中,找到cgi.fix_pathinfo選項,修改為: 1 cgi.fix_pathinfo=1; 這樣php-cgi方能正常使用SCRIPT_FILENAME這個變數. (3).打開/etc/nginx/sites-available/default文件在 1 2 3 server { listen 80; server_name localhost; 下面添加web根目錄的絕對地址,這里是使用的是nginx的默認地址 1 root /var/www/nginx-default 即root和server_name同級這段即相當於apache的默認目錄 如果沒有這個的話,容易在執行php 文件的時候,會提示」No input file specified」. 我就曾在此繞了好大個圈子才發現問題.然後修改 1 2 3 4 5 6 #location ~ .php$ { #fastcgi_pass 127.0.0.1:9000; #fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; #includefastcgi_params; #} 修改成 1 2 3 4 location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name; include /etc/nginx/fastcgi_params; #包含fastcgi的參數文件地址 6、開始fast_cgi進程 1、sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid 7、設置開機啟動fastcgi進程並啟動 1 sudo vi /etc/rc.local 添加下一行 1 /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid 如果打開php文件出現:No input file specified請檢查php.ini的配置中 1 cgi.fix_pathinfo=1 1 doc_root= 還有,每個虛機要根據自己不同的虛機設置不同的目錄,要保證這個路徑正確. 檢查/etc/nginx/sites-available下的配置文件中,server內包含 root 及地址 而非location內的root 啟動 1 fast-cgisudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid 參數含義如下 * -f 指定調用FastCGI的進程的執行程序位置,根據系統上所裝的PHP的情況具體設置 * -a 綁定到地址addr * -p 綁定到埠port * -s 綁定到unix socket的路徑path * -C 指定產生的FastCGI的進程數,默認為5(僅用於PHP) * -P指定產生的進程的PID文件路徑 * -u和-g FastCGI使用什麼身份(-u 用戶 -g 用戶組)運行,Ubuntu下可以使用www-data,其他的根據情況配置,如nobody、apache等現在可以在web根目錄下放個探針或php文件測試一下了 8、安裝mysql 1 sudo apt-get install mysql-server mysql-client 中間會提示輸入Root用戶密碼,依次輸入即可. 啟動MySQL 1 sudo /etc/init.d/mysql start 測試mysql服務是否正常: 運行 1 mysql -uroot -p 輸入mysql密碼 1 show databases; 如果看到下面的內容 Database information_schema mysql 則mysql已正確安裝了. 至此,ubuntu下的nginx+php+mysql就安裝完成了.

G. ubuntu下修改php.ini需要重啟nginx嗎

當然需要的只要是修改到伺服器的配置,就需要重啟。

熱點內容
演算法sum 發布:2024-04-18 10:58:49 瀏覽:20
linux是javaweb 發布:2024-04-18 10:49:30 瀏覽:318
倩女幽魂寶藏演算法 發布:2024-04-18 10:44:20 瀏覽:347
知道伺服器的ip地址怎麼連接 發布:2024-04-18 10:37:53 瀏覽:705
安卓手機的鍵盤如何改成日語 發布:2024-04-18 10:36:07 瀏覽:625
pw壓縮機 發布:2024-04-18 10:35:53 瀏覽:19
qnap搭建java伺服器 發布:2024-04-18 10:35:44 瀏覽:313
王者榮耀qq安卓區最難打的是哪個 發布:2024-04-18 10:34:51 瀏覽:491
如何取消觸手伺服器 發布:2024-04-18 10:34:41 瀏覽:908
壓縮空氣緩沖罐 發布:2024-04-18 10:21:54 瀏覽:93