nginx以fastcgi方式調用phphtml
nginx-1.4.7.tar.gz
mysql
二 安裝mysqllinux
mysql-5.6.31-linux-glibc2.5-x86_64
nginx
三 安裝phpweb
php-5.6.9
sql
1 安裝依賴的文件(在epel中),有選擇性的安裝vim
libmcrypt libmcrypt-devel mhash mhash-devel mcrypt bzip2 bzip2-devel libcurl libcurl-devel libxml2 libxml2-develapi
--with-snmp選項則用於實現php的SNMP擴展,但此功能要求提早安裝net-snmp相關軟件包。
瀏覽器
2 安裝php
# tar xf php-5.4.4.tar.bz2
# cd php-5.4.4
# ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-mysql=/usr/local/mysql \
--with-openssl \
--enable-fpm \
--enable-sockets \
--enable-sysvshm \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-libxml-dir \
--enable-xml \
--with-mhash \
--with-mcrypt \
--with-bz2 \
--with-curl
說明:
--with-config-file-path=PATH Set the path in which to look for php.ini [PREFIX/lib]
--with-config-file-scan-dir=PATH Set the path where to scan for configuration files
# make
# make test
# make intall
2 爲php提供配置文件:
# cp php.ini-production /etc/php.ini
3 爲php-fpm提供配置文件:
# cd /usr/local/php/etc/
# mv php-fpm.conf.default php-fpm.conf
# vim /usr/local/php/etc/php-fpm.conf
配置fpm的相關選項爲你所須要的值,並啓用pid文件(以下最後一行):
pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 10
4 爲php-fpm提供Sysv init腳本,並將其添加至服務列表:
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
5 啓動php-fpm
# service php-fpm start
6 使用以下命令來驗正(若是此命令輸出有中幾個php-fpm進程就說明啓動成功了):
# ps aux | grep php-fpm
4、整合nginx和php5
1 編輯/etc/nginx/nginx.conf,啓用以下選項:
location ~ \.php$ {
root /web/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
2 編輯/etc/nginx/fastcgi_params,將其內容更改成以下內容:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
3 並在所支持的主頁面格式中添加php格式的主頁,相似以下:
location / {
root html;
index index.php index.html index.htm;
}
4 從新載入nginx的配置文件:
# service nginx reload
5 在/usr/html新建index.php的測試頁面,測試php是否能正常工做:
# cat > /usr/html/index.php << EOF
<?php
phpinfo();
?>
接着就能夠經過瀏覽器訪問此測試頁面了。
五 安裝xcache,爲php加速:
一、安裝
# tar xf xcache-3.2.0.tar.gz
# cd xcache-3.2.0
# /usr/local/php/bin/phpize
# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
# make && make install
安裝結束時,會出現相似以下行:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
二、編輯php.ini,整合php和xcache:
首先將xcache提供的樣例配置導入php.ini
# mkdir /etc/php.d
# cp xcache.ini /etc/php.d
說明:xcache.ini文件在xcache的源碼目錄中。
新版的xcache此處不用修改
接下來編輯/etc/php.d/xcache.ini,找到zend_extension開頭的行,修改成以下行:
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
注意:若是php.ini文件中有多條zend_extension指令行,要確保此新增的行排在第一位。
三、從新啓動php-fpm
# service php-fpm restart
6、補充說明
若是要在SSL中使用php,須要在php的location中添加此選項:
fastcgi_param HTTPS on;