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
I think you should not put ‘/public’ at Directory tag.
Try this:
`
<VirtualHost *:80>
DocumentRoot /var/www/html/lavarel-project1/public
`
This is my configuration and works fine.