前言:
现时大家对“如何编译安装php”可能比较注重,各位老铁们都需要知道一些“如何编译安装php”的相关文章。那么小编在网上收集了一些有关“如何编译安装php””的相关资讯,希望咱们能喜欢,姐妹们快快来了解一下吧!一、环境说明
1.系统为CentOS 7.6 x64最小化安装,部署前已完成系统初始化、内核及安全优化。
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 //在文件最后添加如下内容
######PHPPATH=$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.piderror_log = /usr/local/php/var/log/php-fpm.loglog_level = notice[www]listen = 127.0.0.1:9000listen.backlog = -1listen.allowed_clients = 127.0.0.1listen.owner = wwwlisten.group = wwwlisten.mode = 0666user = wwwgroup = wwwpm = dynamicpm.max_children = 200pm.start_servers = 10pm.min_spare_servers = 10pm.max_spare_servers = 50request_terminate_timeout = 50request_slowlog_timeout = 15slowlog = var/log/slow.log
备注:配置文件中所有参数的设置可根据实际环境需求进行修改,此处配置仅供参考。
5.配置启动管理脚本
vi /usr/lib/systemd/system/php-fpm.service //输入以下内容
[Unit]Description=The PHP FastCGI Process Manager Documentation= remote-fs.target nss-lookup.target[Service]Type=forkingPIDFILE=/usr/local/php/var/run/php-fpm.pidExecStart=/usr/local/php/sbin/php-fpm -y /usr/local/php/etc/php-fpm.conf -c /etc/php.iniExecRestart=/bin/kill -USR2 $PIDFILEExecReload=/bin/kill -USR2 $PIDFILEExecStop=/bin/kill -s QUIT $PIDFILEPrivateTmp=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
标签: #如何编译安装php