CentOS7编译安装php-7.4.16

2022-10-11 22:08:16 133 0
魁首哥

一、环境说明

1.系统为CentOS 7.6 x64最小化安装,部署前已完成系统初始化、内核及安全优化。

CentOS7编译安装php-7.4.16

2.oniguruma5php依赖包:开启mbstring扩展,需要的正则处理库。

二、基础依赖文件

1.编译工具—— 若系统初始化时没有安装则执行

## autoconf

cd /data/tools

wget

tar xf autoconf-2.71.tar.gz

cd autoconf-2.71

./configure

make

make install

## automake

cd /data/tools

wget

tar xf automake-1.16.3.tar.gz

cd automake-1.16.3

./configure

make

make install

## libtool

cd /data/tools

wget

tar xf libtool-2.4.6.tar.gz

cd libtool-2.4.6

./configure

make

make install

2.安装依赖

## 基础依赖

rpm -ivh

yum -y install bzip2 bzip2-devel curl curl-devel fontconfig fontconfig-devel freetype freetype-devel gd gd-devel gmp gmp-devel icu libicu libicu-devel libxslt libxslt-devel libmcrypt libmcrypt-devel libevent libjpeg libjpeg-devel libpng libpng-devel libvpx libvpx-devel libXpm libXpm-devel libxml2 libxml2-devel openssl openssl-devel pcre pcre-devel perl readline readline-devel sqlite-devel zlib zlib-devel

## oniguruma5php依赖

yum -y install

yum -y install

## 升级libzip( )

YUM安装的libzip版本为0.10,达不到要求,需升级,卸载掉yum安装的libzip然后手动安装新版。另1.5.0版本后的libzip需要用 cmake 编译。

yum -y remove libzip libzip-devel

cd /data/tools

wget

tar xf libzip-1.2.0.tar.gz

cd libzip-1.2.0

./configure

make && make install

export PKG_CONFIG_PATH=”/usr/local/lib/pkgconfig/”

ldconfig /usr/local/lib

三、PHP安装及配置

1.添加组及用户

groupadd -g 1000 www

useradd -s /bin/bash -u 1000 -g www www

2.安装PHP

cd /data/tools/

wget

tar xf php-7.4.16.tar.gz

cd php-7.4.16

./configure –prefix=/usr/local/php-7.4.16 –with-config-file-path=/etc –enable-fpm –with-fpm-user=www –with-fpm-group=www –enable-inline-optimization –disable-debug –disable-rpath –enable-bcmath –enable-shared –enable-soap –enable-session –enable-shmop –enable-simplexml –enable-sockets –enable-sysvmsg –enable-sysvsem –enable-sysvshm –enable-json –enable-mbstring –enable-mbregex –enable-pdo –enable-calendar –enable-dom –enable-exif –enable-fileinfo –enable-filter –enable-ftp –enable-gd –enable-gd-jis-conv –with-curl –with-cdb -with-jpeg –with-freetype –with-gettext –with-gmp –with-xmlrpc –with-openssl –with-mhash –with-sqlite3 –with-iconv –with-bz2 –with-zlib –with-zip –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-pdo-sqlite –with-readline –with-libxml –with-xsl –enable-mysqlnd-compression-support –with-pear –enable-opcache –enable-pcntl –without-gdbm –enable-fast-install

make ZEND_EXTRA_LIBS=’-liconv’

make install

cd /usr/local/

ln -sf php-7.4.16 php

3.设置全局的php命令 (可选操作)

vi /etc/profile //在文件最后添加如下内容

 ######PHP
PATH=$PATH:/usr/local/php/bin  

source /etc/profile

## 查看PHP版本

php -v

4.参数配置

vi /usr/local/php/etc/ php-fpm .conf //输入以下内容

 [global]
pid = /usr/local/php/ var /run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice

[www]
listen = 127.0.0.1:9000
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 200
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 50
request_terminate_timeout = 50
request_slowlog_timeout = 15
slowlog = var/log/slow.log  

备注:配置文件中所有参数的设置可根据实际环境需求进行修改,此处配置仅供参考。

5.配置启动管理脚本

vi /usr/lib/systemd/system/php-fpm. service //输入以下内容

 [Unit]
Description=The PHP FastCGI Process Manager 
Documentation=
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFILE=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm -y /usr/local/php/etc/php-fpm.conf -c /etc/php.ini
ExecRestart=/bin/kill -USR2 $PIDFILE
ExecReload=/bin/kill -USR2 $PIDFILE
ExecStop=/bin/kill -s QUIT $PIDFILE
PrivateTmp=true

[Install]
WantedBy=multi-user.target  

## 脚本中的 “-c /etc/php.ini” 参数是为了解决某些第三方扩展已安装无法加载的问题,即在phpinfo页面中查看不到的情况。

chmod a+x /usr/lib/systemd/system/php-fpm.service

systemctl daemon-reload

6.配置php. ini文件

cd /data/tools/php-7.4.16

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

sed -i ‘s/post_max_size = 8M/post_max_size = 20M/g’ /etc/php.ini

sed -i ‘s/upload_max_filesize = 2M/upload_max_filesize = 20M/g’ /etc/php.ini

sed -i ‘s/;date.timezone =/date.timezone = Asia\/Shanghai/g’ /etc/php.ini

sed -i ‘s/short_open_tag = Off/short_open_tag = On/g’ /etc/php.ini

sed -i ‘s/max_execution_time = 30/max_execution_time = 300/g’ /etc/php.ini

sed -i ‘s/disable_functions =.*/disable_functions = passthru,exec,system,chroot,scandir,chgrp, chown ,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g’ /etc/php.ini

## 注:

上述参数可根据实际情况进行修改,此处仅供参考。

②session.cookie_path 和 session.save_path 值可自定义,注意目录权限。

四、服务管理

启动:systemctl start php-fpm.service

关闭:systemctl stop php-fpm.service

重启:systemctl restart php-fpm.service

查看状态:systemctl status php-fpm.service

开机启动:systemctl enable php-fpm.service

关闭开机启动:systemctl disable php-fpm.service

收藏
分享
海报
0 条评论
133
上一篇:Plesk轻松搭建PHP开发环境 下一篇:ubuntu16安装php7.2实践

本站已关闭游客评论,请登录或者注册后再评论吧~

忘记密码?

图形验证码