第二章 Centos7下PHP-8.0.0编译安装

一、下载安装包

#1.创建目录
[root@jindada ~]$ mkdir /package

#2.下载PHP安装包
[root@jindada ~]$ cd  /package
[root@jindada /package]$ wget https://www.php.net/distributions/php-8.0.0.tar.gz

#3.解压安装包
[root@jindada /package]$ tar -zxvf php-8.0.0.tar.gz

二、编译安装 php8

1.安装依赖包

[root@jindada /package]$ yum -y install libxml2-devel sqlite-devel bzip2-devel libcurl-devel libpng-devel libjpeg-devel freetype-devel libicu-devel oniguruma-devel libxslt-devel

2.编译安装libzip-devel依赖包

由于yum版本安装libzip-devel依赖包过低,必须下载新版本安装。
#1.下载依赖包
[root@jindada /package]$ wget https://nih.at/libzip/libzip-1.2.0.tar.gz

#2.解压依赖包
[root@jindada /package]$ tar xf libzip-1.2.0.tar.gz

#3.配置依赖包
[root@jindada /package]$ cd libzip-1.2.0
[root@jindada /package]$ ./configure

#4.编译安装依赖包
[root@jindada /package]$ make&&make install

#5.配置环境变量
[root@jindada /package]$ vim /etc/profile.d/libzip.sh 
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

[root@jindada /package]$ source /etc/profile 

3.配置PHP8.0

[root@jindada /package]$ cd /php-8.0.0
[root@jindada /package/php-8.0.0]$ ./configure --prefix=/usr/local/php-8.0.0 --with-config-file-path=/usr/local/php-8.0.0/etc --with-curl --with-freetype --enable-gd --with-jpeg  --with-gettext --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pdo-mysql  --with-pdo-sqlite --with-pear --enable-sockets --with-mhash --with-ldap-sasl --with-xsl --with-zlib --with-zip -with-bz2 --with-iconv  --enable-fpm --enable-pdo  --enable-bcmath  --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl  --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-sysvsem --enable-cli --enable-opcache --enable-intl --enable-calendar --enable-static --enable-mysqlnd --disable-fileinfo

4.配置成功后

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

5.编译:

[root@jindada /package/php-8.0.0]$ make

#.make完成后的提示:
Build complete.
Don't forget to run 'make test'. 

6.安装

[root@jindada /package/php-8.0.0]$ make install

三、查看安装版本

[root@jindada /package/php-8.0.0]$ /usr/local/php-8.0.0/bin/php --version
PHP 8.0.0 (cli) (built: Dec 29 2020 11:51:52) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies

四、配置软连接

[root@jindada /package/php-8.0.0]$ ln -s /usr/local/php-8.0.0/ /usr/local/php

五、生成各个配置文件:

#1.生成php.ini配置文件:
[root@jindada /package/php-8.0.0]$ cp php.ini-production /usr/local/php/etc/php.ini

#2.生成www.conf配置文件
[root@jindada /package/php-8.0.0]$ cd /usr/local/php/etc/php-fpm.d/
[root@jindada /usr/local/php/etc/php-fpm.d]$ cp www.conf.default www.conf

#3.生成php-fpm的配置文件
[root@jindada /usr/local/php/etc/php-fpm.d]$ cd /usr/local/php/etc/       
[root@jindada /usr/local/php/etc]$ cp php-fpm.conf.default php-fpm.conf

六、配置PHP文件

#1.配置www.conf文件
[root@jindada /usr/local/php/etc]$ cd /usr/local/php/etc/php-fpm.d/
[root@jindada /usr/local/php/etc/php-fpm.d]$ vim www.conf
user = www
group = www

#2.配置php.ini文件
[root@jindada /usr/local/php/etc/php-fpm.d]$ cd /usr/local/php/etc/
[root@jindada /usr/local/php/etc]$ vim php.ini
post_max_size = 100M
upload_max_filesize = 100M

七、启动php-fpm

1.生成php-fpm启动文件

#1.创建启动目录
[root@jindada /package/php-8.0.0]$ mkdir /usr/local/php/daemon

#2.复制启动文件
[root@jindada /package/php-8.0.0]$ cp /package/php-8.0.0/sapi/fpm/init.d.php-fpm /usr/local/php/daemon

#3.修改启动文件权限
[root@jindada /package/php-8.0.0]$ chmod 740 /usr/local/php/daemon/init.d.php-fpm 

2.配置system启动

#1.配置system启动
[root@jindada /package/php-8.0.0]$ vim /etc/systemd/system/php-fpm.service 
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target

#2.system重载
[root@jindada /package/php-8.0.0]$ systemctl daemon-reload

3.启动php-fpm

#1.init.d启动
[root@kubemaster ~]# /usr/local/soft/php8/daemon/php-fpm start
Starting php-fpm  done

#2.system启动
[root@jindada /package/php-8.0.0]$ systemctl  start php-fpm.service 
[root@jindada /package/php-8.0.0]$ systemctl  status php-fpm.service 
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/etc/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
   Active: active (running) since 二 2020-12-29 15:03:47 CST; 6s ago
 Main PID: 8072 (php-fpm)
   CGroup: /system.slice/php-fpm.service
           ├─8072 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
           ├─8073 php-fpm: pool www
           └─8074 php-fpm: pool www
12月 29 15:03:47 jindada systemd[1]: Started The PHP FastCGI Process Manager.

4.查看进程中是否已启动

[root@jindada /package/php-8.0.0]$ ps -aux |grep php-fpm
root      8072  0.0  0.5 164660 10684 ?        Ss   15:03   0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
www       8073  0.0  0.2 164660  5008 ?        S    15:03   0:00 php-fpm: pool www
www       8074  0.0  0.2 164660  5008 ?        S    15:03   0:00 php-fpm: pool www
root      8354  0.0  0.0 112828   976 pts/1    R+   15:09   0:00 grep --color=auto php-fpm

5.查看php-fpm默认守护的端口:


[root@jindada /package/php-8.0.0]$ netstat  -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      8072/php-fpm: maste 
posted @ 2021-01-05 17:25  年少纵马且长歌  阅读(2886)  评论(3编辑  收藏  举报