Ask Your Question
3

What is the process to make Apache run .php files on Ubuntu outside the cgi-bin directory?

asked 2023-07-20 01:14:22 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-07-20 01:42:02 +0000

bukephalos gravatar image
  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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-20 01:14:22 +0000

Seen: 13 times

Last updated: Jul 20 '23