广告位

阿里云服务器降级PHP8.0环境详细安装教程

频道: 日期: 浏览:0

阿里云关闭服务器

一、PHP环境安装流程

说明:最近在搭建个人网站,环境有用到PHP,特此记录。本文安装案例是以PHP8.0.0版本为示例,「开始安装前建议先将第三步骤抛出异常的依赖安装,这样安装的时候就无需逐个解决问题。」

1、下载PHP包(在线或者压缩包方式都可)

建议:提前创建好压缩包地址,方便后续对文件管理,下载地址:https://www.php.net/downloads.php

在线下载(如果网速很慢,则离线下载上传到服务器):wget https://www.php.net/distributions/php-8.0.0.tar.gz

离线下载后可通过rz命令上传到服务器:rz -be 文件名

2、解压压缩包

执行代码:tar -xvf php-8.0.0.tar.gz

3、指定配置信息

说明:在执行编译之前,需要配置此次编译和安装后的文件的存放位置以及安装的一些组件,「在安装前务必要清楚,如果不了解,建议直接使用本文的代码,防止出现异常问题。」

了解概念:

1、源码安装需要经历步骤:配置(configure)、编译(make)、安装( make install )。

2、Configure则是一个可执行文件,可以配置很多选项(可以理解为我们在Windows安装时的图像化界面的功能),可以通过./configure --help来查看选项具体含义。

其中--prefix选项作用是配置源码安装的路径,--with-config-file-path选项作用是设置php配置文件(php.ini)的存放位置,一般来说安装的时候只需要指定这两个路径即可,其他的则是指定php支持哪一些组件了。

3、延伸说明下指定存放路径的好处,其实可以类比在Windows等图形化系统的安装软件步骤,安装时指定软件的位置,方便后续对软件进行统一管理(删除,查找等)。

4、注意:下面的代码必须处于同一行上,建议先复制到文本上查看是否在同一行,然后再复制到服务器中执行(否则会出现很多莫名其妙的问题,相信你也不想花上几天时间去处理)。

至于其他参数选项的含义,可以打官方或者使用./configure --help来查看选项具体含义,建议添加自己需要的组件即可,如果不清楚,进入到解压的文件后直接执行下面的代码。

./configure --prefix=/usr/local/install/php8 --with-config-file-path=/usr/local/install/php8/etc --with-curl --with-freetype --enable-gd --with-jpeg --with-gettext --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --enable-sockets --with-mhash --with-ldap-sasl --with-xsl --with-zlib --with-zip -with-bz2 --with-iconv --enable-fpm --enable-pdo --enable-bcmath --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-sysvsem --enable-cli --enable-opcache --enable-intl --enable-calendar --enable-static --enable-mysqlnd

5、配置成功后会出现下面提示:

4、编译中可能出现的异常和解决方案

说明,新服务器在执行configure脚本设置配置之前,需要存在的相关依赖脚本整合,下面会对每一个异常问题做具体说明:

yuminstall dnfdnfinstall libxml2-develdnfinstall sqlite-develdnf-y install bzip2-develdnf-y install libcurl-develdnf-y install libpng-develdnf-y install libjpeg-develdnf-y install freetype-develdnf-y install libicu-develyuminstall oniguruma-devel -ydnf-y install libxslt-develdnf-y install libzip-devel

1、异常信息:

configure: error:Packagerequirements(libxml-2.0>=2.9.0)were not met:Nopackagelibxml-2.0found

解决方案:dnf install libxml2-devel

2、异常信息:

-bash:dnf: command not found

解决方案:yum install dnf

3、异常信息:

configure: error:Packagerequirements(sqlite3>3.7.4)were not met:Nopackagesqlite3found

解决方案:dnf install sqlite-devel

4、异常信息:

checkingforBZip2indefaultpath...notfound configure:error: Please reinstall the BZip2 distribution

解决方案:dnf -y install bzip2-devel

5、异常信息:

configure: error:Packagerequirements(libcurl>=7.29.0)were not met:Nopackagelibcurlfound

解决方案:dnf -y install libcurl-devel

云计算金属服务器

6、异常信息:

configure:error: Package requirements (libpng) were notmet: No packagelibpngfound

解决方案:dnf -y install libpng-devel

7、异常信息:

configure:error: Package requirements (libjpeg) were notmet: Packagelibjpeg, required byvirtual:world, not found

解决方案:dnf -y install libjpeg-devel

8、异常信息:

configure:error: Package requirements (freetype2) were notmet: Packagefreetype2, required byvirtual:world, not found

解决方案:dnf -y install freetype-devel

9、异常信息:

configure: error: Package requirements (icu-uc >=50.1icu-io icu-i18n) werenotmet: Packageicu-uc, requiredbyvirtual:world,notfound Packageicu-io, requiredbyvirtual:world,notfound Packageicu-i18n, requiredbyvirtual:world,notfound

解决方案:dnf -y install libicu-devel

10、异常信息:

configure:error: Package requirements (oniguruma) were notmet: No packageonigurumafound

解决方案:yum install oniguruma-devel -y

华为云服务器学生

11、异常信息:

configure: error:Packagerequirements(libxslt>=1.1.0)were not met:Nopackagelibxsltfound

解决方案:dnf -y install libxslt-devel

12、异常信息:

configure: error:Packagerequirements(libzip>=0.11libzip!=1.3.1libzip!=1.7.0)were not met:Packagelibzip,requiredbyvirtual:world,notfound

解决方案:dnf -y install libzip-devel

13、异常信息:

configure: error:Packagerequirements(libzip>=0.11libzip!=1.3.1libzip!=1.7.0)were not met:Requestedlibzip >= 0.11butversionoflibzipis0.10.1

解决方案:

1、先删除原来的安装:yum remove libzip-devel libzip

2、在线下载对应的版本:wget https://libzip.org/download/libzip-1.3.2.tar.gz --no-check-certificate

4、进入解压后的文件夹,执行配置脚本:./confugure

5、编译并安装:make & make install

6、安装完成后,查询/usr/local/lib目录下是否有pkgconfig目录,有的话执行命令export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"指定PKG_CONFIG_PATH,然后重新执行切换php解压之后的文件夹,执行./configure脚本即可

5、编译和安装

配置完成后,执行make指令对源代码进行编译,执行make install指令对源代码进行安装,也可以同时执行这两个指令,具体如下(注意:编译和安装都是在解压后的php文件夹下执行-即存在configure脚本的目录):

1、编译:make

​ 2、安装:make install

3、出现异常:cc: internal compiler error: Killed (program cc1)

原因:大概率是因为内存不够使用,可以先使用交换分区来解决,编译安装后再删除掉即可。

解决:

sudodd if=/dev/zero of=/swapfile bs=64M count=16sudomkswap /swapfilesudoswapon /swapfile

取消交换分区:

sudoswapoff /swapfilesudorm /swapfile

6、查看php安装情况

切换到configure指定的安装路径的bin目录,执行版本查看:

/usr/local/install/php8/bin/php--version

执行结果:

二、管理各种配置文件

1、生成php.ini配置文件(在php源码压缩包目录下):

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

2、生成www配置文件:

cd/usr/local/install/php8/etc/php-fpm.d/ cp www.conf.default www.conf

3、生成php-fpm配置文件:

cd/usr/local/install/php8/etc/ cp php-fpm.conf.default php-fpm.conf

4、生成php-fpm可执行文件:

-- 创建存放配置文件的目录mkdir /usr/local/install/php8/fpm-- 从源码中复制一份fpm可执行脚本cp /usr/local/php/php-8.0.0/sapi/fpm/init.d.php-fpm /usr/local/install/php8/fpm/php-fpm-- 将php-fpm修改为可执行文件chmod740/usr/local/install/php8/fpm/php-fpm

三、管理php

说明:本文推荐使用php-fpm进行管理php程序,php-fpm(FastCGI Process Manager:FastCGI进程管理器)是一个PHPFastCGI管理器,旨在将FastCGI进程管理整合进PHP包中(来源:百度百科)。

优点:相对Spawn-FCGI,php-fpm在CPU和内存方面的控制都更胜一筹,而且前者很容易崩溃,必须用crontab进行监控,而php-fpm则没有这种烦恼。

1、启动php-fpm:

/usr/local/install/php8/fpm/php-fpmstart

2、查看php-fpm进程是否启动成功

ps aux |grepphp |grep-vgrep

3、查看pfp-fpm占用的端口

ss-lntp | grep php

4、执行php --version出现php command not found异常,解决步骤

// 1、修改配置文件vim /etc/profile//2、添加php环境变量(即configure脚本时指定的安装路径下的bin目录)PATH=$PATH:/usr/local/install/php8/binexportPATH// 刷新配置文件source /etc/profile

5、大功告成

写在最后

「如果觉得文章有帮助,请给博主点赞、收藏、关注。」后续博主会带来更多优质、有质量的文章。

想要学习更多知识,了解更多开源项目,请关注博主,进入技术圈子(「圈子所有资源全免费,但要求加入的小伙伴要有长久兴趣,如果只是一时冲动就不推荐加入,毕竟名额有限」)。

加入技术圈子,除了遇到搭建问题免费指导,还能第一时间收到行业最新咨询和认识各专业大佬!

云git服务器

关键词: