Linux 6 under the compilation installation PHP 5.6 example details

  • 2020-06-03 09:03:23
  • OfStack

Linux 6 under the compilation installation PHP 5.6 example details

PHP (foreign name :PHP: Hypertext Preprocessor, Chinese name: hypertext Preprocessor) is a universal open source scripting language. The grammar absorbs the features of C language, Java and Perl, which is conducive to learning and widely used. It is mainly applicable to the development field of Web. PHP with its development source code, free, fast, cross-platform, efficient, object-oriented, powerful dynamic image creation and other functions by the majority of developers love. This article describes the installation of PHP 5.6.9 based on the compilation of CentOS 6.7, which is also suitable for installation of CentOS 7.

1. Related dependency package installation


1 , demonstration environment 


# more /etc/redhat-release 
CentOS release 6.7 (Final)

2 , extended support (mcrypt , mhash Extension and libevent)
 If you want to compile php support mcrypt , mhash Extension and libevent , the following packages need to be installed 
    libmcrypt
    libmcrypt-devel
    mhash
    mhash-devel

 Description: 
mcrypt The extended library can realize the function of encryption and decryption, that is, it can encrypt plaintext and restore ciphertext. 
mhash It's based on discrete mathematics and it's not invertible php Encryption extended library, which is not enabled by default. 
mhash Can be used to create check values, message digitations, message authentication codes, and to save key information (such as passwords) that does not require the original text. 

centos Source cannot be installed libmcrypt-devel , due to copyright reasons not shipped mcrypt The package 
 You can use the control 3 Source, this can also be used yum To install the 
 Installation of the first 3 party yum The source 
    # wget http://www.atomicorp.com/installers/atomic
    # sh ./atomic
 use yum Command to install 
    # yum install php-mcrypt libmcrypt libmcrypt-devel mhash mhash-devel

3 , libevent Related package 
 It can be installed as needed libevent , the system 1 A will bring libevent But the version is a little low. So you can upgrade and install the following two rpm The package. 
    # yum install libevent libevent-devel

 Description: 
libevent is 1 An asynchronous event notification library file, of which API Provides a mechanism to execute a callback function when an event occurs on a file description or when it times out 
 It is used primarily to replace those on event-driven web servers event loop Mechanism. 
 For now,  libevent support /dev/poll , kqueue , select , poll , epoll and Solaris the event ports . 

4 , support, xml The relevant package 
 support xml the rpm package 
bzip2  is 1 Based on Burrows-Wheeler  The lossless compression software of transformation can accomplish the compression of file data efficiently 
libcurl The main function is to connect and communicate with different servers using different protocols, which is quite encapsulated sockPHP 
libcurl Allows you to connect and communicate with different servers using different protocols 
    # yum install libxml2 libxml2-devel bzip2-devel libcurl-devel

5 , graphics-related rpm package 
 Common error message: JIS-mapped Japanese font support in GD
    # yum install libjpeg-devel libpng-devel freetype-devel

2. Compile and install php-5.6.9


 First download the source package to the local directory, download location http://mirrors.sohu.com/php/
# pwd
  /usr/local/src
# tar -xf php-5.6.9.tar.gz
# cd ..
# ~ln -sv ./src/php-5.6.9 php~  ### Note: This command is removed for brevity after compilation @20160729 
# cd php/
# ./configure \       ### Note: The compiled content has been adjusted @20160729
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-opcache \
--enable-fpm \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-pdo-mysql=/usr/local/mysql \
--with-gettext \
--enable-mbstring \
--with-iconv \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl \
--with-zlib \
--enable-zip \
--with-bz2 \
--with-gd \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir

### A detailed description of the compiled configuration items: https://segmentfault.com/a/1190000002717262
# make && make install
### The following is the prompt message after installation 
    Installing shared extensions: 
     /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
    Installing PHP CLI binary:   /usr/local/php/bin/
    Installing PHP CLI man page:  /usr/local/php/php/man/man1/
    Installing PHP FPM binary:   /usr/local/php/sbin/
    Installing PHP FPM config:   /usr/local/php/etc/
    Installing PHP FPM man page:  /usr/local/php/php/man/man8/
    Installing PHP FPM status page:  /usr/local/php/php/php/fpm/
    Installing PHP CGI binary:   /usr/local/php/bin/
    Installing PHP CGI man page:  /usr/local/php/php/man/man1/
    Installing build environment: /usr/local/php/lib/php/build/
    Installing header files:    /usr/local/php/include/php/
    Installing helper programs:  /usr/local/php/bin/
     program: phpize
     program: php-config
    Installing man pages:     /usr/local/php/php/man/man1/
     page: phpize.1    ### Author : Leshami
     page: php-config.1  ### Blog  : http://blog.csdn.net/leshami
    Installing PEAR environment:   /usr/local/php/lib/php/
    [PEAR] Archive_Tar  - installed: 1.3.12
    [PEAR] Console_Getopt - installed: 1.3.1 
    [PEAR] Structures_Graph- installed: 1.0.4 
    [PEAR] XML_Util    - installed: 1.2.3
    [PEAR] PEAR      - installed: 1.9.5
    Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
    You may want to add: /usr/local/php/lib/php to your php.ini include_path
    /usr/local/php/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
    ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar
    Installing PDO headers:     /usr/local/php/include/php/ext/pdo/

###php configuration 
    php.ini is php Run the core configuration file 
    php-fpm.conf is php-fpm The configuration file for the process service 

# cp php.ini-production /usr/local/php/etc/php.ini
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm

###fpm test php configuration 
# /usr/local/php/sbin/php-fpm -t
[23-May-2016 20:03:52] NOTICE: 
configuration file /usr/local/php/etc/php-fpm.conf test is successful

# chkconfig --add php-fpm
# chkconfig php-fpm on
# service php-fpm start
    Starting php-fpm done
# ps -ef|grep php
    root 45690 1 0 20:07 ? 00:00:00 php-fpm: master process(/usr/local/php/etc/php-fpm.conf)                                  
    nobody 45691 45690 0 20:07 ?   00:00:00 php-fpm: pool www                                                      
    nobody 45692 45690 0 20:07 ?   00:00:00 php-fpm: pool www                                                      
    root  45694  3441 0 20:07 pts/4 00:00:00 grep php

# netstat -nltp|grep 9000
    tcp 0  0 127.0.0.1:9000  0.0.0.0:*  LISTEN  45690/php-fpm  

3. Configure apache to access PHP


### Open the following modules 
# vim /etc/httpd24/httpd.conf   ### Note here that I have compiled and installed it separately httpd2.4 Version, so the path is different 
    LoadModule proxy_module modeles/mod_proxy.so
    LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

    AddType application/x-httpd-php .php  
    AddType application/x-httpd-php-source .phps

    ProxyRequests Off   ### Close the forward agent and turn on the downward reverse agent 
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/$1

# service httpd24 restart
    Stopping httpd24:       [ OK ]
    Starting httpd24:       [ OK ]

4. Verify PHP


### write 1 a php Test page 
# echo "
> <html>
> <h1>This is a php test page.</h1>
> <?php
> phpinfo();
> ?>
> </html>">>/usr/local/apache/htdocs/index.php 

### test PHP
# curl -I http://localhost:90/index.php
HTTP/1.1 200 OK
Date: Fri, 15 Jul 2016 03:16:50 GMT
Server: Apache/2.4.9 (Unix)
X-Powered-By: PHP/5.6.9
Content-Type: text/html; charset=UTF-8

5. For the case that mysql database is not installed on this machine (supplement @20160718)


PHP5.3 The above version, for links MySQL Database, which can be specified mysqlnd , so there is no need to install on the machine first MySQL or MySQL Development kit. 
mysqlnd from php 5.3 Available initially, you can bind to it at compile time (without being specific to it) MySQL Client library bindings form dependencies. 
 from PHP 5.4 Start, for unspecified --with-mysql The case, mysql The local driver will be installed. 
 You can refer to the following configuration: 

./configure        \ ### Modify the @20160729
  ..........       \ ### Ibid., just PI mysql The relevant parameter value is set to mysqlnd
--with-mysql       \ ### Equivalent to the value of the parameter is mysqlnd
--with-mysqli       \ ### Equivalent to the value of the parameter is mysqlnd
--with-pdo-mysql     \ ### Equivalent to the value of the parameter is mysqlnd

 The relevant mysqlnd For reference: 
http://php.net/manual/zh/mysqli.overview.php#mysqli.overview.mysqlnd

Thank you for reading, I hope to help you, thank you for your support to this site!


Related articles: