天天看點

linux+nginx+php-fpm搭建學習筆記

文章内内容均參考網絡上各類文章後自行整理,感謝原文作者的分享.

os環境centos release 6.6

一,安裝配置nginx

下載下傳目前nginx最新的穩定版本nginx-1.8.0

# wget http://nginx.org/download/nginx-1.8.0.tar.gz

解壓編譯安裝

# tar -xvf nginx-1.8.0.tar.gz# cd nginx-1.8.0

# ./configure --prefix=/usr/local/nginx --with-http_realip_module --with-http_sub_module \

--with-http_gzip_static_module --with-http_stub_status_module  --with-pcre

# make && make install

如果提示錯誤找不到pcre就用yum裝一下

# yum install pcre-devel -y

建立nginx使用者

# useradd -m -s /sbin/nologin nginx

修改nginx預設配置檔案,有一些為新添

# vim /usr/local/nginx/conf/nginx.conf

配置檔案修改後,運作nginx指令檢視是否有錯誤

# /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

輸出正确資訊後啟動服務

# /usr/local/nginx/sbin/nginx

關閉服務指令,-s 後可加stop quit reopen reload

# /usr/local/nginx/sbin/nginx -s stop

添加開機啟動

# echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local

随後在/var/www/html下建立個index.html,随意寫點東西,然後打開http://localhost檢視

二,編譯安裝php-fpm

編譯過程中缺少的包用yum provides搜尋後安裝,不一一記錄

# wget http://cn2.php.net/get/php-5.6.15.tar.bz2/from/this/mirror -o phpphp-5.6.15.tar.bz2

# tar -xvf phpphp-5.6.15.tar.bz2

# cd phpphp-5.6.15.tar.bz2

# ./configure \

--prefix=/usr/local/php5.6 \

--with-config-file-path=/usr/local/php5.6/etc \

--enable-fpm \

--with-mysql=shared,mysqlnd \

--with-fpm-user=php-fpm \

--with-fpm-group=php-fpm \

--with-libxml-dir \

--with-gd \

--with-jpeg-dir \

--with-png-dir \

--with-freetype-dir \

--with-iconv-dir \

--with-zlib-dir \

--enable-sockets=shared \

--enable-soap \

--enable-gd-native-ttf \

--enable-ftp \

--enable-mbstring \

--enable-exif \

--with-pear \

--with-curl \

--with-openssl

建立使用者,拷貝兩份配置檔案,因為将準備啟動兩個不同端口的php-fpm程序

# useradd -m -s /sbin/nologin php-fpm

# cd /usr/local/php5.6

# cp etc/php-fpm.conf.default etc/php-fpm-9000.conf

# cp etc/php-fpm.conf.default etc/php-fpm-9001.conf

其中一份配置檔案内容如下,兩份配置檔案端口号需配置不同,日志可以寫同一個

# cat php-fpm-9000.conf |grep  "^[^;]" -n

測試配置檔案是否正确

# /usr/local/php5.6/sbin/php-fpm -t -y etc/php-fpm-9000.conf

notice: configuration file etc/php-fpm-9000.conf test is successful

分别啟動php-fpm兩個服務程序

# /usr/local/php5.6/sbin/php-fpm -y etc/php-fpm-9000.conf

# /usr/local/php5.6/sbin/php-fpm -y etc/php-fpm-9001.conf

# netstat -nlp |grep fpm

tcp  0  0  127.0.0.1:9000  0.0.0.0:*    listen      29925/php-fpm       

tcp  0  0 127.0.0.1:9001  0.0.0.0:*    listen      29938/php-fpm

關閉服務的方法

# killall php-fpm

或單個擷取pid關閉

# cat var/run/php-fpm-9000.pid | xargs kill

測試php

在/var/www/html下建立個phpinfo.php,寫入

修改頁面檔案權限

# chmod 777 /var/www/html -r

# 然後打開http://localhost檢視,顯示php配置資訊,配置完成