Centos7.4编译安装php8.1

时间:2022-03-23作者:klpeng分类:IT综合浏览:1876评论:0

安装依赖包:

yum -y install gcc gcc-c++ glibc automake autoconf libtool make
yum -y install libxslt-devel libjpeg libjpeg-devel libpng libpng-devel 
yum -y install freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel 
yum -y install glibc glibc-devel glib2 bzip2-devel ncurses ncurses-devel 
yum -y install curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel 
yum -y install openssl openssl-devel sqlite-devel libcurl-devel libpng-devel libjpeg-devel 
yum -y install freetype-devel libicu-devel libxslt-devel
yum -y install systemd-devel
yum -y install oniguruma oniguruma-devel
# gmp扩展
yum -y install gmp-devel 

如果安装不了 oniguruma,请使用:

# 方案一:
yum -y install http://mirror.centos.org/centos-7/7.7.1908/cloud/x86_64/openstack-queens/oniguruma-6.7.0-1.el7.x86_64.rpm
yum -y install http://mirror.centos.org/centos-7/7.7.1908/cloud/x86_64/openstack-queens/oniguruma-devel-6.7.0-1.el7.x86_64.rpm

#方案二:
yum -y install http://down.24kplus.com/linux/oniguruma/oniguruma-6.7.0-1.el7.x86_64.rpm
yum -y install http://down.24kplus.com/linux/oniguruma/oniguruma-devel-6.7.0-1.el7.x86_64.rpm

升级cmake

cd /usr/local/src
yum -y install wget
yum remove cmake -y
wget https://cmake.org/files/v3.21/cmake-3.21.0-linux-x86_64.tar.gz
tar zxvf cmake-3.21.0-linux-x86_64.tar.gz
mv cmake-3.21.0-linux-x86_64 /usr/local/cmake

编辑并配置

vim /etc/profile.d/cmake.sh 
export CMAKE_HOME=/usr/local/cmake
export PATH=$CMAKE_HOME/bin:$PATH
# 执行
source  /etc/profile.d/cmake.sh 

安装 libzip

wget https://libzip.org/download/libzip-1.8.0.tar.gz
tar -zxvf libzip-1.8.0.tar.gz
cd libzip-1.8.0
mkdir build && cd build
cmake ..
make install
export PKG_CONFIG_PATH="/usr/local/lib64/pkgconfig/":$PKG_CONFIG_PATH

下载php源码包,编译安装

groupadd php-fpm
useradd -s /sbin/nologin -g php-fpm -M php-fpm
cd /usr/loca/src
wget https://www.php.net/distributions/php-8.1.3.tar.gz
tar zxvf php-8.1.3.tar.gz

编译参数

./configure \
--prefix=/usr/local/php8 \
--with-config-file-path=/usr/local/php8 \
--with-config-file-scan-dir=/usr/local/php8/php.d \
--enable-mysqlnd \
--with-mysqli \
--with-pdo-mysql \
--enable-gd \
--with-gmp \
--with-jpeg \
--with-iconv \
--with-zlib \
--with-zip \
--with-openssl \
--enable-xml \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-pcntl \
--enable-sockets \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-freetype \
--enable-opcache \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--disable-fileinfo 

执行编译:

make && make install

配置php.ini

php.ini-development 测试开发环境
php.ini-production 生产环境

复制一份到指定的目录下(根据自己的情况选用,自己可以对比下这两个文件的差异):

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

配置php-fpm:

# 设置目录
mkdir /home/log/
cd /usr/local/php8/etc
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf

设置pid和log

error_log = /home/log/php-fpm.log
pid = /home/log/php-fpm.pid

配置www

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

使用systemctl命令来控制php-fpm

cd /usr/local/src/php-8.1.3
cp ./sapi/fpm/php-fpm.service  /usr/lib/systemd/system/

管理php-fpm

# 开机启动
systemctl enable php-fpm
# 启动
systemctl start php-fpm
# 查看状态
systemctl status php-fpm
# 停止
systemctl stop php-fpm

添加环境变量:

vim  /etc/profile
# 末尾追加
export PATH=$PATH:'/usr/local/php8/bin/'
# wq 保存退出,执行
source /etc/profile

测试:

php -v

问题

为啥需要给php-fpm 设置一个log目录呢? 默认的不行吗?
php-fpm的systemd配置文件(/usr/lib/systemd/system/php-fpm.service)中,
当ProtectSystem=true时php-fpm进程将以只读的方式挂载/usr、/boot目录;
当ProtectSystem=full时php-fpm进程将以只读的方式挂载/usr、/boot和/etc目录。
解决方法:

  1. 打开php-fpm的systemd配置文件/usr/lib/systemd/system/php-fpm.service,把ProtectSystem=true改成ProtectSystem=false,这种方式会对系统造成一定风险,生产环境不建议使用;
  2. 修改php-fpm的配置文件php-fpm.conf,把error_log设置为除/usr、/boot、/etc以外的目录中的文件。
打赏
文章版权声明:除非注明,否则均为彭超的博客原创文章,转载或复制请以超链接形式并注明出处。
相关推荐

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

猜你喜欢