Home Backend Development PHP7 The correct way to install PHP7 on CentOS

The correct way to install PHP7 on CentOS

Jun 24, 2020 pm 05:58 PM
centos php7

The correct way to install PHP7 on CentOS

##The PHP versions on CentOS are very old and cannot meet the requirements of some frameworks. PHP version required. As a result, many third-party software libraries have emerged, such as EPEL, RPM Fusion, Remi, etc., which provide new versions of PHP. Let our system keep pace with the times.

However, third-party software libraries have several disadvantages: First, the software they provide has not been officially tested by CentOS. When installing the software, some core files of the system may be replaced, causing system instability. . Second, the software installed by third-party libraries may not guarantee compatibility, and upgrading the system may render certain software unusable.

So this article recommends using the SCL (Software Collections) software library to install a higher version of PHP. SCL belongs to the official software library of CentOS. It has been fully tested and will not replace the core files of the system when installing the software, ensuring the stability of the system.

Installing SCL is very simple, just one command is enough:

1

[root@localhost]# yum install centos-release-scl-rh

Copy after login
Copy after login

Then you can search for the new version of PHP in yum:

1

2

3

4

[root@localhost]# yum search php...php54-runtime.x86_64

php55-runtime.x86_64

rh-php56-runtime.x86_64

rh-php70-runtime.x86_64...

Copy after login
Copy after login

rh- The prefix means RedHat, telling you that this is the official PHP provided and not provided by a third-party library. The author guesses that this prefix specification was formulated around 2015, and PHP5.4 & 5.5 were released before that. In order to ensure the compatibility of your program (for example, some of your programs have already written yum install php55, add a prefix The program hangs), without the rh- prefix.

Next, install PHP7.0:

1

[root@localhost]# yum install rh-php70

Copy after login
Copy after login

After installation, PHP will actually be installed in the /opt/rh directory.

If you run the php command at this time, the system will still prompt you command not found. This is because the style of SCL is to minimize the impact of software on the system. Even after PHP is installed, the php command will not be added to the

$PATH variable, so you cannot directly execute the software. of the command. You need to display the execution through the scl enable command:

First look at what software is installed by SCL:

1

[root@localhost]# scl -lrh-php70

Copy after login
Copy after login

You can see that we have installed a rh-php70 in the system. First Enable it and execute the command:

1

[root@localhost]# scl enable rh-php70 "php -v"PHP 7.0.10 (cli) (built: Nov  3 2016 08:06:03) ( NTS )Copyright (c) 1997-2016 The PHP GroupZend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

Copy after login
Copy after login

The command was executed successfully. It would be too troublesome if every command had to be executed like this! It doesn't matter, you don't need to execute one command each time, but directly execute the

bash command, then the newly opened shell will automatically recognize php:

1

2

3

4

5

6

7

[root@localhost]# scl enable rh-php70 bash[root@localhost]# php -vPHP 7.0.10 (cli) (built: Nov  3 2016 08:06:03) ( NTS )

Copyright (c) 1997-2016 The PHP Group

Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

 

[root@localhost ~]# php -m[PHP Modules]

bz2

calendar...

Copy after login
Copy after login

SCL to

scl enable This method of management software adds a little trouble to use, but it absolutely guarantees system stability. And there is another advantage to doing this: multiple PHP versions can coexist on the system without conflicting with each other. It is convenient for you to test the compatibility of your code or framework on various versions of PHP.

In short, if you want to do a rigorous operation and maintenance, this article still highly recommends using SCL to manage the software on your system.

The PHP version on CentOS is very old and cannot meet the PHP version requirements of some frameworks. As a result, many third-party software libraries have emerged, such as EPEL, RPM Fusion, Remi, etc., which provide new versions of PHP. Let our system keep pace with the times.

However, third-party software libraries have several disadvantages: First, the software they provide has not been officially tested by CentOS. When installing the software, some core files of the system may be replaced, causing system instability. . Second, the software installed by third-party libraries may not guarantee compatibility, and upgrading the system may render certain software unusable.

So this article recommends using the SCL (Software Collections) software library to install a higher version of PHP. SCL belongs to the official software library of CentOS. It has been fully tested and will not replace the core files of the system when installing the software, ensuring the stability of the system.

Installing SCL is very simple, just one command is enough:

1

[root@localhost]# yum install centos-release-scl-rh

Copy after login
Copy after login

Then you can search for the new version of PHP in yum:

1

2

3

4

[root@localhost]# yum search php...php54-runtime.x86_64

php55-runtime.x86_64

rh-php56-runtime.x86_64

rh-php70-runtime.x86_64...

Copy after login
Copy after login

rh- The prefix means RedHat, telling you that this is the official PHP provided and not provided by a third-party library. The author guesses that this prefix specification was formulated around 2015, and PHP5.4 & 5.5 were released before that. In order to ensure the compatibility of your program (for example, some of your programs have already written yum install php55, add a prefix The program hangs), without the rh- prefix.

Next, install PHP7.0:

1

[root@localhost]# yum install rh-php70

Copy after login
Copy after login

After installation, PHP will actually be installed in the /opt/rh directory.

此时如果你运行php命令,系统依然会提示你command not found。这是因为,SCL的风格就是把软件对系统的影响减少到最小,甚至安装完PHP,php命令都不会被添加到 $PATH 变量中,所以你没法直接执行软件中的命令的。需要通过 scl enable 命令显示执行:

先看看SCL安装了哪些软件:

1

[root@localhost]# scl -lrh-php70

Copy after login
Copy after login

可以看到我们在系统安装了一个rh-php70,先启用它并执行命令:

1

[root@localhost]# scl enable rh-php70 "php -v"PHP 7.0.10 (cli) (built: Nov  3 2016 08:06:03) ( NTS )Copyright (c) 1997-2016 The PHP GroupZend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

Copy after login
Copy after login

命令成功执行了。要是每一条命令都要这么执行,太麻烦了!不要紧,你可以不用每次执行一条命令,而是直接执行 bash 命令,那么新开的shell就能自动识别php了:

1

2

3

4

5

6

7

[root@localhost]# scl enable rh-php70 bash[root@localhost]# php -vPHP 7.0.10 (cli) (built: Nov  3 2016 08:06:03) ( NTS )

Copyright (c) 1997-2016 The PHP Group

Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

 

[root@localhost ~]# php -m[PHP Modules]

bz2

calendar...

Copy after login
Copy after login

SCL以 scl enable 方式管理软件,虽然在使用上增加了一点点的麻烦,但这绝对地保证了系统稳定性。而且这么做还有一个好处:就是系统上可以多个PHP版本共存而互相不冲突。方便你测试代码或者框架,在各个版本PHP上的兼容性。

总之,要做一个严谨的运维,本篇还是十分推荐用SCL管理你系统上的软件。

推荐教程:《php视频教程

The above is the detailed content of The correct way to install PHP7 on CentOS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the backup methods for GitLab on CentOS What are the backup methods for GitLab on CentOS Apr 14, 2025 pm 05:33 PM

Backup and Recovery Policy of GitLab under CentOS System In order to ensure data security and recoverability, GitLab on CentOS provides a variety of backup methods. This article will introduce several common backup methods, configuration parameters and recovery processes in detail to help you establish a complete GitLab backup and recovery strategy. 1. Manual backup Use the gitlab-rakegitlab:backup:create command to execute manual backup. This command backs up key information such as GitLab repository, database, users, user groups, keys, and permissions. The default backup file is stored in the /var/opt/gitlab/backups directory. You can modify /etc/gitlab

How to optimize CentOS HDFS configuration How to optimize CentOS HDFS configuration Apr 14, 2025 pm 07:15 PM

Improve HDFS performance on CentOS: A comprehensive optimization guide to optimize HDFS (Hadoop distributed file system) on CentOS requires comprehensive consideration of hardware, system configuration and network settings. This article provides a series of optimization strategies to help you improve HDFS performance. 1. Hardware upgrade and selection resource expansion: Increase the CPU, memory and storage capacity of the server as much as possible. High-performance hardware: adopts high-performance network cards and switches to improve network throughput. 2. System configuration fine-tuning kernel parameter adjustment: Modify /etc/sysctl.conf file to optimize kernel parameters such as TCP connection number, file handle number and memory management. For example, adjust TCP connection status and buffer size

Centos stops maintenance 2024 Centos stops maintenance 2024 Apr 14, 2025 pm 08:39 PM

CentOS will be shut down in 2024 because its upstream distribution, RHEL 8, has been shut down. This shutdown will affect the CentOS 8 system, preventing it from continuing to receive updates. Users should plan for migration, and recommended options include CentOS Stream, AlmaLinux, and Rocky Linux to keep the system safe and stable.

Centos shutdown command line Centos shutdown command line Apr 14, 2025 pm 09:12 PM

The CentOS shutdown command is shutdown, and the syntax is shutdown [Options] Time [Information]. Options include: -h Stop the system immediately; -P Turn off the power after shutdown; -r restart; -t Waiting time. Times can be specified as immediate (now), minutes ( minutes), or a specific time (hh:mm). Added information can be displayed in system messages.

How to check CentOS HDFS configuration How to check CentOS HDFS configuration Apr 14, 2025 pm 07:21 PM

Complete Guide to Checking HDFS Configuration in CentOS Systems This article will guide you how to effectively check the configuration and running status of HDFS on CentOS systems. The following steps will help you fully understand the setup and operation of HDFS. Verify Hadoop environment variable: First, make sure the Hadoop environment variable is set correctly. In the terminal, execute the following command to verify that Hadoop is installed and configured correctly: hadoopversion Check HDFS configuration file: The core configuration file of HDFS is located in the /etc/hadoop/conf/ directory, where core-site.xml and hdfs-site.xml are crucial. use

What are the common misunderstandings in CentOS HDFS configuration? What are the common misunderstandings in CentOS HDFS configuration? Apr 14, 2025 pm 07:12 PM

Common problems and solutions for Hadoop Distributed File System (HDFS) configuration under CentOS When building a HadoopHDFS cluster on CentOS, some common misconfigurations may lead to performance degradation, data loss and even the cluster cannot start. This article summarizes these common problems and their solutions to help you avoid these pitfalls and ensure the stability and efficient operation of your HDFS cluster. Rack-aware configuration error: Problem: Rack-aware information is not configured correctly, resulting in uneven distribution of data block replicas and increasing network load. Solution: Double check the rack-aware configuration in the hdfs-site.xml file and use hdfsdfsadmin-printTopo

Centos configuration IP address Centos configuration IP address Apr 14, 2025 pm 09:06 PM

Steps to configure IP address in CentOS: View the current network configuration: ip addr Edit the network configuration file: sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0 Change IP address: Edit IPADDR= Line changes the subnet mask and gateway (optional): Edit NETMASK= and GATEWAY= Lines Restart the network service: sudo systemctl restart network verification IP address: ip addr

Centos install mysql Centos install mysql Apr 14, 2025 pm 08:09 PM

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

See all articles