Centos7安装php8

无道 2021-07-13 0 条评论 教程相关 阅读233 手机阅读

title: 'Centos7安装php8' date: 2021-07-12T20:00:59+08:00 draft: false slug: 'centos7-install-php-8'


CentOS 7.*编译安装PHP8 - Leone- - 博客园 (cnblogs.com)

创建组

groupadd -r www && useradd -r -g www -s /bin/false -d /usr/local/php8 -M php

安装依赖

yum -y install libxml2 libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel sqlite-devel oniguruma-devel

下载一些东西

wget https://www.php.net/distributions/php-8.0.8.tar.bz2
wget https://github.com/phpredis/phpredis/archive/5.3.2.tar.gz -O phpredis-5.3.2.tar.gz
wget https://github.com/swoole/swoole-src/archive/v4.5.9.tar.gz -O swoole-src-4.5.9.tar.gz
wget http://pecl.php.net/get/mcrypt-1.0.3.tgz

wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
wget https://github.com/Kitware/CMake/releases/download/v3.16.0/cmake-3.17.2.tar.gz
wget https://libzip.org/download/libzip-1.5.2.tar.xz

Cmake若没下载下来,可以自行去github下载,通过本机上传到服务器上

注意版本问题(目录名称)

编译安装

libiconv1.16 和 CMAKE 3.17.2 和 libzip 1.5.2

 tar zxvf libiconv-1.16.tar.gz &&  cd libiconv-1.16  &&  ./configure --prefix=/usr/local/libiconv make && make install

 ln -s /usr/local/libiconv/lib/libiconv.so.2 /usr/lib64/libiconv.so.2
# 升级Cmake
tar -zxvf cmake-3.17.2.tar.gz && cd cmake-3.17.2
./bootstrap && gmake && gmake install
cmake -version
# 升级curl
tar xf curl-7.73.0.tar.gz && cd curl-7.73.0
./configure --prefix=/usr/local/curl/ --without-nss --with-ssl=/usr/local/openssl && make && make install
mv /usr/bin/curl /usr/bin/curl.bak
mv /usr/bin/curl-config /usr/bin/curl-config.bak
ln -s /usr/local/curl/bin/curl /usr/bin/curl
cp /usr/local/curl/bin/curl-config /usr/bin/curl-config
source /etc/profile && ldconfig
curl -V
# 升级libzip
tar xvJf libzip-1.5.2.tar.xz && cd libzip-1.5.2
mkdir build && cd build/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/libzip ..
make && make install

编译参数

tar -xjvf php-8.0.8.tar.bz2 && cd php-8.0.8


./configure \
--prefix=/usr/local/php8 --exec-prefix=/usr/local/php8 --bindir=/usr/local/php8/bin --sbindir=/usr/local/php8/sbin \
--includedir=/usr/local/php8/include --libdir=/usr/local/php8/lib/php --mandir=/usr/local/php8/php/man \
--with-config-file-path=/usr/local/php8/etc \
--with-mysql-sock=/usr/local/mysql/mysql.sock --with-mysqli=shared,mysqlnd --with-mhash \
--with-openssl=/usr/local/openssl --with-curl=/usr/local/curl \
--with-pdo-mysql=shared,mysqlnd --with-iconv --with-zlib \
--enable-inline-optimization \
--disable-debug --disable-rpath --enable-shared \
--enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp \
--enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session \
--enable-opcache --enable-fpm --without-gdbm --disable-fileinfo --with-fpm-user=www --with-fpm-group=www 

若configure: error: off_t undefined; check your library configuration,需执行以下命令:

echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
/usr/local/mysql/lib' >> /etc/ld.so.conf && ldconfig -v

编译安装

make && make install

配置文件

cp php-8.0.8/php.ini-production /usr/local/php8/etc/php.ini
cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf
cp php-8.0.8/sapi/fpm/php-fpm.service /lib/systemd/system/php-fpm.service

安装redis

tar zxvf phpredis-5.3.2.tar.gz && cd phpredis-5.3.2
/usr/local/php8/bin/phpize && ./configure --with-php-config=/usr/local/php8/bin/php-config && make && make install

安装fileinfo

## 有问题,暂不弄
cd php-8.0.8/ext/fileinfo && /usr/local/php8/bin/phpize  -std=c99  && ./configure --with-php-config=/usr/local/php8/bin/php-config && make && make install 

替换配置文件

替换/lib/systemd/system/php-fpm.service 中的 /usr/local/php8/var/run/php-fpm.pid 为 /run/php-fpm.pid

配置/usr/local/php8/etc/php-fpm.conf

######Pid file的默认前缀是/usr/local/php8/var
pid = /run/php-fpm.pid
error_log = /var/log/php/fpm-error.log
include=/usr/local/php8/etc/php-fpm.d/*.conf

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

######设置用户和用户组
user = www
group = www

######根据nginx.conf中的配置fastcgi_pass unix:/dev/shm/php-fpm.sock;设置PHP监听
; listen = 127.0.0.1:9000   #####不建议使用
listen = /dev/shm/php-fpm.sock
listen.owner = www
listen.group = www
listen.mode = 0777
listen.allowed_clients = /dev/shm/php-fpm.sock

######使用静态进程数max_children=内存/512
pm = static
pm.max_children = 200
pm.max_requests = 0

pm.status_path = /FpmStatus

######开启慢日志
slowlog = /var/log/php/fpm-$pool-slow.log
request_slowlog_timeout = 30s
request_slowlog_trace_depth = 20
request_terminate_timeout = 0

配置/usr/local/php8/etc/php.ini

######避免PHP信息暴露在http头中
expose_php = Off

######常用配置
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
display_errors = Off
log_errors = On
html_errors = Off
error_log = /var/log/php/cli-error.log
ignore_repeated_errors = On
ignore_repeated_source = On

memory_limit = 512M
max_execution_time = 600  (0为不限制)
max_input_time = -1
post_max_size = 128M
max_input_vars = 1000000
file_uploads = On
upload_tmp_dir = /tmp/www
upload_max_filesize = 100M
session.gc_maxlifetime = 14400
default_socket_timeout = 600  (-1为不限制)
######设置PHP的扩展
extension_dir = "/usr/local/php8/lib/php/extensions/no-debug-non-zts-20190902"
zend_extension=opcache.so
extension=mcrypt.so
extension=mysqli.so
extension=pdo_mysql.so
extension=redis.so
extension=swoole.so

######设置PHP的时区
date.timezone = "Asia/Shanghai"

######开启opcache
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.huge_code_pages=1
opcache.file_cache=/tmp
######设置PHP脚本允许访问的目录(需要根据实际情况配置)
;open_basedir = /usr/share/nginx/html;

session.save_handler = redis
session.save_path = "tcp://*****.aliyuncs.com:6379?auth=******"

[MySQLi]
mysqli.reconnect = On

nginx

配置:

location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
    fastcgi_pass unix://dev/shm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}
全文完 [
有帮助?打赏
支付宝打赏
微信打赏
]
标签: php centos7
修改: 07月13日 20:25
这篇文章还没有评论呢~
点击刷新/生成验证码