一 。php
sudo apt-get install nginxhtml
安裝以後的文件結構大體爲:mysql
啓動nginx sudo service nginx start 或 sudo /etc/init.d/nginx start 訪問便可看到nginx歡迎界面nginx
2.安裝php sudo apt-get install php5 php5-cgisql
3.安裝fastcgi sudo apt-get install spawn-fcgi瀏覽器
4.配置nginx 修改nginx的配置文件:/etc/nginx/sites-available/defaultcurl
修改主機名: server_name localhost;ide
修改index的一行爲: index index.php index.html index.htm;測試
去掉下面部分的註釋用於支持php腳本: location ~ /.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name; #fastcgi_param設置參數 include /etc/nginx/fastcgi_params; }url
重啓nginx sudo service nginx restart
5.用spawn-fcgi啓動php5-cgi spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php5-cgi
6.測試 在/var/www/nginx-default下新建一個index.php文件
<?php echo phpinfo(); ?>
訪問 http://localhost 便可測試成功
二 。 一,安裝Nginx
apt-get install nginx
1,配置nginx
nginx全部的配置在 /etc/nginx/nginx.conf中
nginx.conf配置裏面包括了
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*; 這兩個配置,因此這裏面的配置也是有效的。 錯誤日誌 error_log /var/log/nginx/error.log;
這裏咱們把配置寫在 /etc/nginx/sites-available/default中 修改 root /usr/share/nginx/html; 這是網頁的根目錄,默認裏面有一個index.html頁面 index index.html index.htm修改爲index index.php index.html index.htm; 增長
location ~ .php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; }
2,保存文件,使配置生效 /etc/init.d/nginx reload
3,啓動nginx /etc/init.d/nginx start
4,在 /usr/share/nginx/html下新建index.php <? php phpinfo(); ?> 二 安裝php sudo apt-get install php5-fpm sudo apt-get install php5-gd # Popular image manipulation library; used extensively by Wordpress and it's plugins. sudo apt-get install php5-cli # Makes the php5 command available to the terminal for php5 scripting sudo apt-get install php5-curl # Allows curl (file downloading tool) to be called from PHP5 sudo apt-get install php5-mcrypt # Provides encryption algorithms to PHP scripts sudo apt-get install php5-mysql # Allows PHP5 scripts to talk to a MySQL Database sudo apt-get install php5-readline # Allows PHP5 scripts to use the readline function
查看php5運行進程 ps -waux | grep php5
打開關閉php5進程
sudo service php5-fpm stop sudo service php5-fpm start sudo service php5-fpm restart sudo service php5-fpm status
配置php5監聽端口 /etc/php5/fpm/pool.d/www.conf
把 listen = /var/run/php5-fpm.sock 改成 listen = 127.0.0.1:9000
從新運行php進程
在瀏覽器中輸入 localhost就能夠看到了
三 。 牛人配置
location ~ .php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+.php)(/.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; }