How to run PHP in Apache?
To run PHP on an Apache server, you need to install the PHP interpreter and configure Apache to support PHP. Here are some steps:
- Firstly, make sure that the PHP interpreter has been installed. You can check if PHP has been installed by using the following command:
php -v
- Install the PHP interpreter. You can install PHP using a package manager, for example, by executing the following command on Ubuntu:
sudo apt install php
- Enable the PHP module for Apache. You can enable the PHP module with the following command:
sudo a2enmod php
- Restart the Apache server to apply the configuration changes.
sudo systemctl restart apache2
Currently, Apache servers are able to interpret and execute PHP scripts. PHP files can be placed in the document root directory of the Apache server (usually /var/www/html/), and then accessed through a browser to view their output.