由於在linux下,php和nginx是兩個獨立的進程,所以需要需要進行配置才能讓PHP和NGINX進行通信
(1)下載PHP源碼包並解壓
php-5.5.22.tar.gz 解壓:tar zxvf php-5.5.22
(2)檢查PHP安裝環境
[root@localhost ~]# ./configure –prefix=/usr/local/php5 –with-mysql=mysqlnd –enable-mysqlnd –enable-gd-native-ttf –enable-gd-jis-conv –enable-fpm –enable-shmop –enable-sysvsem –enable-mbregex –enable-mbstring –enable-ftp –enable-gd-native-ttf –enable-pcntl –enable-sockets –with-xmlrpc –enable-soap –without-pear –with-gettext –enable-session –with-curl –with-jpeg-dir –with-zlib –enable-zip
檢查環境完成
(3)編譯安裝
make && make install
安裝好後生成的安裝文件
(4)編譯安裝nginx,過程可以參考我的上一篇文章NGINX的編譯安裝
(5)從解壓後的源碼包裏複製PHP的配置文件
cp /usr/local/src/php-5.5.22/php.ini-production /usr/local/php5/lib/php.ini
(6)複製php 與nginx進行通信的進程配置文件
cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc//php-fpm.conf
(7)啓動該進程
/usr/local/php5/sbin/php-fpm
(8)修改nginx配置文件,使其能夠與php進行通信
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}
}
(9)修改完nginx的配置文件後,重新啓動nginx的進程
/usr/local/nginx/sbin/nginx -s load
(10)在網站根目錄/usr/local/php5/html/下見一個php的文件index.php
在index.php文件內寫一個php函數:phpinfo();進行測試
(11)在瀏覽器進行測試,輸入127.0.0.1即可
PS:我是在linux系統環境下進行測試的!!!!!!!!