您的位置:首页 > 编程语言 > PHP开发

php7 安装 及和php5的共存

2016-04-15 10:30 741 查看
http://blog.csdn.net/liuxinmingcode/article/details/50319145

LNMP

FastCGI 是一个可伸缩地、高速地在HTTP server和动态脚本语言间通信的接口。

HTTP server 是 Apache,nginx等,而动态语言 包括php。

Nginx -> PHP-FastCGI -> PHP

Nginx中根据需求配置调用不同的PHP-FastCGI的访问端口,即可实现不同版本PHP共存了。

一、已有php5.5.7

二、安装php7.0.5

1、下载 php.net wget命令

2、解压 tar命令

3、配置 ./configure 默认配置 可添加修改 注意此处可用 ./configure -h 查看所有选项

3.1、设置不同的安装目录 –prefix=/alidata/server/php7 (原po此处设置了其他目录)

3.2、添加模块 -with-... 即可,

3.3、开启模块,重要是开启fpm -enable-fpm

3.4、7.1要求openssl版本,需要先升级openssl,并添加--with-openssl=/usr/local/ssl (openssl version -a 查看openssl目录)

4、编译 make 即可,可能会报错:make: *** [sapi/cli/php] error 1 ,使用

make ZEND_EXTRA_LIBS='-liconv'


5、安装

make install


6、配置文件

6.1、源代码目录下 php.ini应该放在/usr/local/lib,见补记4

cp php.ini-production /路径/php7/etc/php.ini #复制php.ini配置
cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm #复制php-fpm启动脚本


6.2、 安装目录下 (配置文件)

# cp /路径/php7/etc/php-fpm.conf.default /路径/php7/etc/php-fpm.conf
# cp /路径/php7/etc/php-fpm.d/www.conf.default /路径/php7/etc/php-fpm.d/www.conf


6.3、修改监听端口

www.conf这个配置文件配置 linsten 127.0.0.1:9001

7、启动php7-fpm

chmod 755 /etc/init.d/php-fpm
/etc/init.d/php7-fpm start


8、环境变量 (可选)

echo -e '\nexport PATH=/路径/php7/bin:/路径/php7/sbin:$PATH\n' >> /etc/profile && source /etc/profile


9、Nginx配置FastCGI 访问 PHP7 (按需配置)

location ~ .*.(php|php5)?$
{
fastcgi_pass  127.0.0.1:9001; #注意此端口
fastcgi_index index.php;
include fcgi.conf;
}


即可正常访问。

补记

1、遇到 session 的开启问题,查网络是session.save_path 的设置问题,但我php5.5也是默认没设置

最后,直接清空 tmp目录后正常(1、so上有人说tmp满了(不太可能,2、session文件冲突)

2、php7默认模块比较少(php5不是我自己安装,估计也比较少),自己添加:

./configure
-prefix=/usr/local/php
--with-config-file-path=/usr/local/php/etc
--with-config-file-scan-dir=/usr/local/php7/etc/php.d
-with-mcrypt
-with-mhash
-with-openssl
-with-mysqli
--with-pdo-mysql
-with-gd
-with-iconv
-with-zlib
-with-curl
-enable-zip
-enable-inline-optimization
-enable-sockets
-enable-soap
-enable-session
-enable-opcache
--enable-mysqlnd
-enable-fpm
--disable-fileinfo
--enable-mbstring


3、php-fpm支持的操作:

start,启动PHP的FastCGI进程。

stop,强制终止PHP的FastCGI进程。

quit,平滑终止PHP的FastCGI进程。

restart, 重启PHP的FastCGI进程。

reload, 重新加载PHP的php.ini。

logrotate, 重新启用log文件。

4、Php.ini位置修改方法如下:

php默认php.ini文件放在/usr/local/lib内,可以在编译的时候使用--with-config-file-path参数来修改php.ini的存放位置,例如你可以使用--with- config-file-path=/etc把它存放到/etc下面,然后可以从源码包中拷贝php.ini到/etc/php.ini。

注意,不要忘记修改时区 data.timezone = “Asia/Shanghai”

5、配置openssl位置

./configure
--prefix=/alidata/server/php71
--with-config-file-path=/alidata/server/php71/etc
--with-config-file-scan-dir=/alidata/server/php71/etc/php.d
--with-mcrypt
--with-mhash
--with-mysqli
--with-pdo-mysql
--with-gd
--with-iconv
--with-zlib
--with-curl
--enable-zip
--enable-inline-optimization
--enable-sockets
--enable-soap
--enable-session
--enable-opcache
--enable-mysqlnd
--enable-fpm
--disable-fileinfo
--enable-mbstring
--with-openssl=/usr/local/ssl
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: