您当前的位置: 首页 > 技术文章 > 编程语言

银河麒麟V10 SP2 x86编译安装 PHP7.4

作者: 时间:2023-04-13阅读数:人阅读

目录

前言

一、PHP是什么?

二、使用步骤

1.下载安装包

2.准备PHP相关依赖包

2.1安装oniguruma-6.9.4

2.2.安装libmcrypt

2.3.安装依赖环境

2.4 开始编译PHP

3.修改配置添加快捷启动

总结



前言

PHP不断发展,他们刚刚发布了最新PHP 7.4更新。 正如我们在过去PHP 7版本中所证明的那样,性能和速度在不断提高。 预加载是最令人激动的新更新之一。 由于简化了常见的代码行,因此可以加快脚本执行速度,并使代码更清洁,更快。

一、PHP是什么?

PHP是www上的重要元素,并且在超过79%的网站中使用。 诸如Facebook,Wikipedia,WordPress等知名网站都在使用PHP。 当查看运行PHP的WordPress网站并比较PHP 5和7时,我们可以看到速度提高了两倍。在使用最新PHP版本的情况下– WordPress驱动的网站获得了最大的收益。

二、使用步骤

1.下载安装包

 wget https://www.php.net/distributions/php-7.4.16.tar.gz

2.准备PHP相关依赖包

2.1安装oniguruma-6.9.4

[root@localhost mysqlpackage]# wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
[root@localhost mysqlpackage]# tar -xvf  oniguruma-6.9.4.tar.gz
[root@localhost mysqlpackage]# cd oniguruma-6.9.4/
[root@localhost mysqlpackage]#./autogen.sh && ./configure --prefix=/usr --libdir=/lib64
[root@localhost mysqlpackage]# make && make install

2.2.安装libmcrypt

[root@localhost mysqlpackage]# wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
#安装libmcrypt
[root@localhost mysqlpackage]# tar xf libmcrypt-2.5.8.tar.gz
[root@localhost mysqlpackage]# cd libmcrypt-2.5.8
[root@localhost mysqlpackage]# ./configure --prefix=/usr/local/libmcrypt
[root@localhost mysqlpackage]# make && make install

2.3.安装依赖环境

[root@localhost mysqlpackage]# yum -y install libtool sqlite-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel

2.4 开始编译PHP

[root@localhost tools]# tar -xvf php-7.4.16.tar.gz
[root@localhost tools]# cd php-7.4.16
#编辑PHP的配置项
./configure --prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx \
--enable-inline-optimization --disable-debug --disable-rpath \
--enable-shared --enable-soap  --with-xmlrpc \
--with-openssl --with-mhash  --with-sqlite3 \
--with-zlib --enable-bcmath --with-iconv --with-bz2 \
--enable-calendar --with-curl --with-cdb --enable-dom \
--enable-exif --enable-fileinfo --enable-filter \
--enable-ftp  --with-openssl-dir --with-zlib-dir \
--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 --enable-session \
--enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg \
--enable-sysvsem --enable-sysvshm --with-xsl  \
--enable-mysqlnd-compression-support --with-pear \
--enable-opcache --disable-fileinfo
#安装
[root@localhost tools]# make -j 3 && make install 

3.修改配置添加快捷启动

#添加环境变量
echo "export PATH=$PATH:/usr/local/php/bin" >> /etc/profile
source /etc/profile
#准备配置文件
cp php.ini-production /usr/local/php/etc/php.ini
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
ln -s /usr/local/php/etc/ /etc/php
#修改 /usr/local/php/etc/php-fpm.conf 运行用户和组改为nginx
chown nginx.nginx /usr/local/php/etc/php-fpm.conf
chown -R nginx.nginx /etc/php
#禁用PHP功能
sed -i "s#disable_functions =#disable_functions =\"passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,wnam,posix_getpwuid, posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname\"#" /etc/php/php.ini 
#支持mysql
sed -i "s#pdo_mysql.default_socket=#pdo_mysql.default_socket=/var/lib/mysql/mysql.sock
#" /etc/php/php.ini
sed -i "s#mysqli.default_socket =#mysqli.default_socket =/var/lib/mysql/mysql.sock
#" /etc/php/php.ini 

#设置开机自启,并启动
cp /opt/tools/php-7.4.16/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
chkconfig php-fpm on
systemctl start php-fpm

总结

 php依赖环境较为复杂,如果在编译过程中出现报错,可以根据提示,安装对应依赖即可

本站所有文章、数据、图片均来自互联网,一切版权均归源网站或源作者所有。

如果侵犯了你的权益请来信告知我们删除。邮箱:licqi@yunshuaiweb.com

加载中~