Home  >  Article  >  Backend Development  >  How to start using yum to install php

How to start using yum to install php

PHPz
PHPzOriginal
2023-04-23 10:09:28838browse

It is very convenient to use yum to install PHP in CentOS or RHEL Linux system. However, just installing PHP is not enough, you also need to initiate a connection to the web server to be able to process PHP scripts.

The following are the steps to initiate a connection with the web server after installing PHP on yum:

Step 1: Install PHP

Use the following command to use yum on CentOS or RHEL Linux system Install PHP:

sudo yum install php

Step 2: Install the connection to the web server

In order to initiate the connection to the web server, you need to install the PHP adapter. The Apache web server is the most commonly used web server, so this article will show you how to install a PHP adapter to connect to Apache. On CentOS or RHEL systems, you can install php-mysql using the following command:

sudo yum install php-mysql

If you are not sure which adapter should be installed, you can run the following command to list all available adapters:

sudo yum search php-

This will list all available PHP adapters, including connections to MySQL, PostgreSQL, Oracle, etc.

Step 3: Set up the Apache Web Server

Now you need to configure the Apache web server in order to connect the PHP interpreter with the web server. Using the following command will open Apache's configuration file:

sudo nano /etc/httpd/conf/httpd.conf

Please note that you can use any text editor to open this file. Just open it as root user with sudo permissions.

Now, you need to find the following line of code:

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

This is Apache’s default index file list. Change this to the following to alter the default index file list:

<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

This will cause Apache to look for index.php first and run it.

After saving and closing the file, restart Apache:

sudo systemctl restart httpd

Step 4: Test PHP

Now you can test whether your PHP is connecting with Apache. Create a new file called info.php:

sudo nano /var/www/html/info.php

Add the following lines to the file:

<?php
phpinfo();
?>

After saving and closing the file, use your web browser to access the following URL: http ://yourserverIPaddress/info.php

You will see a page showing detailed information about your PHP environment. This indicates that your PHP is connecting to the Apache web server and processing PHP scripts correctly.

Summary

It is very convenient to use yum to install PHP on CentOS or RHEL Linux system. In order to initiate a connection to the web server, you need to install the PHP adapter and configure the Apache web server to use the PHP interpreter. After completing these steps, you can test that your PHP is working properly and make sure it is successfully connected to the web server.

The above is the detailed content of How to start using yum to install php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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