ubuntu21.10:编译安装php8.1.1

网站技术评论1,108阅读模式

一,下载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

下载:文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

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,解压:文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

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

二,配置php安装:configure

1,配置:文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

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.文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

configure: error: in `/usr/local/source/php8/php-8.1.1':
configure: error: no acceptable C compiler found in $PATH

2,文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

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.

解决:文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

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,文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

configure: error: Package requirements (krb5-gssapi krb5) were not met:
No package 'krb5-gssapi' found
No package 'krb5’ found

解决:文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

root@lhdpc:/usr/local/source/php8/php-8.1.1# apt-get install libkrb5-dev

4,文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

configure: error: Package requirements (openssl >= 1.0.2) were not met:
No package 'openssl' found

解决:文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

root@lhdpc:/usr/local/source/php8/php-8.1.1# apt-get install libssl-dev

5,文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

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,文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

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,文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

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,文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

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,文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

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,文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

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,文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

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,文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

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,文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

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,文章源自爱尚资源教程网-https://www.23jcw.net/2286.html

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
相关文章
版权声明:文章图片资源来源于网络,如有侵权,请留言删除!!!
  • 温馨提示:如遇到资源下载不了,或者文章没有解决你的问题的,可以联系我们帮你处理!!!
  • 转载请务必保留本文链接:https://www.23jcw.net/2286.html

发表评论