(此方法允许同时安装多个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.4.27
$ wget https://www.php.net/distributions/php-8.4.27.tar.xz
$ cd php-8.4.27
$ ./configure --prefix=/opt/php-8.4.27 --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 installPHP-8.3.36
安装:
$ 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=/opt/php-8.3.36 --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 /opt/php-8.3.36/lib/php.inichange 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 /opt/php-8.3.36/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.conflisten = 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 /opt/php-8.3.36/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-opcachemake test的结果保存在php_test_results_20230516_0958.txt
安装apcu扩展
获取扩展包代码:https://pecl.php.net/package/apcu
$ wget https://pecl.php.net/get/apcu-5.1.28.tgz
$ tar zxvf apcu-5.1.28.tgz
$ cd apcu-5.1.28/
$ /opt/php-8.3.36/bin/phpize
$ ./configure --with-php-config=/opt/php-8.3.36/bin/php-config
$ make
$ make test
$ make installAdd following config to /usr/local/php-8.3.14/lib/php.ini
extension=apcuKill php process and restart:
$ cd /opt/php-8.3.36/sbin
$ ps -ef|grep php
$ kill 2665208
$ ./php-fpm &PHP-7.4.33
安装:
$ 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=/opt/php-7.4.33 --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 /opt/php-7.4.33/lib/php.inichange follow line in php.ini:
pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock
extension=/opt/php-7.4.33/lib/php/extensions/no-debug-non-zts-20190902/mcrypt.so ; 需安装扩展,见后面
zend_extension=opcache.so
max_execution_time = 1200
max_input_time = 1600
memory_limit = 2G
post_max_size = 512M
upload_max_filesize = 128M
default_socket_timeout = 1600
配置php-fpm:
$ cd /opt/php-7.4.33/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.
pm.max_children = 64pm.start_servers = 3pm.max_spare_servers = 5php_admin_value[post_max_size] = 128Mphp_admin_value[upload_max_filesize] = 128Mphp_admin_value[memory_limit] = 2G
$ sudo /opt/php-7.4.33/sbin/php-fpm
配置nginx:
location ~ ^/test/drupal9/.*\.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass 127.0.0.1:9001;
}
安装mcrypt扩展
获取扩展包代码:https://pecl.php.net/package/mcrypt
$ wget https://pecl.php.net/get/mcrypt-1.0.9.tgz
$ tar zxvf mcrypt-1.0.9.tgz
$ cd mcrypt-1.0.9/
$ /opt/php-7.4.33/bin/phpize
$ ./configure --with-php-config=/opt/php-7.4.33/bin/php-config
$ make
$ make test
$ make installPHP-7.2.34
安装:
$ ./configure --prefix=/opt/php-7.2.34 --with-pdo-mysql --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 --enable-zip --with-zlib --with-curl --with-pear --with-openssl --enable-pcntl --with-readline --with-gd --enable-calendar --with-freetype-dir --with-jpeg-dir --with-mysqli
$ make
$ make install
配置php.ini:
$
cp php.ini-production /opt/php-7.2.34/lib/php.inichange follow line in php.ini:
pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock
extension=/opt/php-7.2.34/lib/php/extensions/no-debug-non-zts-20170718/mcrypt.so ; 需安装扩展,见后面
zend_extension=opcache.so
max_execution_time = 1200
max_input_time = 1600
memory_limit = 2G
post_max_size = 512M
upload_max_filesize = 128M
default_socket_timeout = 1600
配置php-fpm:
$ cd /opt/php-7.2.34/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.
pm.max_children = 64pm.start_servers = 3pm.max_spare_servers = 5php_admin_value[post_max_size] = 128Mphp_admin_value[upload_max_filesize] = 128Mphp_admin_value[memory_limit] = 2G
$ sudo /opt/php-7.2.34/sbin/php-fpm
参考:
https://www.php.net/manual/en/install.unix.debian.php#122244
评论