目录

centos安装PHP8

php8发布后就一直想体验下,但是自己的服务器内存只有1g一直无法编译成功,后来发现阿里云有乌兰察布的机器,比较便宜。就果断做了迁移,具体链接阿里云 ,选择乌兰察布的,现在有优惠。废话不多说,接下来就具体的讲怎么安装php8吧

1. 下载安装包,并解压

1
2
3
wget https://www.php.net/distributions/php-8.0.3.tar.gz
tar -zxvf php-8.0.3.tar.gz
cd php-8.0.3

2. 安装必要依赖

1
yum -y install libxml2-devel sqlite-devel libcurl-devel libpng-devel gmp-devel readline-devel oniguruma oniguruma-devel readline-devel libxslt-devel libzip-devel autoconf libmcrypt-devel libtool-devel

3. 执行config

1
./configure --prefix=/usr/local/php/php8 --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-config-file-path=/usr/local/php/php8/etc --with-config-file-scan-dir=/usr/local/php/php8/etc/php.d --with-pcre-regex --with-zlib --with-openssl --enable-bcmath --with-curl --with-gd --with-freetype-dir=/usr/local/php/php8 --with-jpeg-dir=/usr/local/php/php8 --with-png-dir=/usr/local/php/php8 --enable-gd-native-ttf --with-gmp --with-mhash --enable-mbstring --with-mcrypt --with-pdo-mysql --with-readline --with-openssl-dir --with-xmlrpc --with-xsl --enable-zip --enable-mysqlnd --with-pear --enable-opcache

直接沿用之前的config会提示以下报错

1
configure: WARNING: unrecognized options: --with-pcre-regex, --with-gd, --with-freetype-dir, --with-jpeg-dir, --with-png-dir, --enable-gd-native-ttf, --with-mcrypt, --with-xmlrpc, --enable-zip

查找了php8的变更记录,对于 –enable-gd-native-ttf, –with-mcrypt, –with-xmlrpc 直接删除就好,最后的config如下

1
./configure --prefix=/usr/local/php/php8 --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-config-file-path=/usr/local/php/php8/etc --with-config-file-scan-dir=/usr/local/php/php8/etc/php.d --with-external-pcre --with-zlib --with-openssl --enable-bcmath --with-curl --enable-gd --with-gmp --with-mhash --enable-mbstring --with-pdo-mysql --with-readline --with-openssl-dir --with-xsl --with-zip --enable-mysqlnd --with-pear --enable-opcache

4. make

1
2
make
make install

5. 添加用户组及修改配置文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
groupadd www
useradd -g www www

cp sapi/fpm/init.d.php-fpm /etc/init.d/php8-fpm
chmod +x /etc/init.d/php8-fpm
cp php.ini-development /usr/local/php/php8/etc/php.ini
cp /usr/local/php/php8/etc/php-fpm.conf.default /usr/local/php/php8/etc/php-fpm.conf
cp /usr/local/php/php8/etc/php-fpm.d/www.conf.default /usr/local/php/php8/etc/php-fpm.d/www.conf\n
ln -sf /usr/local/php/php8/bin/php /usr/local/bin/php8
ln -sf /usr/local/php/php8/bin/php /usr/bin/php8

6. 安装其他必要扩展

1
2
3
4
5
6
7
# mysqli
cd ext/mysqli/
/usr/local/php/php8/bin/phpize
./configure --with-php-config=/usr/local/php/php8/bin/php-config
make && make install
# mcrypt
/usr/local/php/php8/bin/pecl install mcrypt

7. 打开扩展配置

1
2
3
4
5
6
7
8
9
extension=mysqli
extension=mcrypt.so
//配置opcache和jit
zend_extension=opcache
opcache.enable=1
opcache.memory_consumption=128
opcache.validate_timestamps=600
opcache.jit=1235
opcache.jit_buffer_size=64M

8. 启动php

1
service php8-fpm start

到此就安装完了,剩下的jit就需要慢慢研究了