1、安装依赖关系环境
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl curl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu libicu-devel libmemcached-devel sqlite sqlite-devel gcc gcc-c++ openldap openldap-devel libdwarf libdwarf-devel libzstd libzstd-devel libtool freetype freetype-devel libpng libpng-devel libjpeg libjpeg-devel libwebp libwebp-devel libpng libpng-devel zlib zlib-devel pcre2 pcre2-devel mcrypt mcrypt-devel libvpx libvpx-devel
2、创建用户和用户组
创建用户和用户组
groupadd www
useradd -g www www
3、官网下载PHP编译命令如下
编译PHP7.1
./configure \
–prefix=/usr/local/php71 \
–with-config-file-path=/usr/local/php71 \
–with-config-file-scan-dir=/usr/local/php71/ini \
–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-webp-dir \
–with-xpm-dir \
–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-ctype \
–enable-intl \
–enable-pcntl \
–enable-opcache
编译PHP7.2
./configure \
–prefix=/usr/local/php72 \
–with-config-file-path=/usr/local/php72 \
–with-config-file-scan-dir=/usr/local/php72/ini \
–enable-fpm \
–enable-inline-optimization \
–disable-debug \
–disable-rpath \
–enable-shared \
–enable-soap \
–with-libxml-dir \
–with-xmlrpc \
–with-openssl \
–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-filter \
–with-pcre-dir \
–enable-ftp \
–with-gd \
–with-webp-dir \
–with-xpm-dir \
–with-openssl-dir \
–with-jpeg-dir \
–with-png-dir \
–with-zlib-dir \
–with-freetype-dir \
–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-ctype \
–enable-intl \
–enable-pcntl \
–enable-opcache
编译安装PHP73
./configure \
–prefix=/usr/local/php73 \
–with-config-file-path=/usr/local/php73 \
–with-config-file-scan-dir=/usr/local/php73/ini \
–enable-fpm \
–enable-inline-optimization \
–disable-debug \
–disable-rpath \
–enable-shared \
–enable-soap \
–with-libxml-dir \
–with-xmlrpc \
–with-openssl \
–with-mhash \
–with-pcre-regex \
–with-sqlite3 \
–enable-fileinfo \
–with-zlib \
–enable-bcmath \
–with-iconv \
–with-bz2 \
–enable-calendar \
–with-curl \
–with-cdb \
–enable-dom \
–enable-exif \
–enable-filter \
–with-pcre-dir \
–enable-ftp \
–with-gd \
–with-webp-dir \
–with-xpm-dir \
–with-openssl-dir \
–with-jpeg-dir \
–with-png-dir \
–with-zlib-dir \
–with-freetype-dir \
–enable-gd-jis-conv \
–with-gettext \
–with-gmp \
–with-mhash \
–enable-json \
–enable-mbstring \
–enable-mbregex \
–enable-mbregex-backtrack \
–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-ctype \
–enable-intl \
–enable-pcntl \
–enable-opcache
编译安装出错:/usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or dire
解决办法:cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
报错error: off_t undefined; check your library configuration
解决办法:
vim /etc/ld.so.conf
#添加如下几行
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
#保存退出
:wq
ldconfig -v # 使之生效
编译安装php74
./configure \
–prefix=/usr/local/php74 \
–with-config-file-path=/usr/local/php74 \
–with-config-file-scan-dir=/usr/local/php74/ini \
–enable-fpm \
–enable-inline-optimization \
–disable-debug \
–disable-rpath \
–enable-shared \
–enable-soap \
–with-xmlrpc \
–with-openssl \
–with-mhash \
–with-pcre-jit \
–with-sqlite3 \
–enable-fileinfo \
–with-zlib \
–enable-bcmath \
–with-iconv \
–with-bz2 \
–enable-calendar \
–with-curl \
–with-cdb \
–enable-dom \
–enable-exif \
–enable-filter \
–enable-ftp \
–enable-gd \
–with-openssl-dir \
–with-jpeg \
–with-zlib-dir \
–with-freetype \
–enable-gd-jis-conv \
–with-gettext \
–with-gmp \
–with-mhash \
–enable-json \
–enable-mbstring \
–enable-mbregex \
–enable-pdo \
–with-mysqli=mysqlnd \
–with-pdo-mysql=mysqlnd \
–with-zlib-dir \
–with-pdo-sqlite \
–with-readline \
–with-webp \
–with-xpm \
–enable-session \
–enable-shmop \
–enable-simplexml \
–enable-sockets \
–enable-sysvmsg \
–enable-sysvsem \
–enable-sysvshm \
–with-libxml \
–with-xsl \
–with-zip \
–enable-mysqlnd-compression-support \
–with-pear \
–enable-ctype \
–enable-intl \
–enable-pcntl \
–enable-opcache
vim /etc/ld.so.conf
#添加如下几行
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
#保存退出
ldconfig -v # 使之生效
make -j16 && make install(16为服务器核心数的二倍,可以快速编译速度)
4、复制PHP参数
cp php.ini-production /usr/local/php72/php.ini
cp /usr/local/php72/etc/php-fpm.conf.default /usr/local/php72/etc/php72-fpm.conf
cp /usr/local/php72/etc/php-fpm.d/www.conf.default /usr/local/php72/etc/php-fpm.d/www72.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php72-fpm
cp /usr/local/php72/sbin/php-fpm /usr/local/php72/sbin/php72-fpm
php72为安装PHP文件夹名称,上面复制所有72替换为对应PHP版本数字
修改/etc/init.d/php72-fpm 把里面所有的php-fpm替换为php72-fpm,此处72为对应安装PHP版本
5、设置开机启动
vi /etc/systemd/system/php72-fpm.service #此处及72以下添加内容均为一样是对应PHP版本
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php72-fpm.pid
ExecStart=/usr/local/php72/sbin/php72-fpm –nodaemonize –fpm-config /usr/local/php72/etc/php72-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
启动:systemctl start php72-fpm
查看:systemctl status php72-fpm
开机启动:systemctl enable php72-fpm
到这里已经全部安装完成
可以选择隐藏PHP版本号
修改 php.ini 文件 设置 expose_php = Off
vim /usr/local/php7/etc/php.ini
找到 expose_php = On
改为 expose_php = Off
评论0