计算机网络/计算机科学与应用/系统/运维/开发

CentOS7 源码安装PHP7

1、下载php源码

[root@VM-4-2-centos ~]# wget https://www.php.net/distributions/php-7.4.26.tar.gz
--2023-07-25 17:16:00--  https://www.php.net/distributions/php-7.4.26.tar.gz
Resolving www.php.net (www.php.net)... 185.85.0.29, 2a02:cb40:200::1ad
Connecting to www.php.net (www.php.net)|185.85.0.29|:443... connected.
ERROR: cannot verify www.php.net's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’:
  Issued certificate has expired.
To connect to www.php.net insecurely, use `--no-check-certificate'.

如果出现错误:

解决办法  wget  --no-check-certificate....

[root@VM-4-2-centos ~]# wget --no-check-certificate https://www.php.net/distributions/php-7.4.26.tar.gz
--2023-07-25 17:17:35--  https://www.php.net/distributions/php-7.4.26.tar.gz
Resolving www.php.net (www.php.net)... 185.85.0.29, 2a02:cb40:200::1ad
Connecting to www.php.net (www.php.net)|185.85.0.29|:443... connected.
WARNING: cannot verify www.php.net's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’:
  Issued certificate has expired.
HTTP request sent, awaiting response... 200 OK
Length: 16869978 (16M) [application/octet-stream]
Saving to: ‘php-7.4.26.tar.gz’
100%[============================================================================================================================>] 16,869,978  2.77MB/s   in 6.0s   
2023-07-25 17:17:42 (2.69 MB/s) - ‘php-7.4.26.tar.gz’ saved [16869978/16869978]

2、解压php

# tar -zxvf php-7.4.26.tar.gz
# cd php-7.4.26

3、安装依赖

[root@VM-4-2-centos ~]# yum install gcc libxml2-devel
[root@VM-4-2-centos ~]# yum install gcc build-essential sqlite-devel

4、编译安装

[root@VM-4-2-centos php-7.4.26]# ./configure --prefix=/usr/local/php

执行成功,如下所示:

Generating files
configure: patching main/php_config.h.in
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
+--------------------------------------------------------------------+
| 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.
[root@VM-4-2-centos php-7.4.26]#


5、执行安装

[root@VM-4-2-centos php-7.4.26]# make
[root@VM-4-2-centos php-7.4.26]# make install

6、查看目录

[root@VM-4-2-centos php-7.4.26]# cd /usr/local/php/
[root@VM-4-2-centos php]# ll
total 20
drwxr-xr-x 2 root root 4096 Jul 25 17:31 bin
drwxr-xr-x 3 root root 4096 Jul 25 17:31 include
drwxr-xr-x 3 root root 4096 Jul 25 17:31 lib
drwxr-xr-x 3 root root 4096 Jul 25 17:31 php
drwxr-xr-x 4 root root 4096 Jul 25 17:31 var

7、配置环境变量

# vi /etc/profile

文件末尾添加如下:

unset -f pathmunge
PATH=$PATH:/usr/local/php/bin
export PATH
source /etc/profile


8、测试php环境变量是否成功

[root@VM-4-2-centos php]# php -i
phpinfo()
PHP Version => 7.4.26
System => Linux VM-4-2-centos 3.10.0-1160.88.1.el7.x86_64 #1 SMP Tue Mar 7 15:41:52 UTC 2023 x86_64
Build Date => Jul 25 2023 17:27:49

或者:php --version

[root@VM-4-2-centos php]# php --version
PHP 7.4.26 (cli) (built: Jul 25 2023 17:29:54) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

9、测试创建一个php文件:1.php

[root@VM-4-2-centos ~]# php 1.php 
hello,php[root@VM-4-2-centos ~]#



只要一个人还有追求,他就没有老。直到后悔取代了梦想,一个人才算老。熬过了必须的苦,才能过上喜欢的生活。

评论

^