php 8.0源码安装
标签搜索
侧边栏壁纸
  • 累计撰写 5 篇文章
  • 累计收到 0 条评论

php 8.0源码安装

鸿宇
2022-09-27 / 0 评论 / 406 阅读 / 正在检测是否收录...

1.下载php的tar包并解压

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

2.安装依赖包

yum install -y systemd-devel libxml2-devel libcurl-devel libpng-devel sqlite-devel

wget https://github.com/kkos/oniguruma/releases/download/v6.9.8/onig-6.9.8.tar.gz
tar -zxvf onig-6.9.8.tar.gz
cd onig-6.9.8/
./configure --prefix=/usr
make &&make install

3.指定配置信息

在执行编译之前,需要配置安装后的文件存放位置以及安装的一些组件
cd php-8.1.10/
./configure --prefix=/usr/local/php8 --with-config-file-path=/usr/local/php8/etc --with-fpm-user=nginx --with-fpm-group=nginx --with-zlib-dir --with-curl --with-mysqli --with-pdo-mysql --enable-mysqlnd --enable-sockets --enable-fpm --without-sqlite3 --enable-mbstring --enable-mysqlnd --enable-pcntl --disable-rpath --disable-fileinfo

如果之前编译(make)失败,记得用make clean 或者 make distclean 清除之前编译的缓存文件,然后再重新make && make install

配置编译参数成功

+--------------------------------------------------------------------+

| License:                                                           |

| This software is subject to the PHP License, available in this     |

| distribution in the file LICENSE. By continuing this installation  |

| process, you are bound by the terms of this license agreement.     |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point.                            |

+--------------------------------------------------------------------+

Thank you for using PHP.

编译源码
make

make -j2 # 这里是依赖系统cpu核心数进行编译,对性能有一定提升,通常利用核心数不要超过一半

编译错误

error while loading shared libraries: libzip.so.5: cannot open shared object file: No such file or directory

未找到libzip安装目录,先查找 libzip.so.5的路径

find / -name libzip.so.5
/usr/local/lib64/libzip.so.5

将libzip的lib目录添加到环境变量中
vim ~/.bashrc
添加export LD_LIBRARY_PATH=/usr/local/lib64
source ~/.bashrc
再执行就没问题了

安装
make install

4.查看php安装情况

cd /usr/local/php8/bin/
./php -v
PHP 8.1.10 (cli) (built: Sep 23 2022 16:19:03) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies

5. 配置php

5.1 添加环境变量

vim /etc/profile
在文件末尾加入
export PATH=$PATH:/usr/local/php8/bin/
source /etc/profile

php -v
PHP 8.1.10 (cli) (built: Sep 23 2022 16:19:03) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies

5.2 获取默认配置

// 复制php.ini到编译配置参数指定的目录。php.ini在解压的源码目录里

cp /opt/php-8.1.10/php.ini-production /usr/local/php8/etc/php.ini

// 复制一份php-fpm的配置模版文件到同级目录 方便备份和修改

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

// 复制一份php-fpm的扩展配置模板文件到同级目录 方便备份和修改

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

// 复制开启自起脚本到系统启动自动加载脚本目录。fpm/init.d.php-fpm在解压的源码目录里

cp /opt/php-8.1.10/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

5.3 设置开机自启动

添加可执行权限

chmod +x /etc/init.d/php-fpm

检验自启动脚本

service php-fpm start # 检验服务启动

service php-fpm stop # 检验服务关闭

chkconfig php-fpm on # 设置开机自动执行php-fpm脚本

6.通过sock连接php

通常我们配置nginx默认连接php-fpm的方式,是监听127.0.0.1:9000端口,然而还有一种更高效的连接方式,用sock的方式连接。配置如下:
1、创建sock文件
touch /dev/shm/php-fpm.sock

2、更改php配置文件
更改php-fpm配置文件, 将listen指令的值改为sock文件路径,并改启动权限

vim /usr/local/php8/etc/php-fpm.d/www.conf
listen = /dev/shm/php-fpm.sock
listen.owner = nginx #去掉前面的;
listen.group = nginx
listen.mode = 0660

3、更改nginx配置

vim /usr/local/nginx/conf/nginx.conf
location ~ \.php$ {
            #fastcgi_pass   127.0.0.1:9000;
            fastcgi_pass   unix:/dev/shm/php-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

4、重启nginx,php生效

0

评论

博主关闭了所有页面的评论