(此方法允许同时安装多个PHP版本。)
从Ubuntu第三方源安装
The debian packages for PHP 8 is available under ppa:ondrej/php PPA for Ubuntu systems.
https://tecadmin.net/how-to-install-php-8-on-ubuntu-20-04
How to Install PHP 8.3 on Ubuntu 22.04 or 20.04
PHP-8.3.13
安装:
$ sudo apt install autoconf build-essential curl libtool libssl-dev libcurl4-openssl-dev libxml2-dev libreadline-dev libzip-dev openssl pkg-config zlib1g-dev libsqlite3-dev libonig-dev libpng-dev libfreetype6-dev freetype2-demos libjpeg-dev
$ ./configure --prefix=/var/www/php-8.1.13 --enable-mysqlnd --with-pdo-mysql --with-pdo-mysql=mysqlnd --enable-bcmath --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --enable-mbstring --enable-phpdbg --enable-shmop --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-zip --with-zlib --with-curl --with-pear --with-openssl --enable-pcntl --with-readline --enable-gd --enable-calendar --with-freetype --with-jpeg --with-mysqli
$ make
$ make test
$ make install
配置php.ini
$
cp php.ini-production /usr/local/php-8.3.14/lib/php.ini
change follow line in php.ini:
pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock
zend_extension=opcache.so
opcache.enable=1
memory_limit=2G
max_input_vars = 2000
post_max_size = 128M
upload_max_filesize = 128M
extension=apcu ; 需额外安装,见本文档后面
[apcu]
apc.enabled=1
apc.shm_size=128M
配置www.conf
$ cd /usr/local/php-8.3.14/etc;
$ cp php-fpm.conf.default php-fpm.conf
$ cp php-fpm.d/www.conf.default php-fpm.d/www.conf
$ vi
php-fpm.d/www.conf
listen = 127.0.0.1:9003
pm.max_children = 64
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 1500
request_terminate_timeout = 3600
$ sudo /usr/local/php-8.3.14/sbin/php-fpm
配置nginx:
location ~ \.php[?]* {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9003;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_read_timeout 3600;
}
$ sudo service nginx restart
PHP-8.1.13
安装:
$ sudo apt install autoconf build-essential curl libtool libssl-dev libcurl4-openssl-dev libxml2-dev libreadline-dev libzip-dev openssl pkg-config zlib1g-dev libsqlite3-dev libonig-dev libpng-dev libfreetype6-dev freetype2-demos libjpeg-dev
$ ./configure --prefix=/var/www/php-8.1.13 --enable-mysqlnd --with-pdo-mysql --with-pdo-mysql=mysqlnd --enable-bcmath --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --enable-mbstring --enable-phpdbg --enable-shmop --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-zip --with-zlib --with-curl --with-pear --with-openssl --enable-pcntl --with-readline --enable-gd --enable-calendar --with-freetype --with-jpeg --with-mysqli
$ make
$ make test
$ make install
安装libcurl:
如果上面的libcurl4-openssl-dev和libssl-dev冲突装不上,需要手动到下面地址从源码安装libcurl: https://curl.se/download.html
./configure --with-openssl && make && make test
make install
CentOS安装依赖
Download and install https://github.com/kkos/oniguruma, link pkg-config package.
Download and install https://libzip.org/download/ , cmake3 is required to build it. see INSTALL file. also need to link pkg-config file.
yum groupinstall 'Development Tools'
yum install libxml2-devel openssl-devel sqlite3-devel libsqlite3x-devel libcurl-devel libpng-devel libjpeg-devel freetype-devel readline-devel libzip-devel
./configure --prefix=/var/www-new-disk/php-8.2.6 --enable-mysqlnd --with-pdo-mysql --with-pdo-mysql=mysqlnd --enable-bcmath --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --enable-mbstring --enable-phpdbg --enable-shmop --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-zip --with-zlib --with-curl --with-pear --with-openssl --enable-pcntl --with-readline --enable-gd --enable-calendar --with-freetype --with-jpeg --with-mysqli --disable-opcache
make test的结果保存在php_test_results_20230516_0958.txt
安装apcu扩展
获取扩展包代码:https://pecl.php.net/package/apcu
$ wget https://pecl.php.net/get/apcu-5.1.24.tgz
$ tar zxvf apcu-5.1.24.tgz
$ cd apcu-5.1.24/
$ /usr/local/php-8.3.14/bin/phpize
$ ./configure --with-php-config=/usr/local/php-8.3.14/bin/php-config
$ make
$ make test
$ make install
Add following config to /usr/local/php-8.3.14/lib/php.ini
extension=apcu
Kill php process and restart:
$ cd /usr/local/php-8.3.14/sbin
$ ps -ef|grep php
$ kill 2665208
$ ./php-fpm &
PHP-7.4.6
安装:
$ sudo apt install autoconf build-essential curl libtool libssl-dev libcurl4-openssl-dev libxml2-dev libreadline-dev libzip-dev openssl pkg-config zlib1g-dev libsqlite3-dev libonig-dev libpng-dev libfreetype6-dev freetype2-demos libjpeg-dev
$ ./configure --prefix=/var/www/php-7.4.6 --enable-mysqlnd --with-pdo-mysql --with-pdo-mysql=mysqlnd --enable-bcmath --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --enable-mbstring --enable-phpdbg --enable-shmop --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-zip --with-zlib --with-curl --with-pear --with-openssl --enable-pcntl --with-readline --enable-gd --enable-calendar --with-freetype --with-jpeg --with-mysqli
$ make
$ make install
配置php.ini:
$
cp php.ini-production /var/www/php-7.4.6/lib/php.ini
change follow line in php.ini:
pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock
zend_extension=opcache.so
配置php-fpm:
$ cd /var/www/php-7.4.6/etc;
$ cp php-fpm.conf.default php-fpm.conf
$ cp php-fpm.d/www.conf.default php-fpm.d/www.conf
change port from 9000 to 9001 in php-fpm.d/www.conf if you are running more than one php-fpm.
$ sudo /var/www/php-7.4.6/sbin/php-fpm
配置nginx:
location ~ ^/test/drupal9/.*\.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass 127.0.0.1:9001;
}
参考:
https://www.php.net/manual/en/install.unix.debian.php#122244
评论