«

linux 系统同时安装 php7.4 和 php 8.2

时间:2024-2-28 16:08     作者:韩俊     分类: Linux


php 7.4 已经存在了,nginx 也已经安装了,现在新安装 php 8.2,找到 php 源码包的下载地址:

https://www.php.net/downloads.php

选择 8.2 版本的最新地址:

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

tar -zxvf php-8.2.14.tar.gz

cd php-8.2.14

./configure --prefix=/usr/local/php8.2.14 --sysconfdir=/usr/local/php8.2.14/etc/  --enable-opcache --enable-session --enable-fpm  --with-mysqli --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv  --with-mhash --with-openssl --enable-bcmath --enable-gd --enable-soap   --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib  --with-bz2  --with-readline --with-webp --with-jpeg --with-imap-ssl --enable-exif --with-ffi --with-zip --with-pcre-jit

报错:

checking for libxml-2.0 >= 2.9.0... no
configure: error: Package requirements (libxml-2.0 >= 2.9.0) were not met:

No package 'libxml-2.0' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBXML_CFLAGS
and LIBXML_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

先查找看本地是否真的没有:

sudo find / -name libxml-2.0*

果真没找到,那就自己安装吧:

sudo apt install libxml2
sudo apt install libxml2-dev

又报错:

configure: error: Package requirements (sqlite3 >= 3.7.7) were not met:

No package 'sqlite3' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables SQLITE_CFLAGS
and SQLITE_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

执行:

sudo apt install libsqlite3-dev

又报错:

checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution

sudo apt install bzip2

正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
bzip2 已经是最新版 (1.0.8-2)。
升级了 0 个软件包,新安装了 0 个软件包, 要卸载 0 个软件包,有 0 个软件包未被升级。

我已经安装了bzip2,应该是需要安装bzip2-dev,可是运行命令sudo apt-get install bzip2-dev 结果是:E: 无法定位软件包 bzip2-dev
最后在Ubuntu bzip2 package 发现该库在Ubuntu的真正名字是libbz2-dev,所以执行如下命令配置通过:

sudo apt-get install libbz2-dev

又报错:

configure: error: Package requirements (libffi >= 3.0.11) were not met:

No package 'libffi' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables FFI_CFLAGS
and FFI_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

执行:

sudo apt-get install libffi-dev

又报错:

checking for libpng... no
configure: error: Package requirements (libpng) were not met:

No package 'libpng' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables PNG_CFLAGS
and PNG_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

执行:

sudo apt install libpng-dev

又报错:

checking for libwebp >= 0.2.0... no
configure: error: Package requirements (libwebp >= 0.2.0) were not met:

No package 'libwebp' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables WEBP_CFLAGS
and WEBP_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

执行:

sudo apt install libpng-dev

又报错:

checking for libjpeg... no
configure: error: Package requirements (libjpeg) were not met:

No package 'libjpeg' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables JPEG_CFLAGS
and JPEG_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

执行:

sudo apt install libjpeg-dev

又报错:

checking for oniguruma... no
configure: error: Package requirements (oniguruma) were not met:

No package 'oniguruma' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables ONIG_CFLAGS
and ONIG_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

执行:

sudo apt install libonig-dev

又报错:

configure: error: Please reinstall readline - I cannot find readline.h

执行:

sudo apt install libreadline-dev

又报错:

checking for libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0... no
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:

No package 'libzip' found
No package 'libzip' found
No package 'libzip' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBZIP_CFLAGS
and LIBZIP_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

执行:

sudo apt install libzip-dev

直到出现:

+--------------------------------------------------------------------+
| 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

......

PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
clicommand.inc
directorygraphiterator.inc
directorytreeiterator.inc
invertedregexiterator.inc
phar.inc
pharcommand.inc

Build complete.
Don't forget to run 'make test'.

make test
sudo make install

yhm-docker@/webDefault/php-8.2.14$sudo make install
Installing shared extensions:     /usr/local/php8.2.14/lib/php/extensions/no-debug-non-zts-20220829/
Installing PHP CLI binary:        /usr/local/php8.2.14/bin/
Installing PHP CLI man page:      /usr/local/php8.2.14/php/man/man1/
Installing PHP FPM binary:        /usr/local/php8.2.14/sbin/
Installing PHP FPM defconfig:     /usr/local/php8.2.14/etc/
Installing PHP FPM man page:      /usr/local/php8.2.14/php/man/man8/
Installing PHP FPM status page:   /usr/local/php8.2.14/php/php/fpm/
Installing phpdbg binary:         /usr/local/php8.2.14/bin/
Installing phpdbg man page:       /usr/local/php8.2.14/php/man/man1/
Installing PHP CGI binary:        /usr/local/php8.2.14/bin/
Installing PHP CGI man page:      /usr/local/php8.2.14/php/man/man1/
Installing build environment:     /usr/local/php8.2.14/lib/php/build/
Installing header files:          /usr/local/php8.2.14/include/php/
Installing helper programs:       /usr/local/php8.2.14/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php8.2.14/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PDO headers:           /usr/local/php8.2.14/include/php/ext/pdo/

sudo mv /usr/local/php8.2.14/etc/php-fpm.conf.default /usr/local/php8.2.14/etc/php-fpm.conf

sudo mv /usr/local/php8.2.14/etc/php-fpm.d/www.conf.default /usr/local/php8.2.14/etc/php-fpm.d/www.conf

参考 php7.4 的配置文件,

cat /etc/php/7.4/fpm/pool.d/www.conf

更改 php-fpm 的配置文件

sudo vim /usr/local/php8.2.14/etc/php-fpm.d/www.conf

更改如下内容:

user = www-data
group = www-data

取消注释:

listen.owner = www-data
listen.group = www-data

listen 改为:

listen = /run/php/php-fpm.sock

sudo find / -name 'phpize'
/var/lib/dpkg/alternatives/phpize
/etc/alternatives/phpize
/usr/local/php8.2.14/bin/phpize
/usr/bin/phpize

sudo find / -name 'php-config'
/var/lib/dpkg/alternatives/php-config
/etc/alternatives/php-config
/usr/local/php8.2.14/bin/php-config
/usr/bin/php-config

php 8 环境重要配置文件:

phpize 文件:

/usr/local/php8.2.14/bin/phpize

php-config 文件:

/usr/local/php8.2.14/bin/php-config

php-fpm 文件位置:

/usr/local/php8.2.14/sbin/php-fpm

php-fpm 配置文件位置:

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

php-fpm pid 文件位置:

run/php-fpm.pid

php.ini 文件位置:

/usr/local/php8.2.14/lib/php.ini

标签: linux

热门推荐