Centos7 source code compilation and installation of php 7.2 production

  • 2020-10-23 21:18:28
  • OfStack

Introduction:

The php7 is faster and performs better than any version of the php5 series, so I'd like to give it a try. If you are an upgrade or a new installation, you first need to consider whether php7 is compatible with the application. If the application is based on php5, then you need to consider whether php7 is suitable for your current production environment. Today I will actually run and install it for production.

Install the php dependency package first; otherwise, various errors will be reported during the compilation and installation of php7. After the installation is completed, the next step can be entered.

Install the extension pack and update the system kernel:


$ yum install epel-release -y
$ yum update

Install php dependencies (including Nginx dependencies) :

$ yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel

Create users and groups, and download the php installation package to unzip:


$ cd /tmp
$ groupadd www
$ useradd -g www www
$ wget http://am1.php.net/distributions/php-7.2.1.tar.gz
$ tar xvf php-7.2.1.tar.gz
$ cd php-7.2.1

Set variables and start source compilation:


$ cp -frp /usr/lib64/libldap* /usr/lib/
$ ./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--with-mcrypt \
--with-libmbfl \
--enable-ftp \
--with-gd \
--enable-gd-jis-conv \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--with-pear \
--enable-maintainer-zts \
--with-ldap=shared \
--without-gdbm \

If there is no error reporting, the next step installation is performed. If there is an error during compilation, the dependent package is installed based on the error reporting, this usually does not occur.

Note: this parameter, ES33en-ES34en-ES35en-ES36en, will cause Chinese characters of Zabbix to be confused. It is recommended to cancel.

Start installation:


$ make -j 4 && make install

Configure php.ini file after installation:


$ cp php.ini-development /usr/local/php/etc/php.ini
$ cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
$ cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

Modify php. ini related parameters:


$ vim /usr/local/php/etc/php.ini

expose_php = Off
short_open_tag = ON
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 32M
date.timezone = Asia/Shanghai
mbstring.func_overload=2
extension = "/usr/local/php/lib/php/extensions/no-debug-zts-20160303/ldap.so"

Set OPcache cache:


[opcache]
zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20160303/opcache.so
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1

Set php security function:


$ vim /usr/local/php/etc/php.ini

Default value:


disable_functions =

Is amended as:

disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

Or wildcard:

disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru

Configuration www conf

Uncomment the following and modify optimize its parameters:


listen = /var/run/www/php-cgi.sock
listen.owner = www
listen.group = www
listen.mode = 0660
listen.allowed_clients = 127.0.0.1
pm = dynamic
listen.backlog = -1
pm.max_children = 180
pm.start_servers = 50
pm.min_spare_servers = 50
pm.max_spare_servers = 180
request_terminate_timeout = 120
request_slowlog_timeout = 50
slowlog = var/log/slow.log

Create the ES81en-ES82en. sock directory


$ cd /tmp
$ groupadd www
$ useradd -g www www
$ wget http://am1.php.net/distributions/php-7.2.1.tar.gz
$ tar xvf php-7.2.1.tar.gz
$ cd php-7.2.1
0

Configuration php - fpm. conf

Remove the following comment and fill in the full path:


$ cd /tmp
$ groupadd www
$ useradd -g www www
$ wget http://am1.php.net/distributions/php-7.2.1.tar.gz
$ tar xvf php-7.2.1.tar.gz
$ cd php-7.2.1
1

So far, php7 has been installed.

Note: Disable the php functions. If the program needs these functions, you can undisable them. Beginners recommend that you ignore this step.

Create system system unit file php-fpm startup script:


$ cd /tmp
$ groupadd www
$ useradd -g www www
$ wget http://am1.php.net/distributions/php-7.2.1.tar.gz
$ tar xvf php-7.2.1.tar.gz
$ cd php-7.2.1
2

Add the following variable contents:


[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target

Start THE php-fpm service and join the boot startup:


$ cd /tmp
$ groupadd www
$ useradd -g www www
$ wget http://am1.php.net/distributions/php-7.2.1.tar.gz
$ tar xvf php-7.2.1.tar.gz
$ cd php-7.2.1
4

PHP the entire installation process has been completed. If you failed to install according to this article, I hope you can leave a message to explain the reason of the error, I will assist you to configure for free.

If you have good Suggestions to improve this article, you are very welcome to put forward and improve it. We will study and make progress together from now on.


Related articles: