Home >Backend Development >PHP Tutorial >Compile and install php7.2 on CentOS
This article mainly introduces the compilation and installation of php7.2 on CentOS. It has certain reference value. Now I share it with everyone. Friends in need can refer to it
Introduction:
I have heard for a long time that the speed and performance of php7 are faster than any version of the php5 series. How good is the specific performance? It is recommended to try it first. If you are upgrading or installing a new one, you first need to consider whether there is compatibility between php7 and the program. If the program is developed based on php5, then you need to consider whether php7 is suitable for your current production environment. Today I will do it and install it. in production.
Install the php dependency package first, otherwise various errors will appear during the compilation and installation of php7. After the installation is completed, you can enter the next step.
Install the extension package and update the system kernel:
yum install epel-release -yyum update
Install php dependent components (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 and decompress the php installation package:
cd /tmp groupadd www useradd -g www wwwwget http://am1.php.net/distributions/php-7.2.1.tar.gztar xvf php-7.2.1.tar.gz cd php-7.2.1
Set variables and start source code 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 no error is reported, execute One-step installation. If an error occurs during the compilation process, install the dependent package according to the error report. This problem usually does not occur.
Note: –enable-gd-jis-conv This parameter will cause Zabbix Chinese characters to be garbled. It is recommended to cancel it.
Start the installation:
make -j 4 && make install
Configure the php.ini file after completing the installation:
cp php.ini-development /usr/local/php/etc/php.inicp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confcp /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 = 300max_input_time = 300memory_limit = 128M post_max_size = 32Mdate.timezone = Asia/Shanghai mbstring.func_overload=2extension = "/usr/local/php/lib/php/extensions/no-debug-zts-20170718/ldap.so"#OPcache 缓存 [opcache] zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20170718/opcache.so opcache.memory_consumption=128opcache.interned_strings_buffer=8opcache.max_accelerated_files=4000opcache.revalidate_freq=60opcache.fast_shutdown=1opcache.enable_cli=1#设置php安全函数 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 #配置www.conf listen = /var/run/www/php-cgi.sock listen.owner = www listen.group = www listen.mode = 0660listen.allowed_clients = 127.0.0.1pm = dynamic listen.backlog = -1pm.max_children = 180pm.start_servers = 50pm.min_spare_servers = 50pm.max_spare_servers = 180request_terminate_timeout = 120request_slowlog_timeout = 50slowlog = var/log/slow.log
Configure www.conf
listen = /var/run/www/php-cgi.sock listen.owner = www listen.group = www listen.mode = 0660listen.allowed_clients = 127.0.0.1pm = dynamic listen.backlog = -1pm.max_children = 180pm.start_servers = 50pm.min_spare_servers = 50pm.max_spare_servers = 180request_terminate_timeout = 120request_slowlog_timeout = 50slowlog = var/log/slow.log
Create php-cgi.sock storage directory
mkdir /var/run/www/chown -R www:www /var/run/www
Configure php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
取下以下注释并填写完整路径:
pid = /usr/local/php/var/run/php-fpm.pid
至此php7已经安装完成。
说明:禁用php函数,如果程序需要这些函数,可以取消禁止,新手建议忽略此步骤。
创建system系统单元文件php-fpm启动脚本:
vim /usr/lib/systemd/system/php-fpm.service
添加如下变量内容:
[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
启动php-fpm服务并加入开机自启动:
systemctl enable php-fpm.service systemctl restart php-fpm.service
The above is the detailed content of Compile and install php7.2 on CentOS. For more information, please follow other related articles on the PHP Chinese website!