ubuntu21.10:编译安装php8.1.1

一,下载php8的安装包:

1,创建目录:
root@lhdpc:~# mkdir /usr/local/source
root@lhdpc:~# mkdir /usr/local/soft
root@lhdpc:~# chmod 777 /usr/local/source/
root@lhdpc:~# chmod 777 /usr/local/soft
说明:习惯上用source目录保存源码或安装包
soft目录是安装后的可执行程序
 
2,官网下载地址:
https://www.php.net/downloads.php
下载:
root@lhdpc:~# cd /usr/local/source/
root@lhdpc:/usr/local/source# mkdir php8
root@lhdpc:/usr/local/source# cd php8
root@lhdpc:/usr/local/source/php8# wget https://www.php.net/distributions/php-8.1.1.tar.gz

 

3,解压:
root@lhdpc:/usr/local/source/php8# tar -zxvf php-8.1.1.tar.gz
root@lhdpc:/usr/local/source/php8# ls
php-8.1.1  php-8.1.1.tar.gz

说明:刘宏缔的架构森林是一个专注架构的博客,

网站:https://blog.imgtouch.com
本文: https://blog.imgtouch.com/index.php/2023/05/28/ubuntu21-10-bian-yi-an-zhuang-php8-1-1/

         对应的源码可以访问这里获取: https://github.com/liuhongdi/
         或: https://gitee.com/liuhongdi

说明:作者:刘宏缔 邮箱: 371125307@qq.com

 

二,配置php安装:configure

1,配置:
root@lhdpc:/usr/local/source/php8# cd php-8.1.1/
root@lhdpc:/usr/local/source/php8/php-8.1.1# ./configure --prefix=/usr/local/soft/php8 --with-config-file-path=/usr/local/soft/php8/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-ftp --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

 

2,
配置成功时的提示信息:
+--------------------------------------------------------------------+
| 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.

 

三,配置时的报错记录和解决:

1,
configure: error: in `/usr/local/source/php8/php-8.1.1':
configure: error: no acceptable C compiler found in $PATH
解决:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt-get install gcc

 

2,
checking for libxml-2.0 >= 2.9.0... no
configure: error: in `/usr/local/source/php8/php-8.1.1':
configure: error: The pkg-config script could not be found or is too old.  Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.
解决:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt-get install libxml2-dev
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt-get install pkg-config

 

3,
configure: error: Package requirements (krb5-gssapi krb5) were not met:
 
No package 'krb5-gssapi' found
No package 'krb5’ found
解决:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt-get install libkrb5-dev

 

4,
configure: error: Package requirements (openssl >= 1.0.2) were not met:
 
No package 'openssl' found 
解决:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt-get install libssl-dev

 

5,
configure: error: Package requirements (sqlite3 >= 3.7.7) were not met:
 
No package 'sqlite3’ found
解决:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt-get install libsqlite3-dev

 

6,
configure: error: Package requirements (zlib >= 1.2.0.4) were not met:
 
No package 'zlib’ found 
解决:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt-get install zlib1g-dev

 

7,
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
解决:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt-get install libbz2-dev

 

8,
checking for libcurl >= 7.29.0... no
configure: error: Package requirements (libcurl >= 7.29.0) were not met:
 
No package 'libcurl’ found
解决:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt-get install libcurl4-openssl-dev

 

9,
checking for libpng... no
configure: error: Package requirements (libpng) were not met:
 
No package 'libpng’ found
解决:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt-get install libpng-dev

 

10,
checking for libjpeg... no
configure: error: Package requirements (libjpeg) were not met:
 
No package 'libjpeg' found 
解决:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt-get install libjpeg-dev

 

11,
checking for freetype2... no
configure: error: Package requirements (freetype2) were not met:
 
No package 'freetype2’ found
解决:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt-get install libfreetype-dev

 

12,
checking whether the compiler supports GNU C++... no
checking whether g++ accepts -g... no
checking for g++ option to enable C++11 features... none needed
checking how to run the C++ preprocessor... /lib/cpp
configure: error: in `/usr/local/source/php8/php-8.1.1':
configure: error: C++ preprocessor "/lib/cpp" fails sanity check 
解决:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt-get install g++

 

13,
checking for oniguruma... no
configure: error: Package requirements (oniguruma) were not met:
 
No package 'oniguruma' found
解决:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt install libonig-dev

 

14,
checking for libxslt >= 1.1.0... no
configure: error: Package requirements (libxslt >= 1.1.0) were not met:
 
No package 'libxslt’ found
解决:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt install libxslt-dev

 

15,
checking for libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0... no
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:
 
No package 'libzip’ found
解决:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt install libzip-dev

 

四,编译php8

 1,编译
root@lhdpc:/usr/local/source/php8/php-8.1.1# make
说明:事先应该安装有make命令:
可以用下面的命令安装:
root@lhdpc:/usr/local/source/php8/php-8.1.1# apt install make 
2,看到如下内容时,表示编译完成:
Build complete.
Don't forget to run 'make test'.

 

五,安装php8

1,安装
root@lhdpc:/usr/local/source/php8/php-8.1.1# make install
2,测试效果:
root@lhdpc:/usr/local/source/php8/php-8.1.1# /usr/local/soft/php8/bin/php --version
PHP 8.1.1 (cli) (built: Dec 20 2021 16:12:16) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies 
能看到版本表示已安装成功
 

六,生成配置文件:

1,生成php.ini
root@lhdpc:/usr/local/source/php8/php-8.1.1# cp php.ini-production /usr/local/soft/php8/etc/php.ini
2,生成www.conf
root@lhdpc:/usr/local/source/php8/php-8.1.1# cd /usr/local/soft/php8/etc/php-fpm.d/
root@lhdpc:/usr/local/soft/php8/etc/php-fpm.d# ls
www.conf.default
root@lhdpc:/usr/local/soft/php8/etc/php-fpm.d# cp www.conf.default www.conf
3,生成php-fpm.conf
root@lhdpc:/usr/local/soft/php8/etc/php-fpm.d# cd /usr/local/soft/php8/etc
root@lhdpc:/usr/local/soft/php8/etc# ls
pear.conf  php-fpm.conf.default  php-fpm.d  php.ini
root@lhdpc:/usr/local/soft/php8/etc# cp php-fpm.conf.default php-fpm.conf 
 

七,测试php-fpm

1,配置用户:
root@lhdpc:/usr/local/source/php8/php-8.1.1/sapi/fpm# vim /usr/local/soft/php8/etc/php-fpm.d/www.conf
说明:指定用户为 www-data
如下:
;user = nobody
;group = nobody
user = www-data
group = www-data
说明:如果不设置会因为找不到nobody这个group而报错:
root@lhdpc:/usr/local/source/php8/php-8.1.1/sapi/fpm# systemctl status php-fpm
× php-fpm.service - The PHP FastCGI Process Manager
     Loaded: loaded (/etc/systemd/system/php-fpm.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2021-12-20 16:48:53 CST; 4s ago
    Process: 253676 ExecStart=/usr/local/soft/php8/sbin/php-fpm --nodaemonize --fpm-config /usr/local/soft/php8/etc/php-fpm.conf (code=exited, status=78)
   Main PID: 253676 (code=exited, status=78)
        CPU: 304ms
 
12月 20 16:48:53 lhdpc systemd[1]: Started The PHP FastCGI Process Manager.
12月 20 16:48:53 lhdpc php-fpm[253676]: [20-Dec-2021 16:48:53] ERROR: [pool www] cannot get gid for group 'nobody'
12月 20 16:48:53 lhdpc php-fpm[253676]: [20-Dec-2021 16:48:53] ERROR: FPM initialization failed
12月 20 16:48:53 lhdpc systemd[1]: php-fpm.service: Main process exited, code=exited, status=78/CONFIG
12月 20 16:48:53 lhdpc systemd[1]: php-fpm.service: Failed with result 'exit-code'.
2,生成启动文件:
root@lhdpc:/usr/local/source/php8/php-8.1.1/sapi/fpm# cp php-fpm.service /etc/systemd/system/
然后做一下修改:
root@lhdpc:/usr/local/source/php8/php-8.1.1/sapi/fpm# vim /etc/systemd/system/php-fpm.service
修改内容:
# Mounts the /usr, /boot, and /etc directories read-only for processes invoked by this unit.
#ProtectSystem=full
ProtectSystem=false
把 ProtectSystem=full修改为: ProtectSystem=false
说明:如果不做修改会报错如下
查看报错:
root@lhdpc:/usr/local/source/php8/php-8.1.1/sapi/fpm# systemctl status php-fpm
× php-fpm.service - The PHP FastCGI Process Manager
     Loaded: loaded (/etc/systemd/system/php-fpm.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2021-12-20 16:44:02 CST; 3s ago
    Process: 252867 ExecStart=/usr/local/soft/php8/sbin/php-fpm --nodaemonize --fpm-config /usr/local/soft/php8/etc/php-fpm.conf (code=exited, status=78)
   Main PID: 252867 (code=exited, status=78)
        CPU: 317ms
 
12月 20 16:44:02 lhdpc systemd[1]: Started The PHP FastCGI Process Manager.
12月 20 16:44:02 lhdpc php-fpm[252867]: [20-Dec-2021 16:44:02] ERROR: failed to open error_log (/usr/local/soft/php8/var/log/php-fpm.log): Read-only file system (30)
12月 20 16:44:02 lhdpc php-fpm[252867]: [20-Dec-2021 16:44:02] ERROR: failed to post process the configuration
12月 20 16:44:02 lhdpc php-fpm[252867]: [20-Dec-2021 16:44:02] ERROR: FPM initialization failed
12月 20 16:44:02 lhdpc systemd[1]: php-fpm.service: Main process exited, code=exited, status=78/CONFIG
12月 20 16:44:02 lhdpc systemd[1]: php-fpm.service: Failed with result 'exit-code’.
3,启动
因为service文件做过修改,做一次加载:
root@lhdpc:/usr/local/source/php8/php-8.1.1/sapi/fpm# systemctl daemon-reload
启动:
root@lhdpc:/usr/local/source/php8/php-8.1.1/sapi/fpm# systemctl start php-fpm
4,查看php-fpm的进程:
root@lhdpc:/usr/local/source/php8/php-8.1.1/sapi/fpm# ps auxfww | grep php
root      253913  0.0  0.0  12248  2384 pts/1    S+   16:57   0:00  |   |           \_ grep --color=auto php
root      253906  2.8  0.6  82380 25064 ?        Ss   16:57   0:00 php-fpm: master process (/usr/local/soft/php8/etc/php-fpm.conf)
www-data  253908  0.0  0.2  82864  9752 ?        S    16:57   0:00  \_ php-fpm: pool www
www-data  253909  0.0  0.2  82864  9752 ?        S    16:57   0:00  \_ php-fpm: pool www

 

八,安装nginx,配置nginx可访问php-fpm

1,安装nginx
root@lhdpc:~# apt-get install nginx
2,
创建目录和一个php程序:
root@lhdpc:/etc/nginx/sites-enabled# mkdir -p /data/web/html
root@lhdpc:/etc/nginx/sites-enabled# cd /data/web/html
root@lhdpc:/data/web/html# vi index.php
root@lhdpc:/data/web/html# more index.php
<?php
  phpinfo();
?>
3,配置一个站点,供测试php使用:
root@lhdpc:/data/web/html# cd /etc/nginx/sites-enabled/
root@lhdpc:/etc/nginx/sites-enabled# vim php.conf
root@lhdpc:/etc/nginx/sites-enabled# more php.conf
server {
        listen       8003;
        root   /data/web/html;
        location ~ \.php {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }
    }
说明:创建了一个端口是8003的站点
 
4,测试访问:
http://127.0.0.1:8003/index.php
如图:

九,启动jit

默认安装完成后,phpinfo的返回内容中没有一段专门的opcache配置段,
表示opcache还未开启
1,
root@lhdpc:/usr/local/soft/php8/etc# vim php.ini
在[opcache]段编辑如下:
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.jit_buffer_size=128M
opcache.jit=tracing
zend_extension=opcache
2,重启:
root@lhdpc:/usr/local/soft/php8/etc# systemctl reload php-fpm.service 
3,查看效果:
可以看到新增了Zend OPcache段
 
说明:
关于tracing和function
 

十,查看linux的版本:

root@lhdpc:/usr/local/soft/php8/etc# cat /etc/os-release
PRETTY_NAME="Ubuntu 21.10"
NAME="Ubuntu"
VERSION_ID="21.10"
VERSION="21.10 (Impish Indri)"
VERSION_CODENAME=impish
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=impish

 

posted @ 2021-12-21 10:41  刘宏缔的架构森林  阅读(3557)  评论(0编辑  收藏  举报