To enable PHP in Apache, you need to perform the following steps:
-
Install the PHP module:
- On a Windows machine, you can download and install the PHP module from the official website.
- On a Linux machine, you can use the package manager to install PHP. For example, on a Debian-based system, you can use the following command:
sudo apt-get install php libapache2-mod-php
-
Configure Apache to use PHP:
- Open the Apache configuration file, typically located at
/etc/httpd/conf/httpd.conf
orC:\Program Files (x86)\Apache Group\Apache2\conf\httpd.conf
- Add the following line to the configuration file:
AddType application/x-httpd-php .php
- Save and close the configuration file.
- Open the Apache configuration file, typically located at
-
Restart Apache:
- On a Linux machine, use the following command:
sudo service apache2 restart
- On a Windows machine, use the following command:
net stop Apache2.2 && net start Apache2.2
- On a Linux machine, use the following command:
After completing these steps, you should be able to run PHP scripts in Apache. To test that PHP is working correctly, create a new file with the .php
extension and add the following code to it:
<?php phpinfo(); ?>
Save the file and place it in your Apache document root directory. Then, access the file in your web browser. If PHP is working correctly, you should see a page displaying information about your PHP installation.