PHP5 Coexistence PHP7

Source: Internet
Author: User
Tags fpm gmp php source code readline redis sapi git clone

/usr/local/php7/bin/phpize # According to the personal path, if it is a php5 extension module, this is not the result.

PHP7 and PHP5 coexist in CentOS7


Original reference


Principle


The idea is simple: PHP5 is installed through Yum in/usr/, sockets in/VAR/RUN/PHP-FPM.SOCKET,PHP7 themselves compiled in/USR/LOCAL/PHP7, sockets in/var/run/ PHP7-FPM.SOCKET,NIGNX Specifies fastcgi_pass according to the environment in which the application needs to run.
or two different ports, one using the default 9000, one using 9002


Compiling and installing PHP7

Yum installs various dependency packages required for compilation

 
 
   yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel -y

Then to the official website to download the latest PHP source code, unzip

   cd ~
    wget http://am1.php.net/distributions/php-7.1.8.tar.gz
    tar xvf  php-7.1.8.tar.gz
    cd php-7.1.8

Then set the compilation parameters, here are a few things to mention:

    1. In order to reduce the subsequent problems due to permissions, it is recommended to use Nginx and php-fpm with the same user and user group (--with-fpm-user=nginx--with-fpm-group=nginx)
    2. To reduce the problems caused by complex network environments such as multiple NICs, turn off IPv6 support (--disable-ipv6) without using the IPv6 network. Choose according to your own situation
    3. Open the MySQL database API extension (--WITH-MYSQLI=MYSQLND--WITH-PDO-MYSQL=MYSQLND)
    4. Open Opcache Extension (--enable-opcache)


Full compilation parameters:


  ./configure     --prefix=/usr/local/php7     --with-config-file-path=/usr/local/php7/etc     --with-config-file-scan-dir=/usr/local/php7/etc/php.d/     --disable-ipv6      --enable-fpm     --with-fpm-user=nginx      --with-fpm-group=nginx     --enable-inline-optimization     --disable-debug     --disable-rpath     --enable-shared      --enable-soap     --with-libxml-dir     --with-xmlrpc     --with-openssl     --with-mcrypt     --with-mhash     --with-pcre-regex     --with-sqlite3     --with-zlib     --enable-bcmath     --with-iconv     --with-bz2     --enable-calendar     --with-curl     --with-cdb     --enable-dom     --enable-exif     --enable-fileinfo     --enable-filter     --with-pcre-dir     --enable-ftp     --with-gd     --with-openssl-dir     --with-jpeg-dir     --with-png-dir     --with-zlib-dir      --with-freetype-dir     --enable-gd-native-ttf     --enable-gd-jis-conv     --with-gettext     --with-gmp     --with-mhash     --enable-json     --enable-mbstring     --enable-mbregex     --enable-mbregex-backtrack     --with-libmbfl     --with-onig     --enable-pdo     --with-mysqli=mysqlnd     --with-pdo-mysql=mysqlnd     --with-zlib-dir     --with-pdo-sqlite     --with-readline     --enable-session     --enable-shmop     --enable-simplexml     --enable-sockets      --enable-sysvmsg     --enable-sysvsem     --enable-sysvshm     --enable-wddx     --with-libxml-dir     --with-xsl     --enable-zip     --enable-mysqlnd-compression-support     --with-pear     --enable-opcache


 After the setup check is passed, the make and make install is loved, and you are interested in doing test before you install. 

Ps:make test is time-consuming, but it's almost like make install, and after make test, direct make install quickly


Configure PHP7

   cp php.ini-production /usr/local/php7/etc/php.ini
    cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
    cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

Modify the appropriate configuration file (as required), the following is the configuration time zone


date.timezone ="Asia/Shanghai"

A.CENTOS7 Version Startup file modification


Make install error-free installation begins configuration, first copy the default configuration to the specified location

cp -R ./sapi/fpm/php-fpm.service /usr/lib/systemd/system/php7-fpm.service

 
/usr/lib/systemd/system/php7-fpm.service

Modify the corresponding path just fine ... I didn't test it either.



B.CENTOS6 Version Startup file modification


Cp -R ./sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm # This will not conflict when starting up.
     Chmod +x /etc/init.d/php7-fpm

Modify the startup item name VI/ETC/INIT.D/PHP7-FPM


    prefix=/usr/local/php7
    exec_prefix=${prefix}
    
    php_fpm_BIN=${exec_prefix}/sbin/php7-fpm
    php_fpm_CONF=${prefix}/etc/php7-fpm.conf
    php_fpm_PID=${prefix}/var/run/php7-fpm.pid

Add power-on start, build soft Connect


Chkconfig --add php7-fpm
Chkconfig php7-fpm on # These two steps are selected according to your needs
Ln -s /usr/local/php7/bin/php /usr/bin/php
Start PHP7-FPM


Centos7


systemctl enable php7-fpm.service   
systemctl start  php7-fpm.service


Centos6


sudo /etc/init.d/php7-fpm restart
Compile error handling
 
#Found a similar error libiconv_open because the content could not be found

PHP7 compile and install encountered undefined reference to `libiconv_open ‘ problem solution system environment centos6.7

I get an error while making install :

Ext/gd/libgd/.libs/gdkanji.o: In function `do_convert‘:
/root/src/php-7.1.3/ext/gd/libgd/gdkanji.c:349: undefined reference to `libiconv_open‘
/root/src/php-7.1.3/ext/gd/libgd/gdkanji.c:364: undefined reference to `libiconv‘
/root/src/php-7.1.3/ext/gd/libgd/gdkanji.c:380: undefined reference to `libiconv_close‘
Ext/iconv/.libs/iconv.o: In function `php_iconv_stream_filter_dtor‘:
/root/src/php-7.1.3/ext/iconv/iconv.c:2565: undefined reference to `libiconv_close‘
Ext/iconv/.libs/iconv.o: In function `php_iconv_stream_filter_ctor‘:
/root/src/php-7.1.3/ext/iconv/iconv.c:2591: undefined reference to `libiconv_open‘
Ext/iconv/.libs/iconv.o: In function `_php_iconv_strlen‘:
/root/src/php-7.1.3/ext/iconv/iconv.c:754: undefined reference to `libiconv_open‘
/root/src/php-7.1.3/ext/iconv/iconv.c:778: undefined reference to `libiconv‘
/root/src/php-7.1.3/ext/iconv/iconv.c:812: undefined reference to `libiconv_close‘

Solution:

Vim Makefile, add "-liconv":
The result is as follows:

EXTRA_LIBS = -lcrypt -lresolv -lcrypt -lrt -lpng -lz -lcurl -lz -lrt -lm -ldl -lnsl -lxml2 -lz -lm -ldl -lcurl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lcrypt -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lcrypt -liconv

Make install again
Installing the Extension Module MySQL module


Since PHP starting from 5.x, PHP connection to MySQL regardless of which method is used Mysqlnd driver, and PHP7 has officially removed the MySQL extension, due to the new features, PHP7 for the database host address is localhost and 127.0.0.1, respectively, will use Unix Domain sockets and TCP/IP two different ways to connect to the MySQL service.



With UNIX domain sockets, PHP7 uses the default/tmp/mysql.sock as the socket, but CentOS7 the default MySQL service mariadb socket location is/var/lib/mysql/ Mysql.sock, so that even if all the database connection information is correct, such as "Mysqli::real_connect (): (hy000/2002): No such file or directory" and "error Establishing a database Connection "error message.



However, our company is using--WITH-PDO-MYSQL=MYSQLND so there is no MySQL connection problem, here to meet the classmate a link Php7_mysql expansion module installation


Redis Module


1.git Clone:


git clone  https://github.com/phpredis/phpredis.git


Official website: Https://github.com/phpredis/phpredis



To switch branches:


git checkout -b php7 origin/php7


2. Check the PHP extension


/usr/local/php7/bin/phpize # According to the personal path, if it is a php5 extension module, this is not the result.


3. Establish a compilation connection, install


./configure --with-php-config=/usr/local/php7/bin/php-configmakemake testmake install


4. Check the so file


Cd /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303
# The home directory here is different, mainly the last level of the directory name
Ls


5. Modify PHP.ini


Vi /usr/local/php7/etc/php.ini
Add: extension="redis.so"


6. Check the module


Php7 -m |grep redis
# php -m is to check the extension module

If there is a redis, it means normal.


7. Restart PHP-FPM

sudo /etc/init.d/php7-fpm restart
Nginx Configuration

The corresponding PHP boot different ports, or socket mode,

# fastcgi_pass  unix:/var/run/php7-fpm.socket;
fastcgi_pass fastcgi_pass   127.0.0.1:9002;


PHP5 Coexistence PHP7


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.