关于php-fpm
nginx本身不能处理PHP,它只是个web服务器,当接收到请求后,如果是php请求,则发给php解释器处理,并把结果返回给客户端。nginx一般是把请求发fastcgi管理进程处理,fascgi管理进程选择cgi子进程处理结果并返回被nginx。
PHP-FPM是一个PHP FastCGI管理器,是只用于PHP的。PHP在 5.3.3 之后已经讲php-fpm写入php源码核心了
apache默认是用自带的mod_php模块运行php,不需要fastcgi的支持,但是如果想使用fastcgi运行php也是可以单独安装的,毕竟fastcgi从稳定性、安全性、性能、扩展性还是有很多优点的,且可以在任何平台上运行。这次安装以Apache为例。
获取PHP源码
1 2 3 4
| wget http://cn2.php.net/get/php-5.6.30.tar.gz/from/this/mirror mv mirror php-5.6.30.tar.gz tar zxvf php-5.6.30.tar.gz cd php-5.6.30
|
安装依赖
1 2 3 4 5 6 7 8
| yum install libxml2 libxml2-devel -y yum install curl curl-devel -y yum install libpng libpng-devel -y yum install freetype freetype-devel -y yum install libxslt libxslt-devel -y yum -y install libjpeg-devel yum -y install libvpx-devel yum -y install libXpm-devel
|
编译安装php
1 2 3
| ./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysql --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip --with-apxs2=/usr/local/apache/bin/apxs --with-jpeg-dir --with-vpx-dir --with-gd --with-xpm-dir
make && make install
|
设置Php环境变量
1
| export PATH="$PATH:/usr/local/php/bin"
|
php.ini配置
1 2
| cp php.ini-development /usr/local/php/lib/php.ini 找到 always_populate_raw_post_data = -1 并将前面的井号删除
|
其它
有时候会出Apache不执行php代码,直接显示php代码情况,可以使用下面的方法解决,在httpd.conf增加下面的配置
1 2 3 4 5
| AddType application/x-httpd-php .php .phtml AddType application/x-httpd-php-source .phps AddHandler application/x-httpd-php .php
DirectoryIndex index.html index.htm index.php
|
重启Apache,service httpd restart就可以了