下载php8.2.3
cd /usr/localwget https://www.php.net/distributions/php-8.2.3.tar.gz
解压
tar -zxvf php-8.2..tar.gz
安装必要依赖
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel
yum -y install gcc gcc-c++ libxslt-devel* mod_ssl libtool-ltdl* sqlite-devel oniguruma-devel perl* libzip autoconf
进入解压的目录
cd /usr/local/php-8.2./
配置(此步骤可能遇到模块未安装问题,需要逐个安装)
./configure --prefix=/usr/local/php8 --with-curl --with-freetype --enable-gd --with-gettext --with-kerberos --with-libdir=lib64 --with-mysqli --with-openssl --with-external-pcre --with-jpeg --with-pdo-mysql --with-pear --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --with-zip --enable-pcntl --enable-ftp --enable-session --enable-xml --without-pear --disable-phar
编译
make
安装
make install
添加环境变量
vim /etc/profile
在最后一行下面加入
PATH=$PATH:/usr/local/php8/bin
export PATH
立即生效
source /etc/profile
查看PHP版本
php -v
生成必要文件
cp /usr/local/php-8.2./php.ini-production /usr/local/php8/etc/php.ini
cp /usr/local/php-8.2./sapi/fpm/php-fpm /usr/local/php8/etc/php-fpm
cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf
编辑php.ini
vim /usr/local/php8/etc/php.ini
以下参数仅供参考
date.timezone = PRC //设置时区
file_uploads = On //是否允许上传
upload_tmp_dir = /tmp //上传临时目录
max_file_uploads = //单个请求最多上传数量
upload_max_filesize = 10M //允许上传文件大小
post_max_size = 20M //允许post传输最大值(这个必须比upload_max_filezise大)
memory_limit = 128M //设置脚本最大使用内存
error_reporting=E_ALL //输出错误信息
error_log = /var/log/php.log //错误日志路径
创建日志文件
touch /var/log/php.log
chmod /var/log/php.log
启动php-fpm,载入php.ini
/usr/local/php8/sbin/php-fpm -c /usr/local/php8/etc/php.ini
如果修改了php.ini则每次需要杀掉php-fpm进程再重新启动php-fpm
ps -ef | grep php-fpm
kill - 上一条命令查到的PID