Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

500 Internal Server Error after changing AllowOverride to All in Ubuntu

My Project is working fine in Blue host shared hosting and as well in my XAMPP localhost.

For testing we moved the files to a local ubuntu server. But .htaccess not working in this ubuntu server.
Which means the files accesible with .php extention but 404 error when accesed without .php extention.

http://172.31.0.55/project/contact.php works, but
http://172.31.0.55/project/contact shows 404 error

This is the htaccess code I use.

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /project/

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/project/$1.php -f
RewriteRule ^(.+?)/?$ /project/$1.php [L]
Options All -Indexes
RewriteCond %{HTTP_REFERER} !^http://(www\.)?172.31.0.55/project/ [NC] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?172.31.0.55/project/.*$ [NC]


ErrorDocument 403 http://172.31.0.55/project/403-error
ErrorDocument 404 http://172.31.0.55/project/404-error


After some research I changed lines in /etc/apache2/apache2.conf

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride none
    Require all granted
</Directory>

to

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

But now its showing 500 Internal server error when tried to access http://172.31.0.55/project/

Server version is Apache/2.4.18 (Ubuntu) Its a PHP Website

I can see following codes in http://172.31.0.55/ Apache default page

The configuration layout for an Apache2 web server installation on Ubuntu systems is as follows:

/etc/apache2/
|-- apache2.conf
|       `--  ports.conf
|-- mods-enabled
|       |-- *.load
|       `-- *.conf
|-- conf-enabled
|       `-- *.conf
|-- sites-enabled
|       `-- *.conf

I tried changing from ip address to localhost in htaccess. But not working

I checked for File permission its rwx rwx r-x

I made these changes referring https://askubuntu.com/questions/421233/enabling-htaccess-file-to-rewrite-path-not-working

like image 651
Rakesh Avatar asked Oct 18 '22 11:10

Rakesh


1 Answers

By default, Apache prohibits using an .htaccess file to apply rewrite rules, so first you need to allow changes to the file. Open the default Apache configuration file using nano or your favorite text editor in this path /etc/apache2/sites-available/000-default.conf

$ sudo nano /etc/apache2/sites-available/000-default.conf

Inside that file, you will find a <VirtualHost *:80> block starting on the first line. Inside of that block, add the following new block so your configuration file looks like the following. Make sure that all blocks are properly indented.

<VirtualHost *:80>
<Directory /var/www/html>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>

. . .
</VirtualHost>

Save and close the file. To put these changes into effect, restart Apache.

$ sudo systemctl restart apache2

I followed these steps and my issue resolved.

like image 107
Rakesh Avatar answered Oct 20 '22 02:10

Rakesh