What are the steps for configuring Apache in PHP?
When setting up an Apache server to run PHP scripts, the following steps need to be followed:
- Installing Apache Server and PHP: Initially, it is necessary to install both the Apache Server and PHP interpreter. This can be done either through a software package manager or by downloading and installing both software from the official website.
- Enable PHP module: Activate the PHP module in the Apache server configuration file. You can add the following line in the httpd.conf file.
LoadModule php_module modules/libphp.so
AddHandler php-script .php
- Specify the path of the PHP interpreter in the Apache configuration file. This can be done by setting it as follows:
<IfModule php_module>
PHPIniDir "path_to_php_ini_file"
</IfModule>
- Set up a virtual host: To run PHP scripts in a virtual host, you can add the following lines to the Apache virtual host configuration file.
<IfModule php_module>
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
</IfModule>
- Restart Apache server: After completing the above configurations, it is necessary to restart the Apache server in order for the changes to take effect. You can use the following command to restart the Apache server:
sudo systemctl restart apache2
After completing the above steps, the Apache server will be able to interpret and run PHP scripts properly.