Home > Backend Development > PHP Problem > A brief analysis of how to install Apache modules to support PHP

A brief analysis of how to install Apache modules to support PHP

PHPz
Release: 2023-04-04 21:20:02
Original
1347 people have browsed it

When building a web server, Apache and PHP are two important components. As a web server software, Apache provides many powerful functions, such as supporting virtual hosts, reverse proxy, etc. As a server-side scripting language, PHP is used to process dynamic content of web applications. In order for Apache to support PHP code execution, you need to install the PHP module integrated with Apache.

In this article, we will introduce how to install Apache modules to support PHP.

1. Confirm the Apache version

Before installing the PHP module, you need to confirm the current Apache version. Enter the following command in the terminal:

httpd -v
Copy after login

If your Apache version number is 2.x.x, you can continue to the next step. Otherwise, you need to change the corresponding parameters of the installation command.

2. Install PHP and Apache modules

After completing the installation of the Apache server, you can start to install the integration module of PHP and Apache. Entering the following command will install the PHP Module and PHP Common package for Apache:

yum install php php-common
Copy after login

At the same time, you need to install the PHP extension and mod_php modules in the Epel warehouse:

yum install php-mysqlnd php-gd php-ldap php-xml php-mbstring php-pear mod_php
Copy after login

After completing the above steps, restart Apache Server:

service httpd restart
Copy after login
Copy after login
Copy after login

After the installation is complete, you can create a PHP file for testing:

nano /var/www/html/index.php

<?php
phpinfo();
?>
Copy after login

Save and exit the editor, reload Apache:

service httpd restart
Copy after login
Copy after login
Copy after login

Open the browser and visit localhost or server address, PHP module information can be seen on the welcome page.

3. Point the Apache configuration file to the PHP module

In order for the Apache server to use the newly installed PHP module, you need to find and edit the httpd.conf file:

nano /etc/httpd/conf/httpd.conf
Copy after login

Find the following Line:

DirectoryIndex index.html
Copy after login

Change it to:

DirectoryIndex index.php index.html
Copy after login

Save and exit the editor, reload Apache:

service httpd restart
Copy after login
Copy after login
Copy after login

Apache will now look for the index.php file by default so that Execute PHP code.

4. Conclusion

This article describes how to install the Apache module to support PHP. After installing the module, you can create and access a PHP file to verify that the installation was successful. Additionally, it details how to point the Apache configuration file to the newly installed PHP module.

Hope this article is helpful to you.

The above is the detailed content of A brief analysis of how to install Apache modules to support PHP. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template