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
#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
#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
#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
#5
RE: Document root in public dir
Have a look into vhost overrides in the Apache Config section :-)
Reply
#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
#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
#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
#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
#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


Possibly Related Threads…
Thread Author Replies Views Last Post
root limits sentora thanhlan2103 0 3 ,741 11-02-2018, 06:11 PM
Last Post: thanhlan2103
sentora root limits mohamadcom 4 12 ,692 01-25-2018, 08:21 AM
Last Post: TGates
ROOT Login CMs222 6 16 ,649 01-25-2018, 07:50 AM
Last Post: TGates

Forum Jump:


Users browsing this thread: 1 Guest(s)