Install and configure PHP 7.1.12 in CentOS 7

Source: Internet
Author: User
Tags mcrypt

Install and configure PHP 7.1.12 in CentOS 7

Linux: CentOS 7

Record the installation and configuration process of PHP 7.1.12 in CentOS 7.

Install the dependent package first

Yum install

Pcre-devel zlib-devel openssl-devel gd-devel libjpeg-devel libpng-devel freetype-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel lua-devel
Autoconf libxml2 libxml2-devel glibc-devel glib2 glib2-devel kernel bzip2-devel ncurses-devel curl-devel libidn-devel libtool-libs kernel-devel kernel openldap-clients -servers libtool-ltdl-devel bison libgcrypt php-mcrypt libmcrypt-devel cmake gcc-c ++ ncurses-devel perl-Data-Dumper libicu-devliblibquadmath-devel python-devel bzip2-devel

I will not differentiate them either. These are the dependent packages that need to be installed to build the lnpm environment, and they will all be installed.

Download php, I go to the official website to download the http://www.php.net/downloads.php

Download the latest stable tar.gz format

Then, use the xftp tool to remotely connect to linux and place the downloaded package to the/usr/local/directory of linux.

1. decompress:

[Root @ localhost

[Root @ localhost] # tar-zxvf php-7.1.12.tar.gz

2 Compilation:

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mcrypt=/usr/include --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --with-png-dir --with-libxml-dir --with-mcrypt --with-mhash

Errors are reported during compilation. Check whether the errors are resolved. If some errors are reported, check whether all the dependent packages have been installed. If you have not installed mysql, install mysql first.

Php compilation error: configure: error: mcrypt. h not found. Please reinstall libmcrypt.

Yum install-y epel-release
Yum install-y libmcrypt-devel
The two cannot be installed together. Because the default yum source of CentOs6 does not have the libmcrypt-devel package, you can only use the yum source of epel. Therefore, install epel first and then install
Libmcrypt

After all the compilation is complete, execute:

Make & make install

3. Configure startup:

After the make installation is complete, the directory/usr/local/php will appear;

Execute the following sentence

[Root @ localhost local] # ll/usr/local/php/etc/

You can see the configuration file under the directory. Generally, I transfer the configuration file to the Home Directory of other non-root users.

For example, if I create a adv user and create a directory under the adv user to save the php configuration file;

[Root @ localhost home] # cd/home/adv/

[Root @ localhost adv] # mkdir phpfpm

[Root @ localhost adv] # cd phpfpm/

[Root @ localhost phpfpm] # mkdir conf

Now we have the directory/home/adv/phpfpm/conf.

Next, cp the configuration file to the/home/adv/phpfpm/conf directory.

1. First, cp the php. ini file to the/home/adv/phpfpm/conf directory.

The php. ini file is in the php-7.1.12 file you just decompressed.

[Root @ localhost/] # cp/usr/local/php-7.1.12/php. ini-production/home/adv/phpfpm/conf/php. ini

[Root @ localhost/] # cp/usr/local/php/etc/php-fpm.conf.default/home/adv/phpfpm/conf/php-fpm.conf

P/usr/local/php/etc/php-fpm.d/www. conf. default/home/adv/phpfpm/conf/backend. conf

Now we can see that there are three files in the/home/adv/phpfpm/conf/directory.

2. modify the configuration file:

Modify php-fpm.conf files

[Root @ localhost/] # vim php-fpm.conf.

 

 

You can modify other configurations as needed.

3. Edit the startup php file. Because we transfer the configuration file to the adv user, you need to specify the configuration file to start php

Startup Script: [root @ localhost phpfpm] # vim/home/adv/phpfpm. sh

#!/bin/bashCURRDIR=`dirname "$0"`BASEDIR=`cd "$CURRDIR"; pwd`NAME="php-fpm"CMD=/usr/local/php/sbin/php-fpmif [ "$1" = "-d" ]; then    shift    EXECUTEDIR=$1'/'    shiftelse    EXECUTEDIR=$BASEDIR'/'fiif [ ! -d "$EXECUTEDIR" ]; then    echo "ERROR: $EXECUTEDIR is not a dir"    exitfiif [ ! -d "$EXECUTEDIR"/conf ]; then    echo "ERROR: could not find $EXECUTEDIR/conf/"    exitfiif [ ! -d "$EXECUTEDIR"/logs ]; then    mkdir "$EXECUTEDIR"/logsficd "$EXECUTEDIR"PID_FILE="$EXECUTEDIR"/logs/php-fpm.pidcheck_pid() {    RETVAL=1    if [ -f $PID_FILE ]; then        PID=`cat $PID_FILE`        ls /proc/$PID &> /dev/null        if [ $? -eq 0 ]; then            RETVAL=0        fi    fi}check_running() {    PID=0    RETVAL=0    check_pid    if [ $RETVAL -eq 0 ]; then        echo "$CMD is running as $PID, we'll do nothing"        exit    fi}start() {    check_running    "$CMD" -y "$EXECUTEDIR/conf/php-fpm.conf" -c "$EXECUTEDIR/conf/php.ini" -p `pwd`}stop() {    kill -SIGQUIT `cat $PID_FILE`}status() {    check_pid    if [ $RETVAL -eq 0 ]; then        echo "php-fpm is running as $PID ..."    else        echo "php-fpm is not running"    fi}reload() {    check_pid    if [ $RETVAL -eq 0 ]; then        kill -SIGUSR2 `cat $PID_FILE`    else        echo "php-fpm is not running"    fi}reopen() {    check_pid    if [ $RETVAL -eq 0 ]; then        kill -SIGUSR1 `cat $PID_FILE`    else        echo "php-fpm is not running"    fi}RETVAL=0case "$1" in    start)        start        ;;    stop)        stop        ;;    restart)        stop        start        ;;    status)        status        ;;    reload)        reload        ;;    reopen)        reopen        ;;    *)    echo "Usage: $0 {start|stop|restart|status|reload|reopen}"    RETVAL=1esacexit $RETVAL 

After writing, you can use it to start the test.

[Root @ localhost phpfpm] # bash phpfpm. sh
Usage: phpfpm. sh {start | stop | restart | status | reload | reopen}
[Root @ localhost phpfpm] #

You can see that phpfpm. sh {start | stop | restart | status | reload | reopen} can be executed at startup.

Start:

[Root @ localhost phpfpm] # bash phpfpm. sh start

Run the following command to check whether the startup is successful and whether a process exists.

Root @ localhost phpfpm] # ps-ef | grep php

The red box indicates that the startup is successful;

Since the configuration is put under the adv user, we recommend that you use the adv user to start it;

Install PHP in Red Hat Enterprise Linux 7.3

Detailed php hd scanning PDF + CD source code + full set of teaching videos

Install PHP7.0 in CentOS 7.3

Compile and install PHP7.0.10 + MySQL5.7.14 + Nginx1.10.1 in CentOS 7.2

Install PHP5 and PHP7 in Linux

How to install the PHP extension module in Linux

Use MySQL 5.7 + PHP 7 + Apache to deploy Nextcloud in CentOS 7

Install the LEMP environment on Ubuntu 17.10 (Nginx, MariaDB, PHP7.1)

PHP details: click here
PHP: click here

Related Article

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.