skip to Main Content

Created my first Laravel App (Using Lavarel 7.x) on Ubuntu 18.04LTS with Apache2 on a local PC I have.

Followed setup intstruction from Lavarel Docs, all went well.
One issue is with the url:

http://localhost/lavarel-project1/ - returns the directory listing

The apache2 virtual host file looks like this:

<VirtualHost *:80>
   DocumentRoot /var/www/html/lavarel-project1/public

   <Directory /var/www/html/lavarel-project1/public>
       AllowOverride All
       Require all granted
   </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

From researching on the web – articles stated to copy server.php file from Lavarel App root directory and rename it index.php.
This worked but then created routes in the app, found other issues with the url:

http://localhost/lavarel-project1/ - works
http://localhost/lavarel-project1/catlog/ - doesn't work
http://localhost/lavarel-project1/public/index.php/catlog - works

Here is the content of the .htaccess file in the public folder:

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

  RewriteEngine On

  # Handle Authorization Header
  RewriteCond %{HTTP:Authorization} .
  RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

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

  # Send Requests To Front Controller...
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [L]
</IfModule>

Researched this issue on the web – how to go about removing public/index.php from the url, but with little success – all methods recommended don’t work, hence asking the question on here.

thanks in advance.

2

Answers


  1. I think you should not put ‘/public’ at Directory tag.

    Try this:

    `
    <VirtualHost *:80>
    DocumentRoot /var/www/html/lavarel-project1/public

    <Directory /var/www/html/lavarel-project1>
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    

    `

    This is my configuration and works fine.

    Login or Signup to reply.
  2.  <VirtualHost *:80>
    
     ServerName laravel.dev
     ServerAlias www.laravel.dev
     DocumentRoot /var/www/html/lavarel-project1/public
     
        <Directory /var/www/html/lavarel-project1/public/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
            Require all granted
        </Directory>
     
    LogLevel debug
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search