Solved how DocumentRoot change from 1 domain

Del S

Verified User
Joined
Jul 6, 2021
Messages
25
Hello

I bought a web script and I was able to install it via softaculous in DA, so that's not the problem but the problem is that it's in a different folder "domainname.com/public", how or where can I change that domain name. com/public is automatically sent to domainname.com ? According to the provider via documentroot, but the manuals are only for cpanel, I have full access to that server. in other words admin/user

thx
 
Last edited:
php css html
Configure your web server's document / web root to point to the public directory of the software. For example, if you've uploaded the software in example.com folder, your web directory should be changed to example.com/public folder.

You can find more info an how to change your site Document root over at:
 
Of is het beter dat ik het installeer op een subdomein en deze koppel aan het domein ?
 
Glad to here it works.
But it's bad programming if the server has to be adjusted to the sofware instead of the other way around which is normal. ;)
 
But it's bad programming if the server has to be adjusted to the sofware instead of the other way around which is normal.
Modern PHP frameworks have this and imo it's much safer this way. By changing the docroot for the domain to /public the only file accessible to the outside is /public/index.php instead of every file of the framework, like .env or config files / database migrations / other sensitive data. Never have all this public and use /public in the URL.:)

For example, Laravel: Nginx

Please ensure, like the configuration below, your web server directs all requests to your application's public/index.php file. You should never attempt to move the index.php file to your project's root, as serving the application from the project root will expose many sensitive configuration files to the public Internet:
 
like .env or config files
I still don't see it.

In the old days some scripts had an even better way to keep files save, which put them before the public_html. Even a github simple (but not that good) dating script uses it this way.
So for example a config.php could then be in the directory before the public_html /domains/domain.com/config.php/public_html/index.php so this kind of setup.
This way the important things can only be accessed via localhost called by the script. Seems a lot safer to me.

Changing a document root, changes in fact nothing except for the name. Name is different, not the permissions.
So if you change your document root from public_html to public then public (and all files in it) it's still the document root, an all files and directory's in it accessible same as with using the default docroot.
Which is the same I see from the cPanel and Plesk methods to change the document root.

I've read that nGinx Laravel quote, but that is project root, which is not the same as a document root. But I don't quite understand where the project root exactly is because that is not the /public directory because that contains the index.php. And the index.php should not be in the projects root directory it says there.
 
In the old days some scripts had an even better way to keep files save, which put them before the public_html.
That's also a way to do it while keep using the public_html folder. With WordPress I also move the wp-config.php file on directory up. (y)

But with how modern PHP apps are installed and managed with Composer, that's sometimes not the best way to do it anymore. With things installed and managed with Composer you can't just move files or directories around and the recommended way is to change the docroot for a domain.

So if you change your document root from public_html to public then public (and all files in it) it's still the document root, an all files and directory's in it accessible same as with using the default docroot.

Yes, but the difference is that you don't need /public in the URL to access the app. So when changing the docroot you can reach the app with myapp.dev instead of myapp.dev/public

I've read that nGinx Laravel quote, but that is project root, which is not the same as a document root. But I don't quite understand where the project root exactly is because that is not the /public directory because that contains the index.php.

Another example; I have Firefly III installed in /home/user/domains/mydomain.nl/firefly-iii and changed the Nginx docroot (with the |?DOCROOT= token) to /home/user/domains/mydomain.nl/firefly-iii/public. And the app is reachable by myapp.dev. So public_html isn't even used in this case. And everything in /home/user/domains/mydomain.nl/firefly-iii can't be reached to the outside.

And by reading the post by @Del S this is the same situation
 
Yes, but the difference is that you don't need /public in the URL to access the app. So when changing the docroot you can reach the app with myapp.dev instead of myapp.dev/public
So if it was coded/configured in public_html (with directory's before it) instead of public it would have the same effect.

Also with your example, I understand now that you put stuff in firefly-iii which can not be accessed by outside and probably if you have more projects, you don't need to put everything in your/mydomains.nl folder, but I still find in the world turned upside down. You do not change default server things to match up applications, I still don't think it's good practice.
If the app could point to some directory below, it would still be possible with the default docroot.

These custom things lead imho to complaints with hosters who don't run nGinx on don't want to turn their apache config upside down by creating various custom configs (like me).

I'm used to use standards like RFC's and defaults if possible. And it was always the case, that the applications can be adjusted to work on the server and not the basic server config to fit the applications.
Anyway, that's an opinion we probably won't agree about. I'm too old for this new stuff I guess. :)

If devs do it this way nowadays, well.... so be it then.

Thanks you for the extra explanation and examples.

@Del S Thank you that I was able to ask this in your thread. I only did it because it was already solved.
 
Last edited:
Back
Top