PHP environment construction

1. Install the compilation environment

yum -y install gcc automake autoconf libtool make gcc-c++ glibc

 

2. Install dependency packages (install on demand)

yum -y install libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel

 

3. Install PHP

wget -O php-5.6.14.tar.gz http://cn2.php.net/get/php-5.6.14.tar.gz/from/this/mirror

tar zxvf php-5.6.14.tar.gz

cd php-5.6.14

 

./configure --enable-fpm \

--enable-mbstring --disable-pdo --with-curl --disable-debug  --disable-rpath \

--enable-inline-optimization --with-bz2  --with-zlib --enable-sockets \

--enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex \

--enable-zip --with-pcre-regex --with-mysql --with-mysqli \

 

--with-gd --with-jpeg-dir

 

make

 

make install

 

4. Create a dedicated user and group www-data for php

groupadd www-data

 

useradd -g www-data www-data

 

5. Generate and modify the default configuration of php-fpm and make php-fpm run as the www-data user

cd /usr/local/etc/

cp php-fpm.conf.default php-fpm.conf

vi php-fpm.conf

Find and modify to the following line (line 149)

user = www-data

group = www-data

Find and modify the following line (line 164) (in order to support access using any IP, in preparation for subsequent load balancing):

listen = [::]:9000

 

After the above modification is successful, php-fpm can provide services directly

 

6. Register php-fpm as a system service

First, modify the configuration file of php-fpm and set the storage path of the pid file:

vi /usr/local/etc/php-fpm.conf

Find and modify the following (line 25):

pid = /var/run/php-fpm.pid

In /etc/init.d/ we create a service script php-fpm

vi /etc/init.d/php-fpm

 

Write the following:

#! /bin/sh

 

### BEGIN INIT INFO

# Provides:          php-fpm

# Required-Start:    $remote_fs $network

# Required-Stop:     $remote_fs $network

# Default-Start:     2 3 4 5

# Default-Stop:      0 1 6

# Short-Description: starts php-fpm

# Description:       starts the PHP FastCGI Process Manager daemon

### END INIT INFO

 

prefix=/usr

exec_prefix=/usr

 

php_fpm_BIN=/usr/local/sbin/php-fpm

php_fpm_CONF=/usr/local/etc/php-fpm.conf

php_fpm_PID=/var/run/php-fpm.pid

 

 

php_opts="--fpm-config $php_fpm_CONF"

 

 

wait_for_pid () {

        try=0

 

        while test $try -lt 35 ; do

 

                case "$1" in

                        'created')

                        if [ -f "$2" ] ; then

                                try=''

                                break

                        be

                        ;;

 

                        'removed')

                        if [ ! -f "$2" ] ; then

                                try=''

                                break

                        be

                        ;;

                esac

 

                echo -n .

                try=`expr $try + 1`

                sleep 1

 

        done

 

}

 

 

case "$1" in

        start)

                echo -n "Starting php-fpm "

 

                $php_fpm_BIN $php_opts

 

                if [ "$?" != 0 ] ; then

                        echo " failed"

                        exit 1

                fi

 

                wait_for_pid created $php_fpm_PID

 

                if [ -n "$try" ] ; then

                        echo " failed"

                        exit 1

                else

                        echo " done"

                fi

        ;;

 

        stop)

                echo -n "Gracefully shutting down php-fpm "

 

                if [ ! -r $php_fpm_PID ] ; then

                        echo "warning, no pid file found - php-fpm is not running ?"

                        exit 1

                fi

 

                kill -QUIT `cat $php_fpm_PID`

 

                wait_for_pid removed $php_fpm_PID

 

                if [ -n "$try" ] ; then

                        echo " failed. Use force-quit"

                        exit 1

                else

                        echo " done"

                fi

        ;;

 

        force-quit)

                echo -n "Terminating php-fpm "

 

                if [ ! -r $php_fpm_PID ] ; then

                        echo "warning, no pid file found - php-fpm is not running ?"

                        exit 1

                fi

 

                kill -TERM `cat $php_fpm_PID`

 

                wait_for_pid removed $php_fpm_PID

 

                if [ -n "$try" ] ; then

                        echo " failed"

                        exit 1

                else

                        echo " done"

                fi

        ;;

 

        restart)

                $0 stop

                $0 start

        ;;

 

        reload)

 

                echo -n "Reload service php-fpm "

 

                if [ ! -r $php_fpm_PID ] ; then

                        echo "warning, no pid file found - php-fpm is not running ?"

                        exit 1

                fi

 

                kill -USR2 `cat $php_fpm_PID`

 

                echo " done"

        ;;

 

        *)

                echo "Usage: $0 {start|stop|force-quit|restart|reload}"

                exit 1

        ;;

 

 

esac

 

给该脚本赋予执行权限:

chmod +x /etc/init.d/php-fpm

注册为服务并随系统启动:

chkconfig php-fpm on

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326615083&siteId=291194637