Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kimmer's avatar

Installing Laravel outside of the httpdocs folder

Hi there,

I’ve been researching how to install my first Laravel project on my Ubuntu 16.04 (plesk17) VPS. I’m reading that I should install Laravel in a folder outside of the httpdocs and move the public folder inside httpdocs. For security reasons.

Is this correct?

If this is correct I have a follow up question: I am also learning how to use GIT to pull updates to my production site. I can make it deploy to a folder outside of httpdocs but how do I keep the public folder up to date when when pulling updates when it is no longer in the same folder as the rest of my Laravel files?

Thanks!

0 likes
15 replies
Yamen's avatar

Here is your solution https://www.youtube.com/watch?v=hv4hwgQO9xI And for folders like css, js, images in public folder, you may make a symbolic link to it and don't forget to update the index.php file if this app is your root app or primary domain, otherwise you can make the whole public folder as symbolic link. Note: clone it from github as https not ssh so it doesn't prompt you the password after the webhook request, don't forget to manage .env file

Kimmer's avatar

Thanks for your reply @Yamen but I don't really understand your answer.

Are you saying I should install my Laravel app outside of the httpdocs folder?

Kimmer's avatar

Thanks!

With the help the the articles linked here and this one https://laravel-news.com/subfolder-install I managed to install my app in a subfolder.

It seems to work apart from the CSS and JS. The source and href paths start with a "/" so the js and css file are not found. I've been looking around on where to fix that but the only file where I can find the paths with a starting "/" is public/mix-manifest.json. Changing it there does not make a difference.

Any idea what I need to do to get the JS and CSS working?

DC Blog's avatar

You can adjust your path in your layout with url such as

url('css/style.css')

the url() will return the full URL.

1 like
jlrdw's avatar

No matter what guide is used, see this screenshot. This is how the folder structure is setup. https://drive.google.com/file/d/0B1_PFw--3o74WHNmMFlkRklKRTg/view

Notice main laravel is above public_html (htdocs or www).

I'd get it properly setup (structured) first, then look at the url and other helper functions. Otherwise you will have it working in development, but later in production things won't work. Have your dev and production setup the same.

And Hi Dave.

1 like
DC Blog's avatar

Hey Jim ;),

yes, the structure is important but it sounds like you've got that covered now.

Kimmer's avatar

Yes I have the structure now, but it is different then my development version. I think I'll manage to solve that. At the moment the differences are minimal so I'm focussing on getting everything to work on my production server first. This is mainly what I'm struggling with.

Your tip with url() did the trick. I just had to work out how to use that with Laravel Mix and versioning. My app is loading the CSS and JS files as it should. This is what the stylesheet link tag looks like.

<link rel="stylesheet" href="{{ url(mix('css/app.css')) }}">

However, my routes don't seem to work. Getting 404s. The url is fine. At the moment my app only has one link available for guests, a login via Socialite and Spotify. I'm going to create a testlink to a simple page and see if that works.

Kimmer's avatar

Strange, the testlink I created also does not work. Made a simple a tag like this

<a href="{{ url('/test') }}">test</a>

and this in my routes/web.php file.

Route::get('/test', function () {
    return view('welcome');
});

Works locally but not on my server.

jlrdw's avatar

I just tested

<a href="<?= url('admin/login'); ?>">tryme</a>

and it works. Sorry I don't use blade. Where admin/login is one of my routes. Try

<a href="{{ url('test') }}">test</a>

no leading slash.

Kimmer's avatar

I tried that but it doesn't make a difference. Works on my local dev version but not on the server. I also tried removing the leading slash from the routes but also no difference.

I don't think it's the blade template. It seems my routes file just doesn't do anything on the server.

Kimmer's avatar

The .htaccess files was missing in the public folder. Adding it fixed the test link. Logging is still doesn't work but I think I'm getting close.

This thread has gone way out of topic so if I have another question I will start a new topic.

Thanks for your help!

Please or to participate in this conversation.