FreeBSD安裝實在太久了,所以我就用Ubuntu 12.04 LTS來做Server,安裝就不寫了,不會就甭玩。
因為Ubuntu預設的 /bin/sh 是 dash ,有時候會出問題,所以我都習慣換成 bash:
$sudo dpkg-reconfigure dash
如果有裝Apache 要先移掉:
$sudo apt-get remove apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libapache2-mod-fastcgi
如果不想移Apache就先停用:
$sudo /etc/init.d/apache2 stop $sudo update-rc.d -f apache2 remove
再來安裝Nginx,好習慣是先更新repository,省得某些套件會找不到:
$sudo apt-get update $sudo apt-get upgrade $sudo apt-get install nginx
$sudo apt-get install fcgiwrap php5-fpm php5-xcache php5-mysql php5-pgsql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
至此套件都裝好了,可以設定Nginx,若有要支援https,得先改 /etc/nginx/nginx.conf
在 http {...} 區域內加上
在 http {...} 區域內加上
## Detect when HTTPS is used map $scheme $fastcgi_https { default off; https on; }
再改 /etc/nginx/sites-available/default
在 server { ... } 區域內加上
# 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)(/.+)$; fastcgi_pass 127.0.0.1:9000; fastcgi_param HTTPS $fastcgi_https; # <-- 要用SSL得加上這行,並得改 nginx.conf fastcgi_index index.php; include /etc/nginx/fastcgi_params; }
較複雜的版本
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param HTTPS $fastcgi_https; # <-- 要用SSL得加上這行,並得改 nginx.conf fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; include /etc/nginx/fastcgi_params; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_buffer_size 128k; fastcgi_buffers 256 4k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; }
並同樣在 server {...} 內把 root /usr/share/nginx/www; 改成 root /var/www; 才會和原本Apache的目錄一致。再把 index index.html index.htm; 改成 index index.html index.htm index.php; 。server_name 也可改成你的server名稱。
最後重新啟動服務即可
$sudo /etc/init.d/php5-fpm restart $sudo /etc/init.d/nginx restart