Centos 7 compile and install php-7.2.11 steps
Download the php compressed package of php-7.2.11 on the official website. The steps for installing php-7.2.11 on centos 7 are http://cn2.php.net/distributions/php-7.2.11.tar.gz
cd /usr/local/srcwget -c http://cn2.php.net/distributions/php-7.2.11.tar.gz
After downloading, decompress the php-7.2.11.tar.gz compressed package and enter the decompressed directory
tar -xzvf php-7.2.11.tar.gzcd php-7.2.11
Install some dependent library packages libxml2 and some other dependent extension libraries required by php7
yum -y install libxml2 yum -y install libxml2-devel yum -y install openssl yum -y install openssl-devel yum -y install curl-devel yum -y install libjpeg-devel yum -y install libpng-devel yum -y install freetype-develyum -y install bzip2-develyum -y install libmcrypt libmcrypt-develyum -y install postgresql-develyum -y install aspell-develyum -y install readline-develyum -y install libxslt-develyum -y install net-snmp-develyum -y install unixODBC-develyum -y install libicu-develyum -y install libc-client-develyum -y install libXpm-develyum -y install libvpx-develyum -y install enchant-develyum -y install openldapyum -y install openldap-develyum -y install db4-develyum -y install gmp-develyum -y install sqlite-develyum -y install mysql-devel
yum install oniguruma-devel -y
Check the environment configuration before installation, check some dependency packages of php7, and start up php extensions. If there is no library package that php depends on in this process, there will be an error message.
Add users and groups: (Here the users and groups are nginx, my username used by nginx) groupadd -r nginx && useradd -r -g nginx -s /sbin/nologin
php installation configuration
Please select the appropriate one according to the following A BC for installation and configuration
A. PHP 7.2.10 Single Selection Mode
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-xmlrpc --with-openssl --with-mcrypt --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache
B. PHP 7.2.10 multi-line mode
./configure \--prefix=/usr/local/php \--with-config-file-path=/usr/local/php/etc \--enable-fpm \ --with-fpm-user=nginx \--with-fpm-group=nginx \ --enable-inline-optimization \--disable-debug \--disable-rpath \--enable-shared \--enable-soap \--with-xmlrpc \--with-openssl \--with-mcrypt \--with-pcre-regex \--with-sqlite3 \--with-zlib \--enable-bcmath \--with-iconv \--with-bz2 \--enable-calendar \--with-curl \--with-cdb \--enable-dom \--enable-exif \--enable-fileinfo \--enable-filter \--with-pcre-dir \--enable-ftp \--with-gd \--with-openssl-dir \--with-jpeg-dir \--with-png-dir \--with-freetype-dir \--enable-gd-native-ttf \--enable-gd-jis-conv \--with-gettext \--with-gmp \--with-mhash \--enable-json \--enable-mbstring \--enable-mbregex \--enable-mbregex-backtrack \--with-libmbfl \--with-onig \--enable-pdo \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \--with-zlib-dir \--with-pdo-sqlite \--with-readline \--enable-session \--enable-shmop \--enable-simplexml \--enable-sockets \--enable-sysvmsg \--enable-sysvsem \--enable-sysvshm \--enable-wddx \--with-libxml-dir \--with-xsl \--enable-zip \--enable-mysqlnd-compression-support \--with-pear \--enable-opcache
C. PHP 7.4.10
./configure \--prefix=/usr/local/php \--with-config-file-path=/usr/local/php/etc \--enable-fpm \--with-fpm-user=nginx \--with-fpm-group=nginx \--enable-inline-optimization \--disable-debug \--disable-rpath \--enable-shared \--enable-soap \--with-xmlrpc \--with-openssl \--with-mcrypt \--with-pcre-regex \--with-sqlite3 \--with-zlib \--enable-bcmath \--with-iconv \--with-kerberos \--with-libdir=lib64 \--with-bz2 \--enable-calendar \--with-curl \--with-cdb \--enable-dom \--enable-exif \--enable-fileinfo \--enable-filter \--with-pcre-dir \--enable-ftp \--enable-gd \--with-openssl-dir \--with-jpeg-dir \--with-png-dir \--with-freetype-dir \--enable-gd-native-ttf \--enable-gd-jis-conv \--with-gettext \--with-gmp \--with-mhash \--enable-json \--enable-mbstring \--enable-mbregex \--enable-mbregex-backtrack \--with-libmbfl \--with-onig \--enable-pdo \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \--with-zlib-dir \--with-pdo-sqlite \--with-readline \--enable-session \--enable-shmop \--enable-simplexml \--enable-sockets \--enable-sysvmsg \--enable-sysvsem \--enable-sysvshm \--enable-wddx \--with-libxml-dir \--with-xsl \--with-zip \--enable-xml \--enable-mysqlnd-compression-support \--with-pear \--enable-opcache \--enable-pcntl
Starting from PHP 7.4.0, you must use the --with-zip configuration option to provide zip support when compiling PHP. In previous versions of PHP, the --enable-zip option was required.
Compile and install php7
make && make install
(If there is an error of make: *** [sapi/cli/php] Error 1, continue to execute the make ZEND_EXTRA_LIBS='-liconv' command to solve
Compilation is successful, check the php version
/usr/local/php/bin/php -v
Run php-fpm
/usr/local/php/sbin/php-fpm
The errors you may encounter when starting php-fpm are basically configuration file configuration and renaming problems:
Error 1: Missing www.conf configuration file (WARNING: Nothing matches the include pattern /usr/local/php/etc/php-fpm.d/*.conf), you need to change /usr/local/php/etc/php- Rename www.conf.default in the fpm.d/*.conf directory to www.conf.
Error 2: The php-fpm.conf configuration file is missing. You need to change the default configuration file php-fpm.conf.default to php-fpm.conf in /usr/local/php/etc/php-fpm.conf
Error 3: Missing php.ini configuration file After php7 is compiled and installed, you will find that there is no php.ini configuration file. You need to copy php.ini-production or php.ini-development in the root directory of the unzipped package and rename it to php.ini. The /usr/local/php/etc folder in the php compiled installation directory is fine.
Other error solutions:
error: Package requirements (sqlite3> 3.7.4) were not metyum install libsqlite3x-devel -yerror: Package requirements (oniguruma) were not met
yum install oniguruma-devel -yWhen yum install prompts "No package available"
yum install -y epel-releaseoff_t undefined error
configure: error: off_t undefined; check your library configuration
configure: WARNING: unrecognized options: --with-mcrypt, --enable-gd-native-ttf
After php7.2 does not support –with-mcrypt, --enable-gd-native-ttf these two parameters, need to be removed
After compiling and installing php in centos7, php will not be started after the system restarts, so it is necessary to add a startup script to centos7 to start the php service.
How to compile and install php7: http://zixuephp.net/article-207.html
Manual start:
-
/usr/local/php/sbin/php-fpm
Start automatically at boot:
Open configuration php-fpm pid
-
#Find the php-fpm.conf configuration file
-
/usr/local/php/etc/php-fpm.conf
-
#Open pid, remove the semicolon comment
-
pid = run/php-fpm.pid
What to do after installation:
1. Copy php.ini-development in the installation directory to the /etc/ directory 2. Modify /usr/local/php/etc/php-fpm.conf.default named php-fpm.conf and enter to modify 3. Modify /usr/local/php/etc/php-fpm.d/www.conf.default to www.conf and enter the modification
PHP 7.4.10 install ZIP
1 Extension package wget https://pecl.php.net/get/zip-1.19.0.tgz 2 Unzip and enter tar -zxvf zip-1.19.0.tgz 2.2 cd zip-1.19.03 /usr/local/php /bin/phpize 4 ./configure --with-php-config=/usr/local/php/bin/php-config own php directory 5 make && make install------------- --------Then download the latest, unzip wget https://libzip.org/download/libzip-1.5.2.tar.gztar -zxvf libzip-1.5.2.tar.gz and find that Install cmake, then download cmake: wget https://github.com/Kitware/CMake/releases/download/v3.15.4/cmake-3.15.4.tar.gz Unzip: tar -zxvf cmake-3.15.4.tar .gz Note: cmake should be installed according to the documentation. /bootstrap && make && sudo make install After a long wait, after the installation is complete, execute cmake -version and the version number appears, which means that the cmake installation is successful. Next, enter cd libzip-1.5.2mkdir build && cd build/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/libzip ..makemake install//Check whether libzip is installed successfully whereis libzip libzip: /usr/local/libzip
Create boot script
How to configure php-fpm as a service in Linux
PHP source file path: /usr/local/src/php-7.2.11/
PHP installation path: /usr/local/php/
1. Configure php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
The php-fpm.pid directory must point to: /usr/local/php/var/run/php-fpm.pid
2. Copy the php-fpm script to the /etc/init.d directory
cp /usr/local/src/php-7.2.11/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#! /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 INFOprefix=/usr/local/phpexec_prefix=${prefix}php_fpm_BIN=${exec_prefix}/sbin/php-fpmphp_fpm_CONF=${prefix}/etc/php-fpm.confphp_fpm_PID=${prefix}/var/run/php-fpm.pidphp_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"wait_for_pid () { try=0 while test $try -lt 35 ; do case "$1" in 'created') if [ -f "$2" ] ; then try='' break fi ;; 'removed') if [ ! -f "$2" ] ; then try='' break fi ;; esac echo -n . try=`expr $try + 1` sleep 1 done}case "$1" in start) echo -n "Starting php-fpm " $php_fpm_BIN --daemonize $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 ;; status) if [ ! -r $php_fpm_PID ] ; then echo "php-fpm is stopped" exit 0 fi PID=`cat $php_fpm_PID` if ps -p $PID | grep -q $PID; then echo "php-fpm (pid $PID) is running..." else echo "php-fpm dead but pid file exists" 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" ;; configtest) $php_fpm_BIN -t ;; *) echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}" exit 1 ;;esac
3. Set permissions and start php-fpm:
chmod 755 /etc/init.d/php-fpm
/etc/init.d/php-fpm start
chkconfig –add php-fpm
Finally, give php-fpm start, stop and restart as a service:
service php-fpm start
service php-fpm stop
service php-fpm reload
PHP-FPM self-starting configuration service:
vim /etc/rc.d/rc.local
View all services started at boot
chkconfig --list
Nginx demo configuration: (Don’t forget to chown www-data:www-data website directory or you don’t have permission)
server { listen 80; server_name { { server_name }}; access_log /data/logs/nginx/{ { server_name }}/access.log; error_log /data/logs/nginx/{ { server_name }}/error.log;location / {index index.php index.html index.htm;root /data/www/wwwroot/{ { server_name }}/;if (!-e $request_filename) {rewrite ^/(.*)$ /index.php;}}location ~ \.php$ {include fastcgi_params;fastcgi_pass unix:/tmp/php-fcgi.sock;fastcgi_index index.php;}}
php-fpm configuration (rename the two files, the other depends on the actual configuration (omitted...))
www.conf.default -> www.conf
php-fpm.conf.default -> php-fpm.conf
start: php- fpm -D
nginx -s reload