PHP8编译安装
PHP,全称Hypertext Preprocessor(超文本预处理器),是一种通用开源脚本语言。它特别适合于web开发,并能嵌入HTML中。现在主要用于PHP网站中实现动态网站功能,常规我们使用nginx、apache部署的是html静态网页,可以通过.php编写动态页面实现。1.php-ini,将源码目录下的php.ini-production复制到自己的目录下。2.生成www配置文件,将目
·
CentOS8编译安装PHP8
PHP,全称Hypertext Preprocessor(超文本预处理器),是一种通用开源脚本语言。它特别适合于web开发,并能嵌入HTML中。现在主要用于PHP网站中实现动态网站功能,常规我们使用nginx、apache部署的是html静态网页,可以通过.php编写动态页面实现。
一、下载
# 创建文件夹用来安装php
mkdir /www/php80
# 官网下载然后上传到服务器或者wget下载到对应文件夹
wget https://www.php.net/distributions/php-8.1.7.tar.gz
# 解压文件
tar -zxvf php-8.1.7.tar.gz
# 修改文件夹用户和组,防止没有权限执行
chown -R root php-8.1.7
chgrp -R root php-8.1.7
cd php-8.1.7
二、安装配置
# 和nginx编译安装类似,使用.configure进行配置
# --prefix:php.ini文件路径位置
# --with-config-file-path : 配置文件
./configure --prefix=/www/php8 --with-config-file-path=/www/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
报错处理:
1.libxml
问题:
Package 'libxml-2.0', required by 'virtual:world', not found
解决方法:
yum install libxml2-devel
2.sqlite3
问题:
Package 'sqlite3', required by 'virtual:world', not found
解决方法:
yum install sqlite-devel
3.Bzip2
问题:
configure: error: Please reinstall the BZip2 distribution
解决方法:
yum -y install bzip2-devel
4.libcurl
问题:
Package 'libcurl', required by 'virtual:world', not found
解决方法:
yum install libcurl-devel
5.libpng
问题:
Package 'libpng', required by 'virtual:world', not found
解决方法:
yum install libpng libpng-devel
6.libjpeg
问题:
Package 'libjpeg', required by 'virtual:world', not found
解决方法:
yum install libjpeg-devel
7.freetype2
问题:
Package 'freetype2', required by 'virtual:world', not found
解决方法:
yum install freetype-devel
8.icu
问题:
Package 'icu-uc', required by 'virtual:world', not found
Package 'icu-io', required by 'virtual:world', not found
Package 'icu-i18n', required by 'virtual:world', not found
解决方法:
yum install -y libicu-devel.x86_64
9.oniguruma
问题:
Package 'oniguruma', required by 'virtual:world', not found
解决方法:
1.下载安装包
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
2.解压
tar -zxvf oniguruma-6.9.4.tar.gz
3.进入文件夹进行编译安装
cd oniguruma-6.9.4
4.安装依赖
yum install autoconf automake libtool
5.编译到/usr目录下
./autogen.sh && ./configure --prefix=/usr
6.安装
make && make install
10.libxslt
问题:
Package 'libxslt', required by 'virtual:world', not found
解决方法:
yum -y install libxslt-devel
11.libzip
问题:
Package 'libzip', required by 'virtual:world', not found
Package 'libzip', required by 'virtual:world', not found
Package 'libzip', required by 'virtual:world', not found
解决方法:
yum install libzip-devel
终于完成了,出现下面的提示:
Generating files
configure: patching main/php_config.h.in
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
+--------------------------------------------------------------------+
| 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 install
完成:
Don't forget to run 'make test'.
Installing shared extensions: /www/php8/lib/php/extensions/no-debug-non-zts-20210902/
Installing PHP CLI binary: /www/php8/bin/
Installing PHP CLI man page: /www/php8/php/man/man1/
Installing PHP FPM binary: /www/php8/sbin/
Installing PHP FPM defconfig: /www/php8/etc/
Installing PHP FPM man page: /www/php8/php/man/man8/
Installing PHP FPM status page: /www/php8/php/php/fpm/
Installing phpdbg binary: /www/php8/bin/
Installing phpdbg man page: /www/php8/php/man/man1/
Installing PHP CGI binary: /www/php8/bin/
Installing PHP CGI man page: /www/php8/php/man/man1/
Installing build environment: /www/php8/lib/php/build/
Installing header files: /www/php8/include/php/
Installing helper programs: /www/php8/bin/
program: phpize
program: php-config
Installing man pages: /www/php8/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /www/php8/lib/php/
[PEAR] Archive_Tar - installed: 1.4.14
[PEAR] Console_Getopt - installed: 1.4.3
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.5
warning: pear/PEAR dependency package "pear/Archive_Tar" installed version 1.4.14 is not the recommended version 1.4.4
[PEAR] PEAR - installed: 1.10.13
Wrote PEAR system config file at: /www/php8/etc/pear.conf
You may want to add: /www/php8/lib/php to your php.ini include_path
/www/php-8.1.7/build/shtool install -c ext/phar/phar.phar /www/php8/bin/phar.phar
ln -s -f phar.phar /www/php8/bin/phar
Installing PDO headers: /www/php8/include/php/ext/pdo/
三、文件设置
1.php-ini,将源码目录下的php.ini-production复制到自己的目录下
cp php.ini-production /www/php8/etc/php.ini
2.生成www配置文件,将目录下的模板文件重命名
cd /www/php8/etc/php-fpm.d/
cp www.conf.default www.conf
3.生成php-fpm配置文件
cd /www/php8/etc/
cp php-fpm.conf.default php-fpm.conf
4.生成php-fpm可执行文件
# 创建存放配置文件的目录
mkdir php-fpm
# 从源码中复制一份fpm可执行脚本
cp /www/php-8.1.7/sapi/fpm/init.d.php-fpm /www/php8/etc/php-fpm/php-fpm
# 修改可执行文件的权限
chmod 740 php-fpm
四、进程启用管理
# 使用可执行文件进行启动
cd /www/php8/etc/php-fpm/
./php-fpm start
# 正常启动:
Starting php-fpm done
# ps查看进程是否启动
ps -aux | grep php-fpm
# 查看php-fpm进程占用的端口,正常应该是9000
netstat -nltp
# 查看php版本
cd /www/php8/bin/
./php -v
使用systemctl管理服务
# 修改/php/etc/php-fpm.conf
[global]
; Pid file
; Note: the default prefix is /www/php8/var
; Default Value: none
; pid = run/php-fpm.pid # 将前面分号删除
vim /usr/lib/systemd/system/php-fpm.service
# 添加下面内容,目录要配置自己的对应目录
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 保存文件
# 使用systemctl管理
systemctl daemon-reload # 刷新systemctl
systemctl start php-fpm # 启动进程
systemctl stop php-fpm # 结束进程
systemctl enable php-fpm# 开机启动
五、模块功能更新
1.进入源码目录进行编译安装
# php -m输出php的功能模块,在源码包的ext里面可以看到相应的模块,这些是自带的模块
cd /www/php-8.1.7/ext/
# 查看模块
ls
# 测试exif
cd exif
# 进入文件夹,使用phpize生成configure文件进行编译安装
cd /www/php8/bin/phpize
# 编译时指定配置文件
./configure --with-php-config=/www/php8/bin/php-config
# 安装
make && make install
# 安装完成之后会出现一个目录,里面包含了exif.so文件
# 修改php.ini,在最后添加上添加模块的路径
vim /www/php8/etc/php.ini
extension=/www/php8/lib/php/extensions/no-debug-non-zts-20210902/exif.so
# 保存,重启php-fpm进程
# 通过php -m 查看模块功能已经添加
本文由 mdnice 多平台发布
更多推荐
已为社区贡献1条内容
所有评论(0)