原文:http://www.woyaohuijia.cn/show/58.html

一、安装php5.5

1、安装依赖包

yum -y install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel libaio


2、安装php5.5

wget http://cn2.php.net/get/php-5.5.10.tar.gz/from/cn2.php.net/mirror

tar -zxvf mirror

cd php-5.5.10

./configure \

--prefix=/usr/local/php5 \

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

--with-bz2 \

--with-curl \

--enable-ftp \

--enable-sockets \

--disable-ipv6 \

--with-gd \

--with-jpeg-dir=/usr/local \

--with-png-dir=/usr/local \

--with-freetype-dir=/usr/local \

--enable-gd-native-ttf \

--with-iconv-dir=/usr/local \

--enable-mbstring \

--enable-calendar \

--with-gettext \

--with-libxml-dir=/usr/local \

--with-zlib \

--with-pdo-mysql=mysqlnd \

--with-mysqli=mysqlnd \

--with-mysql=mysqlnd \ //PHP7安装是注意,configure中没有这一项

--enable-dom \

--enable-xml \

--with-libdir=lib64 \

--enable-pdo \

--enable-fpm //使用nginx必须启用


编译过程有可能报如下错误:

checking for known struct flock definition… configure: error: Don’t know how to define struct flock on this system, set –enable-opcache=no

解决方法:

yum groupinstall "Development tools"

说明:以上配置根据自己需要选择就行,如果使用nginx+php,就必须使用php-fpm。

make

make install

3、配置php5.5

//--with-config-file-path=/path 指定的目录

cp php.ini-production /usr/local/php5/etc/php.ini  #php配置文件

cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf #php-fpm配置文件

4、启动php-fpm

/usr/local/php5/sbin/php-fpm start    //启动

/usr/local/php5/sbin/php-fpm stop    //停止

/usr/local/php5/sbin/php-fpm reload    //重新加载


查看是否启动成功:

netstat -lnt | grep 9000

tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN

或者使用如下命令,查看是否9000端口被php-fpm占用:

netstat -tunpl | grep 9000

tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      2124/php-fpm


查看进行运行转台

ps -ef | grep php-fpm


5、php-fpm.conf配置文件

vim /usr/local/php5/etc/php-fpm.conf

打开pid = run/php-fpm.pid前的注释,这样fpm的进程就会被写入这个文件:/usr/local/php5/var/run/php-fpm.pid


php-fpm 关闭:

kill -INT `cat /usr/local/php5/var/run/php-fpm.pid`

或者:pkill php-fpm

php-fpm 重启:

kill -USR2 `cat /usr/local/php5/var/run/php-fpm.pid`

修改了php.ini后要记得重启php-fpm。


二、PHP+Nginx配置

1、http下增加如下内容:

fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2 keys_zone=TEST:10m inactive=5m; 

fastcgi_connect_timeout 300;   

fastcgi_send_timeout 300;   

fastcgi_read_timeout 300;   

fastcgi_buffer_size 64k;   

fastcgi_buffers 4 64k;   

fastcgi_busy_buffers_size 128k;   

fastcgi_temp_file_write_size 128k;   

fastcgi_cache TEST;   

fastcgi_cache_valid 200 302 1h;   

fastcgi_cache_valid 301 1d;   

fastcgi_cache_valid any 1m; 


下面是对上述代码的含义进行介绍。

第一行代码是为FastCGI缓存指定一个文件路径、目录结构等级、关键字区域存储时间和非活动删除时间。

fastcgi_connect_timeout:指定连接到后端FastCGI的超时时间。

fastcgi_send_timeout:指定向FastCGI传送请求的超时时间,这个值是已经完成两次握手后向FastCGI传送请求的超时时间。

fastcgi_read_timeout:指定接收FastCGI应答的超时时间,这个值是已经完成两次握手后接收FastCGI应答的超时时间。

fastcgi_buffer_size:用于指定读取FastCGI应答第一部分需要用多大的缓冲区,这个值表示将使用1个64KB的缓冲区读取应答的第一部分(应答头),可以设置为fastcgi_buffers选项指定的缓冲区大小。

fastcgi_buffers:指定本地需要用多少和多大的缓冲区来缓冲FastCGI的应答请求。如果一个PHP脚本所产生的页面大小为256KB,那么会为其分配4个64KB的缓冲区来缓存;如果页面大小大于256KB,那么大于256KB的部分会缓存到fastcgi_temp指定的路径中,但是这并不是好方法,因为内存中的数据处理速度要快于硬盘。一般这个值应该为站点中PHP脚本所产生的页面大小的中间值,如果站点大部分脚本所产生的页面大小为256KB,那么可以把这个值设置为“16 16k”、“4 64k”等。

fastcgi_busy_buffers_size:的默认值是fastcgi_buffers的两倍。

fastcgi_temp_file_write_size:表示在写入缓存文件时使用多大的数据块,默认值是fastcgi_buffers的两倍。

fastcgi_cache:表示开启FastCGI缓存并为其指定一个名称。开启缓存非常有用,可以有效降低CPU的负载,并且防止502错误的发生,但是开启缓存也会引起很多问题,要视具体情况而定。

fastcgi_cache_valid:fastcgi用来指定应答代码的缓存时间,实例中的值表示将200和302应答缓存一个小时,将301应答缓存1天,其他应答均缓存1分钟。

2、server下配置如下内容:

        location ~* \.(php[3-9]?|phtm[l]?)(\/.*)*$ {

                fastcgi_index index.php;

                fastcgi_pass 127.0.0.1:9000;

                include fastcgi_params;

                set $path_info "";

                set $real_script_name $fastcgi_script_name;

                if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {

                        set $real_script_name $1;

                        set $path_info $2;

                }

                fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;

                fastcgi_param SCRIPT_NAME $real_script_name;

                fastcgi_param PATH_INFO $path_info;

        }

这里的配置方式可以支持CI、ThinkPHP等基于PATH_INFO的请求方式。


三、以下是安装PHP7时候遇见的一些问题

//错误 make: *** [sapi/cli/php] Error 1
make ZEND_EXTRA_LIBS='-liconv'
ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/
//错误make: [ext/phar/phar.phar] Error 1 (ignored)
http://php.net/manual/zh/configure.about.php

http://php.net/distributions/php-7.0.7.tar.gz
yum install libmcrypt libmcrypt-devel mcrypt mhash
/var/lib/mysql/mysql.sock
libmcrypt-2.5.8.tar.gz
下载地址:http://sourceforge.net/project/showfiles.php?group_id=87941&package_id=91774&release_id=487459
mhash-0.9.9.tar.gz
下载地址:http://sourceforge.net/project/showfiles.php?group_id=4286&package_id=4300&release_id=645636
mcrypt-2.6.8.tar.gz
下载地址:http://sourceforge.net/project/showfiles.php?group_id=87941&package_id=91948&release_id=642101


http://www.cnblogs.com/zhuhongbao/archive/2013/06/04/3118061.html
//Nginx安装
一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。
2.安装PCRE库
cd ~/src
//pcre下载地址 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
tar -zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure
make
make install

安装zlib库
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make install

安装ssl
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
tar -zxvf openssl-1.0.1c.tar.gz
./config
make
make install
安装Nginx
tar -zxvf nginx-1.10.0.tar.gz
cd nginx-1.10.0  
./configure --prefix=/usr/local/nginx
--with-pcre=/root/src/pcre-8.38 指的是pcre-8.38 的源码路径。
--with-zlib=/root/src/zlib-1.2.8 指的是zlib-1.2.8 的源码路径。
make
make install
//启动
确保系统的 80 端口没被其他程序占用,
/usr/local/nginx/sbin/nginx
检查是否启动成功:
netstat -ano|grep 80 有结果输入说明启动成功
打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。
//重启
/usr/local/nginx/sbin/nginx –s reload
//PHP7安装
./configure \
--prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--with-bz2 \
--with-curl \
--enable-ftp \
--enable-sockets \
--disable-ipv6 \
--with-gd \
--with-jpeg-dir=/usr/local \
--with-png-dir=/usr/local \
--with-freetype-dir=/usr/local \
--enable-gd-native-ttf \
--with-iconv-dir=/usr/local \
--enable-mbstring \
--enable-calendar \
--with-gettext \
--with-libxml-dir=/usr/local \
--with-zlib \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--enable-dom \
--enable-xml \
--with-libdir=lib64 \
--enable-pdo \
--enable-fpm
//常见错误处理
http://www.poluoluo.com/jzxy/201505/364819.html
make: *** [sapi/cli/php] Error 1
make ZEND_EXTRA_LIBS='-liconv'
ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/