一 安装nginx
nginx以fastcgi方式调用php
nginx-1.4.7.tar.gz
二 安装mysql
mysql-5.6.31-linux-glibc2.5-x86_64
三 安装php
php-5.6.9
1 安装依赖的文件(在epel中),有选择性的安装
libmcrypt libmcrypt-devel mhash mhash-devel mcrypt bzip2 bzip2-devel libcurl libcurl-devel libxml2 libxml2-devel
--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
四、整合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加速:
1、安装
# 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/
2、编辑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指令行,要确保此新增的行排在第一位。
3、重新启动php-fpm
# service php-fpm restart
六、补充说明
如果要在SSL中使用php,需要在php的location中添加此选项:
fastcgi_param HTTPS on;
来自为知笔记(Wiz)