How to connect PHP with Apache?

To connect Apache and PHP, make sure the PHP module is installed on the Apache server. Then, you can follow these steps:

  1. Enable the PHP module in the Apache configuration file. In the httpd.conf file, locate the following line and make sure it is uncommented (remove the “#” at the beginning of the line):
LoadModule php7_module modules/libphp7.so
  1. Restart the Apache server to apply the configuration changes.
sudo systemctl restart apache2
  1. Create a simple PHP file to test the connection. Create a file named index.php in the document root of Apache (usually /var/www/html) and add the following content:
<?php
phpinfo();
?>
  1. When you enter the server’s IP address or domain name in the browser, such as http://localhost/index.php, you should be able to see a PHP info page, indicating that Apache has successfully connected to PHP.

By following the above steps, you can easily connect Apache with PHP and start using PHP scripts on your website.

bannerAds