galaners's avatar

Change default "/public" to "public_html" in production

I'm putting my Laravel project in production and I've clone it from GitHub to: "/home/myuser/repositories/myuser/MYPROJECT-app", and my public Laravel folder content in "/home/myuser/public_html".

I've changed the "(project location)/app/Providers/AppServiceProvider.php" and add:

$this->app->bind('path.public',function(){
   return '/home/myuser/public_html';
});

To the Register function. I changed the "index.php" from the public folder to match my project location and everything works well, except when I try to upload a file using the method:

Storage::disk('public')->put('myfiles/', $request->myFile)

It is stored in "/home/myuser/repositories/MYPROJECT-app/public/storage/myfiles" instead of "/home/myuser/public_html/storage/myfiles".

(Note: I cannot use symbolic links because some restrictions with the server configuration, so I'm trying to store all the files within a "storage" folder within the public path).

I'm guessing I'm missing some configuration to tell Laravel to store the uploaded files in "/public_html/storage" instead of "MYPROJECT/public/storage", but I can't find wich file I've to change.

0 likes
5 replies
jlrdw's avatar

By having main laravel above public_html and point to public_html as document root. In other words you still point to public as document root, but public can be renamed to something else. So you are using new name.

Search for an answer by @snapey as he has given an explanation of this setup.

Snapey's avatar

why not change your code to store files in the public folder instead of storage

You have gone against best practices already so why not?

just check your .env is not directly accessible

Seriously though, no symlinks? Time to look for a new host

1 like
galaners's avatar

@Snapey There are quite serious security flaws that I have reported to the person responsible for contracting the service. Unfortunately, I have to work with what I have until they figure out what's going on. I'm trying to avoid changing my code, because I'm hoping that sooner or later I'll be allowed to create symlinks, so I'd like to try temporarily modifying the paths to allow me to store the information in the public Storage folder.

jlrdw's avatar

@galaners unless these are secured user images, public is fine to store images. In other words are they images that anyone can see or private.

Putting them in storage does not make them private anyway in such a case you need to put images outside of web all together.

But I do not know your setup.

Randy_Johnson's avatar

Whats the name of the service you are using?

Can you not just use the command storage:link and then drag and drop the folder into the public_html, keeping the symlink.

Please or to participate in this conversation.