php-7.2.18安装

ThinkPhp 发表时间:2021-11-19 15:12:05 作者:梁子亮 浏览次数:1228

下载好php-7.2.18.tar.gz源码,然后再上传到服务器的root目录下,开始解压

tar -zxvf php-7.2.18.tar.gz

进入php-7.2.18目录

yum install libxml2 libxml2-devel openssl openssl-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libmcrypt libmcrypt-devel -y
./configure 
--prefix=/usr/local/php 
--with-config-file-path=/usr/local/php 
--enable-mbstring 
--enable-ftp 
--with-gd 
--with-jpeg-dir=/usr 
--with-png-dir=/usr 
--with-mysql=mysqlnd 
--with-mysqli=mysqlnd 
--with-pdo-mysql=mysqlnd 
--without-pear 
--disable-phar 
--enable-sockets 
--with-freetype-dir=/usr 
--with-zlib 
--with-libxml-dir=/usr 
--with-xmlrpc 
--enable-zip 
--enable-fpm 
--enable-xml 
--enable-sockets 
--with-gd 
--with-zlib 
--with-iconv 
--enable-zip 
--with-freetype-dir=/usr/lib/ 
--enable-soap 
--enable-pcntl 
--enable-cli 
--with-curl

或者把config-file-path指定到etc下,即

./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-jpeg-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip
make
make install

源码安装完成后,大概显示如下

image.png

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/

Installing PHP CLI binary:        /usr/local/php/bin/

Installing PHP CLI man page:      /usr/local/php/php/man/man1/

Installing PHP FPM binary:        /usr/local/php/sbin/

Installing PHP FPM defconfig:     /usr/local/php/etc/

Installing PHP FPM man page:      /usr/local/php/php/man/man8/

Installing PHP FPM status page:   /usr/local/php/php/php/fpm/

Installing phpdbg binary:         /usr/local/php/bin/

Installing phpdbg man page:       /usr/local/php/php/man/man1/

Installing PHP CGI binary:        /usr/local/php/bin/

Installing PHP CGI man page:      /usr/local/php/php/man/man1/

Installing build environment:     /usr/local/php/lib/php/build/

Installing header files:          /usr/local/php/include/php/

Installing helper programs:       /usr/local/php/bin/

  program: phpize

  program: php-config

Installing man pages:             /usr/local/php/php/man/man1/

  page: phpize.1

  page: php-config.1

Installing PDO headers:           /usr/local/php/include/php/ext/pdo/

开始配置php.ini,使用php --ini查看,可能获得以下结果,也可能除了第一个外都为null

Configuration File (php.ini) Path: /usr/local/php/etc
Loaded Configuration File:         /usr/local/php/etc/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

我们需要把php.ini等配置文件复制到相关的路径,注意是在当前目录,即php-7.2.18目录

cp php.ini-production   /usr/local/php/lib/php.ini

或者我们实际上是复制到这里

cp php.ini-production   /usr/local/php/etc/php.ini

在init.d中添加php-fpm服务命令

cp sapi/fpm/php-fpm /etc/init.d/php-fpm

添加执行权限

chmod +x /etc/init.d/php-fpm

配置php-fpm文件

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

设置环境变量,在最后方加上

vi /etc/profile
export PATH=/usr/local/php/bin:$PATH

刷新更改

source /etc/profile

启动php-fpm

/etc/init.d/php-fpm

我们修改php-fpm的配置文件,把/usr/local/php/etc/php-fpm.conf中的pid注释打开了

pid = run/php-fpm.pid

查看php-fpm master 主进程

ps aux|grep php-fpm

重启php-fpm

kill -USR2 42891

此后,在/usr/local/php/var/run/文件夹下就会多了php-fpm.pid文件,显示进程后,则我们可以使用以下来重启php-fpm了

kill -SIGUSR2 `cat /usr/local/php/var/run/php-fpm.pid`
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`

关闭php-fpm

kill -INT `cat /usr/local/php/var/run/php-fpm.pid`

关闭后需要再启动,则使用以下

etc/init.d/php-fpm