將下面這行文字加入到 /etc/apt/sources.list 最後一行即可
deb http://nginx.org/packages/ubuntu/ precise nginx
2. 加入 Ubuntu source 來源的 public key,有兩種方式。
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABF5BD827BD9BF62
或是下載 nginx signing key (按右鍵另存),參考來源。
sudo apt-key add nginx_signing.key
3. 接著就進行系統 update & upgrade 的步驟
sudo apt-get update
sudo apt-get upgrade
4. 更新完畢後,就可以直接安裝 Nginx 了,安裝完畢後,就是 1.4.2-1 版
sudo apt-get install nginx如果想看是否安裝成功,執行下列指令。
service nginx start
看到這個畫面就表示OK,簡單吧!
5. 接著安裝 MySQL + php5,這裡主要是以安裝 php5-fpm 當作 php 服務,參考來源,一併安裝包括 XCACHE 加速等。
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql fcgiwrap php5-fpm php5-xcache 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
上面的 mysql-server libapache2-mod-auth-mysql php5-mysql 部分是安裝 MySQL,其餘就是 php5-fpm XCACHE 以及需要的相關模組,安裝過程中會問到 MySQL root 的密碼,記得要輸入。
修改 www.conf 資料
sudo nano /etc/php5/fpm/pool.d/www.conf
找到 listen = 127.0.0.1:9000 的字樣,改成下列資料,使用 php5-fpm 服務
listen = /var/run/php5-fpm.sock
Lets create the following file: /etc/init.d/php-fastcgi
vim
/etc/init
.d
/php-fastcgi
|
This file will have the following content:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=500
PHP_CGI=
/usr/bin/php-cgi
PHP_CGI_NAME=`
basename
$PHP_CGI`
PHP_CGI_ARGS=
"- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
RETVAL=0
start() {
echo
-n
"Starting PHP FastCGI: "
start-stop-daemon --quiet --start --background --chuid
"$USER"
--
exec
/usr/bin/env
-- $PHP_CGI_ARGS
RETVAL=$?
echo
"$PHP_CGI_NAME."
}
stop() {
echo
-n
"Stopping PHP FastCGI: "
killall -q -w -u $USER $PHP_CGI
RETVAL=$?
echo
"$PHP_CGI_NAME."
}
case
"$1"
in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo
"Usage: php-fastcgi {start|stop|restart}"
exit
1
;;
esac
exit
$RETVAL
|
As Tomasz Sterna mentions, you will need to fiddle with the PHP_FCGI_CHILDREN
and PHP_FCGI_MAX_REQUESTS
variables depending on your server’s amount of memory and compute power. I am running a baseline 256 MB / 10 GB Rackspace Cloud Server so I use the following settings which seem to work very well (as seen above):
4
5
|
PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=500
|
Moving on … after you’ve created and saved the file we will make it executable and then start up the FastCGI service with the following commands:
chmod
+x
/etc/init
.d
/php-fastcgi
/etc/init
.d
/php-fastcgi
start
|
We will want the service to auto start when we reboot our server, so we also do the following:
update-rc.d php-fastcgi defaults
7.修改 /etc/nginx/conf.d/default.conf
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
8. 重新啟動相關服務即可
sudo service php5-fpm restart
sudo service nginx restart