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
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
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
After completing the above steps, restart Apache Server:
service httpd restart
After the installation is complete, you can create a PHP file for testing:
nano /var/www/html/index.php <?php phpinfo(); ?>
Save and exit the editor, reload Apache:
service httpd restart
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
Find the following Line:
DirectoryIndex index.html
Change it to:
DirectoryIndex index.php index.html
Save and exit the editor, reload Apache:
service httpd restart
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!