LINUX centos 多版本php安装记录

前言:服务器环境为 linux centos6.5, 原web环境为通过阿里云下载的一键安装服务,nginx+php5.3.29+mysql,在 不影响原有PHP5.3环境的情况下安装PHP7

 

1,编译安装PHP7

 

1,安装php7所需要的依赖

所需依赖是在主要是通过php7编译过程中 make test报错显示缺少的依赖

安装freetype

yum install freetype-devel

  

安装iconv

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz #下载 或1.14
tar zxvf libiconv-1.15.tar.gz && cd libiconv-1.15
./configure --prefix=/usr/local/libiconv
make
make install 

2,创建php7安装的目标目录

mkdir /alidata/server/php-7.2.15
ln -s /alidata/server/php-7.2.15 php7
#些目录是将php7安装的目标目录,方便管理,此目录在运行./configure时作为配置使用

  

3,增加php7用户组和用户 用来管理PHP7的

groupadd php7

useradd -g php7 php7

 

 

4,官网下载

地址: http://php.net/downloads.php 下载版本为php-7.2.15.tar.gz 我下载到了到 /dingfei目录

解压 tar zxvf php-7.2.15.tar.gz && cd php-7.2.15

5,运行 ./configure 其中参数内容主要为将php7安装到第2步中创建的php7目录和配置php7要安装的扩展功能,此处要检查好再运行,不要将php7安装成了默认目录,以免影响原版本php使用

#运行
./configure \
--prefix=/alidata/server/php7 \
--exec-prefix=/alidata/server/php7 \
--bindir=/alidata/server/php7/bin \
--sbindir=/alidata/server/php7/sbin \
--includedir=/alidata/server/php7/include \
--libdir=/alidata/server/php7/lib/php \
--mandir=/alidata/server/php7/php/man \
--with-config-file-path=/alidata/server/php7/etc \
--with-mysql-sock=/tmp/mysql.sock \
--with-mcrypt \
--with-mhash \
--with-openssl \   #如果openssl已经重新安装需要配置路径--with-openssl=/usr/local/openssl \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gd \
--with-iconv=/usr/local/libiconv \
--with-zlib \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache \
--enable-fpm \
--enable-fastcgi \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--without-gdbm \
--with-fileinfo \
#--disable-fileinfo #执行过程中注意是否有错误,如无错误进行下一步,如有错误解决错误。

 

6,编译安装

依次运行
make
make test
make install
#在此三步运行过程中可能报错,一般是依赖问题,如有依赖问题,就先安装依赖后再重新configure 编译安装,其它问题可在网上查找问题原因和解决方式,直到make install成功

  

7,安装完成

安装完成后,可以目标目录/alidata/server/php7中查看到以下php目录

bin  etc  include  lib  php   sbin  var

  

进入其中的bin目录

#运行以下命令,查看是否显示php7的版本信息,注意是./php,不是php
./php -version

  

 

 

 

2,配置PHP7

1,创建php.ini

#php.ini是从下载的安装目录中拷贝的
cp /dingfei/php-7.2.15/php.ini-production /alidata/server/php7/etc/php.ini 

  

 

3,将php7命令配置为系统命令

但系统命令php已经被php5.3使用,所以命令改为php7

 

cp /alidata/server/php7/bin/php /alidata/server/php7/phpbin/php7
cp /alidata/server/php7/bin/php-cgi /alidata/server/php7/phpbin/php7-cgi
cp /alidata/server/php7/bin/php-config /alidata/server/php7/phpbin/php7-config
cp /alidata/server/php7/sbin/php-fpm /alidata/server/php7/phpbin/php7-fpm
cp /alidata/server/php7/bin/phpdbg /alidata/server/php7/phpbin/phpdbg7
cp /alidata/server/php7/bin/phpize /alidata/server/php7/phpbin/phpize7
#修改 /etc/profile
#文件最后加入
export PATH=$PATH:/alidata/server/php7/php7bin
#修改完成后,重新登录bash,
#运行命令php7 -version,查看是否正常显示php7

 

 

 

 

4,配置php7-fpm

1,php7-fpm配置文件

#php-fpm配置文件主要为php-fpm.conf这个文件包含了php-fpm.d/*.conf
cp /alidata/server/php7/etc/php-fpm.conf.default /alidata/server/php7/etc/php-fpm.conf
cp /alidata/server/php7/etc/php-fpm.d/www.conf.default /alidata/server/php7/etc/php-fpm.d/www.conf 
#修改php-fpm.conf 查找pid = 字符串改为 pid = /alidata/server/php7/var/run/php7-fpm.pid
#9,修改 /alidata/server/php7/etc/php-fpm.d/www.conf 将group和user改为php7 查找9000,改为9007,让php7fpm监听商口为9007,让原php5.3的fpm监听9000而php7监听9007

 

2,将php7-fpm设置为开机启动

cp /alidata/server/php7/php7bin/php7-fpm /etc/rc.d/init.d/php7-fpm

 

 

5,创建Nginx测试站点使用PHP7

1,编辑/alidata/server/nginx/conf/nginx.conf

#/alidata/server/nginx/conf/nginx.conf文件尾增加
include /alidata/server/nginx/conf/vhostsphp7/*.conf;

 

2,在/alidata/server/nginx/conf/vhostsphp7中增加 php7test.conf 配置一个测试虚拟主机


#创建目录 mkeir /alidata/server/nginx/conf/vhostsphp7
#创建目录 mkeir /alidata/wwwphp7
#php7test.conf 内容   


server {
        listen       80;
        server_name test.test.com;
        root /alidata/wwwphp7/php7test;
        index index.php index.html index.htm;
        error_page 502 /error/502.php;  
        location ~ \.php {
            include        fastcgi_params;
            set $real_script_name $fastcgi_script_name;
            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;
            fastcgi_pass   127.0.0.1:9007;
            fastcgi_index  index.php;
        }
        access_log /alidata/server/nginx-1.4.4/logs/php7test/access_merchant.log;
    }


   server {
        listen       443 default ssl;
        ssl on;
        ssl_certificate "/alidata/server/nginx/conf/ssl/php7test/server.crt";
        ssl_certificate_key  "/alidata/server/nginx/conf/ssl/php7test/server.key";
 
        server_name test.test.com;
        root /alidata/wwwphp7/php7test;
        location / {
            index  index.html index.htm index.php;
            autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9007;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}


#ssl 证书和密钥是
 

 

3,创建目录/alidata/wwwphp7/php7test 在目录中创建文件phpinfo.php 

<?php
phpinfo();

 

4,浏览器中访问test.test.com/phpinfo.php 测试是否成功访问并,显示php版本为php7

如果显示php版本为7.2.15,则说明配置成功。访问前需要重启nginx并开启php7-fpm,可以重启一下服务器再访问。

5,浏览器中访问https://test.test.com/phpinfo.php 测试https是否能正常访问

 

6,其它

1,单独安装fileinfo扩展

安装完成后,使用composer安装Laravel时报错没有fileinfo扩展,单独安装方法为

cd /dingfei/php-7.2.15/ext/fileinfo

/alidata/server/php7/php7bin/phpize7 
./configure --with-php-config=alidata/server/php7/php7bin/php7-config
make && make install

#在/alidata/server/php7/etc/php.ini添加扩展:
extension=fileinfo.so
#重启php7-fpm restart 
#或 ps aux | grep php-fpm  
#kill pid    && php7-fpm

  

 

参考

参考链接1,https://blog.51cto.com/longlei/2294212

参考链接2,https://www.cnblogs.com/da-guang/p/6973868.html

参考链接2,https://blog.csdn.net/daily886/article/details/79758160

参考链接2,https://my.oschina.net/cxgphper/blog/2050523

 

 

 

 

centos6.5 php5.3.29安装phpredis

下载:https://codeload.github.com/phpredis/phpredis/tar.gz/4.1.1

安装:

$cd phpredis

$/alidata/server/php-5.3.29/bin/phpize

$./configure --with-php-config=/alidata/server/php-5.3.29/bin/php-config

$ vim /alidata/server/php-5.3.29/etc/php.ini

增加 extension=redis.so

 

centos6.5 php7安装phpredis

下载:https://codeload.github.com/phpredis/phpredis/tar.gz/4.3.0

安装:

$cd phpredis

$/alidata/server/php-7.2.15/php7bin/phpize7

$./configure --with-php-config=/alidata/server/php-7.2.15/php7bin/php-config

$ vim /alidata/server/php-7.2.15/etc/php.ini

extension_dir="/alidata/server/php7/lib/php/extensions/no-debug-non-zts-20170718/"

增加 extension=redis.so

 

 

 

 

 

1,安装Php7.3.8

下载路径:https://www.php.net/distributions/php-7.3.8.tar.gz

解压 tar zxvf php-7.3.8.tar.gz && cd php-7.3.8

./configure \
--prefix=/alidata/server/php-7.3.8 \
--exec-prefix=/alidata/server/php-7.3.8 \
--bindir=/alidata/server/php-7.3.8/bin \
--sbindir=/alidata/server/php-7.3.8/sbin \
--includedir=/alidata/server/php-7.3.8/include \
--libdir=/alidata/server/php-7.3.8/lib/php \
--mandir=/alidata/server/php-7.3.8/php/man \
--with-config-file-path=/alidata/server/php-7.3.8/etc \
--with-mysql-sock=/tmp/mysql.sock \
--with-mcrypt \
--with-mhash \
--with-openssl \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gd \
--with-iconv=/usr/local/libiconv \
--with-zlib \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache \
--enable-fpm \
--enable-fastcgi \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--without-gdbm \
--with-fileinfo

make 

make install

编译安装过程中出现错误可参考此连接 https://www.php.cn/php-weizijiaocheng-414091.html

其中安装最新版本libzip(https://libzip.org/download/)需要安装cmake

cmake 下载地址:https://github.com/Kitware/CMake/releases

下载完成后vim /etc/profile 

加入export PATH=$PATH:/usr/local/cmake/bin

运行source /etc/profile

cmake --version查看cmake是否安装成功

cmake安装成功后

tar libzip.tar.gz && cd libzip

mkdir build&&cd build

cmake ..

make && make install

posted @ 2019-02-22 10:51  cyberpunk_blog  阅读(38)  评论(0)    收藏  举报