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

pdechery's avatar

Deploy, can't modify DocumentRoot on server, what now?

Hi, I have a Laravel app installed in a Apache 2.2.15 CentOS.

After hours of researching I've found that in order to serve my app from the '/public' folder I would have to change Apache configuration and so I did. I've changed the /etc/httpd/conf.d/vhosts.conf file as such:

VirtualDocumentRoot /vhosts/%0/html/public

And everything went fine! Until the server administrator tells me that I cannot change the document root.

So I've read dozens of posts that suggest creating separate folders, one for the application and other for the public folder, and later fix the links in public/index.php. Or use symlinks to link the 'html' folder (in my case the document root) with laravel's 'public' folder.

I need to say that I'm not in a shared hosting environment. It's a Linux machine I own almost completely.

So, what do you think it's the best solution in this case? Taking in account I update the site via Git so I need to maintain directory structure as equal as possible?

Btw, I've changed the document root back to 'html' and it seems that the public/.htaccess is broken. All routes except home return 404 and you have to put /public/index.php to see anything.

You can check it all here:

http://aws.rioaliancafrancesa.com.br/public

Thanks.

0 likes
11 replies
Snapey's avatar

I don't see why you should not be able to change the document root? What reason does the admin give?

Are you configuring a virtual host and are there many sites on this install?

pdechery's avatar

Hi Snapey,

He told me that it was for business reasons. All vhosts must have the html folder as DocumentRoot and if that's changed for a single project that would cause extra costs for my client (he manages the server for them). He mentioned backup routines.

It seems I will have to adapt myself to this situation. Like I've said, I've read many posts here teaching how to install Laravel in a shared hosting environment. Separating the public folder from the rest and all that.

I wish I could avoid this approach as it will mess up my updates with Git, let alone the extra work and possibility of new problems to arise.

Thanks.

Snapey's avatar

Not to mention that if its for some silly backup routines, then seriously... you could end up with most of your site not backed up.

Honestly, I would find a more professional host. Sounds like he is making you bend to make his life easier. Who is the customer here?

pdechery's avatar

@Snapey , my client is his customer. And for many years.

When we begin this project I've demanded him a server with all Laravel's requirements and he gave it to me. With SSH access, command line php and everything. I thought it was great until this problem arrived.

But, anyway, assuming I can't change the DocumentRoot path, but at the same time have a machine to use anyway I want, what do you think would be the best approach?

I was thinking about moving the files to a new folder and later create a symlink with the root directory and Laravel's public folder. At least I would maintain the directory structure.

Snapey's avatar

As you suggested originally, put everything into a release folder that is a sibling of html. Then delete the html folder and create a symlink from html to public.

Hope that makes sense.

/vhosts/sitename/release20160426  <--- all your project in here
/vhosts/sitename/html  <--- replace folder html with symlink html pointing to release20160426/public
$ cd /vhosts/sitename
$ rmdir html
$ ln -s release20160426/public html

or something like that! I'm no expert !

pdechery's avatar

Ok I'm not either! :-)

Just one question: do you think is really necessary to remove the html folder? And, more important, is it safe?

Snapey's avatar

your host says document root must be html so to create a symlink you need to first remove the folder.

safe from what perspective?

pdechery's avatar

Yes, I was just trying now without removing it first and learned that the hard way...

As for safeness It was just a silly idea I've had, nevermind. I thought that folder was 'special' somehow and should not be deleted.

Thank you, everything seems to be working online now.

EmilMoe's avatar

And that's why most developers require to demand the host being used or at least not let the customer choose it solely.

pdechery's avatar

@jlrdw, I've read your link and it seems nice. My only problem is the need of moving files accross directories, since it will turn the updates with Git a little more difficult...

I did the symlink approach and it's working. I think I'll stick with that for now, at least if there aren't any drawbacks... thanks.

Please or to participate in this conversation.