SoFunction
Updated on 2025-04-07

Detailed explanation of the tutorial on compiling and installing php7.1 in CentOS7

1. Install the dependency package first:

yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel

2. Download the PHP compressed package and decompress:

wget /distributions/php-7.1.
tar -zxvf php-7.1.
cd php-7.1.0

3. Compile and install. Various errors may occur during compilation. The next article mainly writes the compilation and is a common error and solution:

./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--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-zlib-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

4. Install after successful compilation:

make && make install

5. Configure environment variables after successful installation:

For convenience, you can add php environment variables at the end of /etc/profile file:

PATH=$PATH:/usr/local/php/bin 
export PATH

Refresh environment variables after saving:

source /etc/profile# Update

View environment variables:

echo $PATH

After seeing the path of the php environment variable, you can use the php command directly in the future to view the php version:

php -v

6. Now PHP does not have .ini files and configuration files, and you also need to configure PHP-FPM:

cp -production /etc/
cp /usr/local/php/etc/ /usr/local/php/etc/
cp /usr/local/php/etc// /usr/local/php/etc//
cp sapi/fpm/-fpm /etc//php-fpm
chmod +x /etc//php-fpm

Start, stop and restart of php-fpm:

service php-fpm start#start upservice php-fpm stop #stopservice php-fpm restart #Restart

Summarize

The above is a detailed explanation of the tutorial on compiling and installing php7.1 by CentOS7 introduced to you. I hope it will be helpful to you. If you have any questions, please leave a message. The editor will reply to you in time!