Michael
Michael

Reputation: 4400

How to run laravel in root directory without the public folder?

I am running the latest version of laravel on my own server running Debian and Apache2.

The contents of laravel are located in /var/www which is what my domain name is pointed to however all of the functionality happens through the public directory so I would have to go to http://mydomain.com/public to access anything.

I would like to change it so that I only have to access http://mydomain.com. Is this possible?

How can I change this? Would I have to move everything up another level to the parent at /var?

I haven't found anything online so far that says that it is possible, or that it is a good idea.

Upvotes: 2

Views: 3863

Answers (5)

Pascal Tovohery
Pascal Tovohery

Reputation: 986

Locate your httpd.conf and change the part that DocumentRoot "/var/www" to "/var/www/public" and override directory to allow .htaccess file of laravel

...
DocumentRoot "/var/www/public"
...
<Directory "/var/www/public">
   AllowOverride None
   Options None
   Order allow,deny
   Allow from all
</Directory>

...

Upvotes: 0

Imad Ullah
Imad Ullah

Reputation: 1238

Add a file in laravel root directory, name it as .htaccess and put this inside,

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

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]

RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php

It will be fixed surely.

Upvotes: 3

pankaj
pankaj

Reputation: 1914

Sorry I deleted my old answer .. that was if u rename server.php to index then it will work but of course not because laarvel not load all service. so you have to paste into root all public folder file. and remove "../" from everywhere in index.php

Upvotes: 0

Bryan T
Bryan T

Reputation: 36

The following worked for me, as discussed here: https://stackoverflow.com/a/16569078/3091980

Move all contents of the /public folder down a level. Then update the include lines in index.php to point to the correct location - if it's down a level, remove the "../".

Upvotes: 1

wesside
wesside

Reputation: 5740

That is not your problem, you need to point the virtual host to the public folder.

Upvotes: 5

Related Questions