This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Document root in public dir
#1
Document root in public dir
I am using a framework that has a public directory with the index file and the app dir is in the parent directory.

Sentora always points the domains to a folder in the root public_html directory and I can't point it to any sub directory. I have changed DocumentRoot and Directory directly in the httpd-vhosts.conf file but after restarting the server it reverted to the original.

I also know there is an apache conf override in Sentora but I don't know how to use it, anyone?
Reply
Thanks given by:
#2
RE: Document root in public dir
I would recommend putting a .htaccess file with a rewrite rule inside.

Which framework are you using and where is the front controller file (normally index.php) located?
Reply
Thanks given by:
#3
RE: Document root in public dir
For example for Zend Framework 1 i used the following:

/var/zpanel/hostdata/username/public_html/panel.domain.com/.htaccess

Code:
       RewriteEngine on
       ## If your framework is in a subfolder add the folder to RewriteBase
       RewriteBase /
       RewriteRule ^(.*)$ ./public/$1 [L]

This should redirect all traffic hitting panel.domain.com into the public directory with the correct parameters in the url remaining in place.


/var/zpanel/hostdata/username/public_html/panel.domain.com/public/.htaccess

Code:
       RewriteEngine On
       RewriteCond %{REQUEST_FILENAME} -s [OR]
       RewriteCond %{REQUEST_FILENAME} -l [OR]
       RewriteCond %{REQUEST_FILENAME} -d
       RewriteRule ^.*$ - [NC,L]
       RewriteRule ^.*$ index.php [NC,L]

This should then route requests not matching an image / css / js / file to the index.php inside /public for the framework to handle.

Hope this helps Smile
Reply
Thanks given by: Swift-R
#4
RE: Document root in public dir
That dit it. But I don't really like that solution.

I would rather have DocumentRoot altered in the httpd-vhosts.conf but it is reverted to the original every time I restart the server.
Reply
Thanks given by:
#5
RE: Document root in public dir
Have a look into vhost overrides in the Apache Config section :-)
Reply
Thanks given by:
#6
RE: Document root in public dir
(08-05-2015, 10:04 PM)kandrews Wrote: Have a look into vhost overrides in the Apache Config section :-)

I did, but as I mention in the first post, I don't know how to use it for this situation. I need an example.
Reply
Thanks given by:
#7
RE: Document root in public dir
Ah ok well something like this might work:

Module Admin -> Apache Config -> Override Vhost -> Custom Entry

Code:
   <Directory "/var/zpanel/hostdata/username/public_html/panel.domain.com/">
       RewriteEngine on
       RewriteBase /
       RewriteRule ^(.*)$ ./public/$1 [L]

   </Directory>

   <Directory "/var/zpanel/hostdata/username/public_html/panel.domain.com/public/">
       RewriteEngine On
       RewriteCond %{REQUEST_FILENAME} -s [OR]
       RewriteCond %{REQUEST_FILENAME} -l [OR]
       RewriteCond %{REQUEST_FILENAME} -d
       RewriteRule ^.*$ - [NC,L]
       RewriteRule ^.*$ index.php [NC,L]
   </Directory>
Reply
Thanks given by: Swift-R
#8
RE: Document root in public dir
(08-05-2015, 10:30 PM)kandrews Wrote: Ah ok well something like this might work:

Module Admin -> Apache Config -> Override Vhost -> Custom Entry

Code:
   <Directory "/var/zpanel/hostdata/username/public_html/panel.domain.com/">
       RewriteEngine on
       RewriteBase /
       RewriteRule ^(.*)$ ./public/$1 [L]

   </Directory>

   <Directory "/var/zpanel/hostdata/username/public_html/panel.domain.com/public/">
       RewriteEngine On
       RewriteCond %{REQUEST_FILENAME} -s [OR]
       RewriteCond %{REQUEST_FILENAME} -l [OR]
       RewriteCond %{REQUEST_FILENAME} -d
       RewriteRule ^.*$ - [NC,L]
       RewriteRule ^.*$ index.php [NC,L]
   </Directory>

That worked flawlessly, thank you!

Edit: Just had to remove the ending slash on the directory.

One more thing, do you think it is possible to override the default DocumentRoot? Instead of redirecting...
Reply
Thanks given by:
#9
RE: Document root in public dir
As the custom entry section is written into the apache vhost after the inital DocumentRoot statement i'm not sure without testing. Depends on if apache would read the second statement and use it in place of the first one....

Try putting the DocumentRoot statement inside the custom entry section and see if it loads...

Edit -> no problem glad that worked for you Smile
Reply
Thanks given by: Swift-R
#10
RE: Document root in public dir
That worked. I have tried it before but it didn't work at the time, no idea why.

Code:
DocumentRoot "/srv/web/mnunes/public_html/cloudlog/public"

<Directory "/srv/web/mnunes/public_html/cloudlog/public">
 Options +FollowSymLinks -Indexes
 AllowOverride All
 Require all granted
</Directory>
Reply
Thanks given by:


Possibly Related Threads…
Thread Author Replies Views Last Post
root limits sentora thanhlan2103 0 3 ,248 11-02-2018, 06:11 PM
Last Post: thanhlan2103
sentora root limits mohamadcom 4 10 ,956 01-25-2018, 08:21 AM
Last Post: TGates
ROOT Login CMs222 6 13 ,688 01-25-2018, 07:50 AM
Last Post: TGates

Forum Jump:


Users browsing this thread: 1 Guest(s)