CentOS 7 is a common Linux operating system that is very suitable for use on servers. PHP is a widely used scripting language, especially suitable for web development. Installing the PHP environment on CentOS 7 is a very basic and important task. This article will introduce how to install the PHP environment on CentOS 7.
Prerequisites for installing PHP
Before installing the PHP environment, we need to ensure that the necessary software has been installed according to the following steps:
Installing PHP environment
Before installing the PHP environment, we need to use root Users update their systems to the latest version to ensure that software packages are up to date. We can update the software package using the following command:
yum update -y
After the update is completed, we can start installing the PHP environment:
yum install -y php php-mysql
This command will install PHP and PHP extensions related to MySQL. Note that here we use the -y parameter, which will automatically ask for confirmation when installing the package.
PHP Configuration
When the installation is complete, we need to configure PHP in Apache. Here we need to edit the Apache configuration file. You can use the following command:
vi /etc/httpd/conf/httpd.conf
Find the following code:
<IfModule dir_module> DirectoryIndex index.html </IfModule>
Here Add the following content below the code snippet:
DirectoryIndex index.php index.html AddType application/x-httpd-php .php
Then, enable the php module in the Apache web server:
systemctl start httpd
systemctl enable httpd
After the installation is complete, We can verify that PHP is installed correctly using the following command:
php -v
This will display the version information of PHP. If PHP is installed correctly, you should see output similar to the following:
PHP 7.0.33 (cli) (built: Jul 3 2019 11:53:17) (NTS)
Copyright (c) 1997 -2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
We can now place some PHP files on the web server in order to test whether PHP is working properly. Create a test php file on the server, name it info.php, and enter the following code:
phpinfo();
Save the file and upload it to the web server root Directory, such as /var/www/html/. This file can then be accessed on a browser at the URL http://
Conclusion
Installing the PHP environment on CentOS 7 is not complicated, just follow the above steps. You need to pay attention to some details during the installation process, such as using the root account and adding necessary code to the Apache configuration file. Once the installation is complete, you can verify that PHP is working properly by creating a test file.
The above is the detailed content of How to install php environment in coentos7. For more information, please follow other related articles on the PHP Chinese website!