Sentora Support Forums

Full Version: Document root in public dir
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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?
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
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.
Have a look into vhost overrides in the Apache Config section :-)
(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.
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>
(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...
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
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>