Linux 6 under Compile and install PHP 5.6

Source: Internet
Author: User
Tags fpm mcrypt pear php cli


PHP (foreign name: Php:hypertext Preprocessor, Chinese name: "Hypertext Preprocessor") is a common open source scripting language. The grammar absorbs the C language, Java and Perl features, is conducive to learning, widely used, mainly for the field of web development. PHP with its development source code, free, fast, cross-platform, efficient, object-oriented, powerful dynamic image creation and other functions by the vast number of developers love. This document describes the installation of PHP 5.6.9 based on the CentOS 6.7 compiler.

One, related dependent package installation

1. Demo environment
# more / etc / redhat-release
CentOS release 6.7 (Final)

2. Extended support (mcrypt, mhash extension and libevent)
If you want the compiled PHP to support mcrypt, mhash extension and libevent, you need to install the following packages
        libmcrypt
        libmcrypt-devel
        mhash
        mhash-devel

Description:
The mcrypt extension library can realize encryption and decryption functions, that is, it can both encrypt plaintext and restore ciphertext.
mhash is an irreversible PHP encryption extension library based on the principle of discrete mathematics, which is not enabled by default.
mhash can be used to create check values, message digests, message authentication codes, and key information storage (such as passwords) that do not require original text.

The centos source cannot install libmcrypt-devel, due to copyright reasons, there is no mcrypt package
You can use a third-party source, so you can also use yum to install
Install a third-party yum source
        # wget http://www.atomicorp.com/installers/atomic
        # sh ./atomic
Install with yum command
        # yum install php-mcrypt libmcrypt libmcrypt-devel mhash mhash-devel

3. libevent related packages
You can install libevent as needed. The system generally comes with libevent, but the version is a bit low. Therefore, the following two rpm packages can be upgraded and installed.
        # yum install libevent libevent-devel

Description:
libevent is an asynchronous event notification library file, its API provides a mechanism to execute a callback function when an event occurs on a file description or when it times out
It is mainly used to replace the event loop mechanism on the event-driven network server.
Currently, libevent supports / dev / poll, kqueue, select, poll, epoll, and Solaris event ports.

4. Related packages supporting xml
Support xml rpm package
bzip2 is a lossless compression software based on Burrows-Wheeler transform that can efficiently compress file data
The main function of libcurl is to connect and communicate with different servers using different protocols, which is quite sockPHP
libcurl allows you to connect and communicate with different servers using different protocols
        # yum install libxml2 libxml2-devel bzip2-devel libcurl-devel

5. RPM package related to graphics
Usually corresponding error message: JIS-mapped Japanese font support in GD
        # yum install libjpeg-devel libpng-devel freetype-devel
Second, compile and install php-5.6.9
First download the source code package to a 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
# cd php /

# ./configure --prefix = / usr / local / php \
        --with-mysql = / usr / local / mysql \
        --with-openssl \
        --enable-fpm \
        --enable-sockets \
        --enable-sysvshm \
        --enable-ftp \
        --with-mysqli = / usr / local / mysql / bin / mysql_config \
        --enable-mbstring \
        --with-freetype-dir \
        --with-jpeg-dir \
        --with-png-dir \
        --with-zlib-dir \
        --with-libxml-dir = / usr \
        --enable-xml \
        --with-mhash \
        --with-mcrypt \
        --with-config-file-path = / etc / php / php.ini \
        --with-config-file-scan-dir = / etc / php / php.d \
        --with-bz2 \
        --with-curl \
        --with-pear \
        --with-gd

# make && make install
### The following is the prompt message after the installation is completed
        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 /

### Create php configuration directory
        # mkdir -pv /etc/php/php.d

### php configuration
        php.ini is the core configuration file for PHP running
        php-fpm.conf is the configuration file for the php-fpm process service

# cp /usr/local/php/php.ini-production /etc/php/php.ini

# cp /usr/local/php/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod 755 /etc/init.d/php-fpm

# cp /usr/local/php/etc/php-fpm.conf.default / usr / local / php / etc / php-fpm.
conf

### 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
Three, configure apache to access PHP
### Open the following module
# vim /etc/httpd24/httpd.conf ### Note here, I am here to compile and install the httpd2.4 version separately, 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 ### Turn off the forward proxy and turn on the downstream reverse proxy
        ProxyPassMatch ^ / (. * \. Php) $ fcgi: //127.0.0.1: 9000 / usr / local / apache / htdocs / $ 1

# service httpd24 restart
        Stopping httpd24: [OK]
        Starting httpd24: [OK]
Fourth, verify PHP
### Write a php page test
# 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
Compile and install PHP 5.6 under Linux 6

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.