Search code examples
apachelaravel.htaccessubuntu-server

Not able to access laravel routes in apache2 server


I've deployed a new laravel installation to my server, While doing so I configured my apache2 as following:

I added 000-default.conf file in /etc/apache2/sites-available/ as following:

DocumentRoot /var/www/html

 <Directory /var/www/html/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    Allow from all
    Require all granted
 </Directory>

I've my laravel installed into /var/www/html/stellar folder now I access my installation through:

http://52.39.175.55/stellar/public/

But while calling the routes it is not working, Like

http://52.39.175.55/stellar/public/oauth/token

Here is the screenshot:enter image description here

But suppose I call through this:

http://52.39.175.55/stellar/public/index.php/oauth/token

I get the access,

enter image description here

I tried changing my public/.htaccess file to something like this:

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On
RewriteBase /stellar

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

Still there is no change, Help me out in this.


Solution

  • Your VirtualHost on /etc/apache2/sites-available/ should look like this:

    <VirtualHost *:80>
        DocumentRoot "/var/www/html/stellar/public"
        ServerName yourdomain.com
        <Directory /var/www/html/stellar/public>
          AllowOverride All
        </Directory>
    </VirtualHost>
    

    Then restart apache2 and it should work.

    I hardly recommend you to duplicate the 000-default.conf file, rename it and include the VirtualHost, then enable it with a2ensite command, just because it's more easy to manage.