Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
  1. Install the Apache web server:
sudo apt-get update
sudo apt-get install apache2
  1. Install PHP:
sudo apt-get install php
  1. Modify the Apache configuration files to handle PHP files outside the cgi-bin directory:
sudo nano /etc/apache2/mods-enabled/dir.conf

Change the DirectoryIndex line to include index.php:

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
  1. Configure Apache to handle PHP files using mod_php:
sudo nano /etc/apache2/mods-enabled/php7.2.conf

Change the following lines to allow PHP files to be executed outside the cgi-bin directory:

<FilesMatch ".+\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>

<Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>
  1. Restart Apache to apply the changes:
sudo systemctl restart apache2

Now, Apache should be able to handle PHP files outside the cgi-bin directory.