CentOS 7安装php7.4

三分藏道 2024-06-21 10:07:16 阅读 99

1、yum安装

#安装依赖yum install epel-release#启用PHP 7.4 Remi存储库并在CentOS 7上安装PHP 7.4#配置安装源yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpmyum -y install yum-utils#设置安装版本yum-config-manager --enable remi-php74#安装php及拓展包yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis#查看php版本php -v#启动phpsystemctl start php-fpm#php配置文件vi /etc/php.ini#修改php上传限制,默认为2Mupload_max_filesize = 500M

2、编译安装

1、安装依赖包

yum install -y libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel libsqlite3x-devel oniguruma-devel

2、安装编译工具

yum groupinstall 'Development Tools'

3、下载解压

wget http://mirrors.sohu.com/php/php-7.4.9.tar.gz#此处目录为roottar -zxvf php-7.4.9.tar.gzcd php-7.4.9#编译./configure --prefix=/usr/local/php74 --with-config-file-path=/usr/local/php74/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-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --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-sysvshm --enable-xml --enable-zip --enable-fpm#makemake&make install#设置环境变量vi /etc/profile#添加以下内容export PATH=$PATH:/usr/local/php74/binsource /etc/profilecp php.ini-production /usr/local/php74/etc/php.inicd /usr/local/php74/etccp php-fpm.conf.default php-fpm.confcp php-fpm.d/www.conf.default php-fpm.d/www.confln -s /usr/local/php74/sbin/php-fpm /usr/sbin/# 启动 php-fpmphp-fpm# 查看进程ps -ef | grep php-fpmps -aux | grep php-fpm# 查看相关进程数量ps -ef | grep php-fpm | grep -v grep | wc -l# 查看端口netstat -tnl | grep 9000# 将源码目录 sapi/fpm 下的 init.d.php-fpm 复制到 /etc/init.d 目录下并改名为 php-fpmcp /root/php-7.4.9/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm#添加可执行权限chmod u+x /etc/init.d/php-fpm# 添加系统服务chkconfig --add php-fpm# 开启服务chkconfig php-fpm on# 查看是否添加成功chkconfig --list php-fpmvi /usr/lib/systemd/system/php-fpm.service[Unit]Description=php-fpm server daemonAfter=network.target sshd-keygen.target[Service]Type=forkingExecStart=/etc/init.d/php-fpm startExecStop=/etc/init.d/php-fpm stopExecReload=/bin/kill -HUP $MAINPID[Install]WantedBy=multi-user.targetsystemctl daemon-reload

编译遇到以下问题解决办法

#configure: error: Package requirements (libxml-2.0 >= 2.7.6) were not met:#Package ‘libxml-2.0’, required by ‘virtual:world’, not foundyum install libxml2-devel -y#configure: error: Package requirements (krb5-gssapi krb5) were not met:#Package 'krb5-gssapi', required by 'virtual:world', not found#Package 'krb5', required by 'virtual:world', not foundyum install krb5-devel -y#configure: error: Package requirements (openssl >= 1.0.1) were not met:#Package 'openssl', required by 'virtual:world', not foundyum install openssl-devel -y#configure: error: Package requirements (sqlite3 > 3.7.4) were not met:#Package 'sqlite3', required by 'virtual:world', not foundyum install sqlite-devel -y#configure: error: Please reinstall the BZip2 distributionyum -y install bzip2-devel#configure: error: Package requirements (libcurl >= 7.15.5) were not met:#Package 'libcurl', required by 'virtual:world', not foundyum install libcurl-devel -y#configure: error: Package requirements (oniguruma) were not met:#Package 'oniguruma', required by 'virtual:world', not foundyum config-manager --set-enabled PowerToolsyum -y install oniguruma oniguruma-devel#configure: error: Package requirements (libxslt >= 1.1.0) were not met:#Package 'libxslt', required by 'virtual:world', not foundyum install libxslt-devel -y#configure: error: Package requirements (libpng) were not met:#Package 'libpng', required by 'virtual:world', not foundyum install libpng-devel -y#configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:#Package 'libzip', required by 'virtual:world', not found#Package 'libzip', required by 'virtual:world', not found#Package 'libzip', required by 'virtual:world', not foundyum install libzip-devel -y

3、编译安装拓展包

#进入源代码中ext文件夹下需要编译的拓展的文件夹中,比如编译gd,则进入源代码ext文件夹下的gd#编译好后的php安装目录下的phpize,执行后生成configure文件/usr/local/php74/bin/phpize#进行配置./configure --with-php-config=/usr/local/php74/bin/php-config#编译make&make install#make中可能报以下错误#PHP编译安装报错,make:*libtool: link: `ext/libxml/libxml.lo‘ is not a valid libtool object#把 php的源代码目录(你make过的)删掉, 再解压, 然后再 make 应该就 ok 了#编译安装完成后会显示一个目录Installing shared extensions: /usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902/#编辑php.ini,编译的php一般都是在其安装目录下有一个etc文件夹,里面有一个php.ini#此处为/usr/local/php74/etc/php.ini#将/usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902/目录添加到php.ini,大概有一个extension_dir=xxx,在其下面添加一行,把编译好后的路径添加上extension_dir=/usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902/#再找到对应的模块启用#对应模块显示类似为为;extension=gd,去掉前面的分号保存,如果没有则手动添加extension=gd#重新启动php



声明

本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。