Using Plesk and vhost.conf
9th February 2006 - By Aaron
Wondering how to create a good vhost.conf? Well you’ve come to the right place.
Plesk automatically updates httpd.include for each domain, making changes to this file only temporary. You don’t want to use this file if you need to make changes to Apache’s config on the fly, such as php’s open_basedir values per domain.
Instead you will want to use a vhost.conf file. This file will be placed inside your domain’s conf directory, usually found at /var/www/vhosts/yourdomain.com/conf. Create a file called vhost.conf in whatever editor you prefer. I use joe.
You can now put in any Apache configuration options like you would into httpd.include. In my case I wanted to do three things, give my site access to /php/includes, add a mod_rewrite rule, and tell Apache to follow symlinks.
Here is my resulting vhost.conf file.
<Directory /var/www/vhosts/yourdomain.com/httpdocs/>
php_admin_value open_basedir "/var/www/vhosts/yourdomain.com/httpdocs:/php/includes"
</Directory>
Options +FollowSymLinks
RewriteEngine on
RewriteRule /ministries/(.*)\.php$ /ministries/ministry.php?url=$1
You can see the first three lines take care of the additional base directory for php, the line after the empty one takes care of following symlinks, and the last two lines turn on the rewrite engine and add a rule to it.
Save your file and we’re almost done. This is the part that everyone forgets, you need to tell Plesk to update it’s information. See your httpd.include file will soon have an include for your vhost.conf, but it doesn’t yet. Plesk has to realize it’s there and then add the include. The command to reconfigure Plesk for one site is /usr/local/psa/admin/sbin/websrvmng -u --vhost-name=domain.com or the command I use reconfigures all sites, /usr/local/psa/admin/bin/websrvmng -a.
After running that there is no need to restart Apache or any other service. Your changes should have taken effect already.
As always, feel free to comment if you have more suggestions or questions.
February 23rd, 2006 at 9:02 am
Hey there, havin a problem with symlinks. Have used plesk to setup physical hosting for a domain. deleted the httpdocs folder then recreated it as a symlink to a sub folder in domain2.
I then added Options +FollowSymLinks into vhost.conf on domain2 and ran the restart code. the symlink works when browsing ssh but when i visit domain 1 in a browser it gives a 403 forbidden error - you know what im doing wrong?
February 23rd, 2006 at 11:06 am
You probably need to edit your vhost.conf of the redirected domain to include the httpdocs of the first domain, such as
php_admin_value open_basedir "/var/www/vhosts/redirecteddomain.com/httpdocs:/var/www/vhosts/firstdomain.com/httpdocs"I did this same thing for a while. I would encourage you instead to just send a php header redirect with a “permenantly moved” header. The search engines will drop your second site off the listings either way. They don’t play friendly with mirrors.
May 3rd, 2006 at 2:39 pm
I have a syntax question. If there’s many directories for which I want to lift the open_basedir restriction, what is the syntax to allow me to ‘force word-wrap?’ that is, my colon-separated directories, how could I put them on separate lines?
php_admin_value open_basedir “/var/www/vhosts/yourdomain.com/httpdocs:/php/includes”
Thanks!
November 8th, 2006 at 4:00 am
Thanks for this post - it really helped me getting open_basedir sorted.
- Hugo
December 8th, 2006 at 5:07 am
Another big thanks - I’d got my vhost.conf file set up to allow my site to access pear, I just couldn’t work out how to get apache to read it without editing the httpd.include file that Plesk (over-)writes for you…
It works now, yippee!
Rebecca
January 5th, 2007 at 9:25 am
I am having trouble with creating my vhost.conf file. so far every time i have tried, it crashed my httpd service. My goal is to enable “register long arrays”. Can you help please?
June 2nd, 2007 at 4:50 am
Hello,
I want to put my website files outside of the usual plesk directory in a separate drive, how do I do that? Is it possible using vhost.conf?
June 8th, 2007 at 11:57 am
If you need to add more directories try this:
php_admin_value open_basedir “**Directory 1**:**Directory 2**”
June 13th, 2007 at 8:58 am
isnt it possible to create a file that goes for all vhosts?
I want to add a open_basedir to all my vhosts…
July 14th, 2007 at 11:39 pm
Another big thanks - I’d got my vhost.conf file set up to allow my site to access pear, I just couldn’t work out how to get apache to read it without editing the httpd.include file that Plesk (over-)writes for you…
It works now, yippee!
Rebecca
August 8th, 2007 at 11:36 am
If I wanted to have open_basedir for a folder outside of httpdocs would this work:
php_admin_value open_basedir “/var/www/vhosts/DOMAIN.COM/foldername”
September 30th, 2007 at 11:56 am
Used this method to relax open_basedir restrictions, was editing the httpd.include file before, found this method much more efficient. Thank you!
October 1st, 2007 at 12:42 pm
As a side note you can use vhost_ssl.conf to set the https settings for your site.
November 8th, 2007 at 9:12 am
Thank you so much,
i have a cms on one domain to manage content on several other domains and the second post solved all my problems :)
November 26th, 2007 at 8:53 pm
I followed your recipe for configuring my site by editing the vhost.conf file and then doing /usr/local/psa/admin/sbin/websrvmng -u –vhost-name=domain.com
However the next time I tried to restart the server using the Plesk panel I got a message “Internal Plesk error occurred: Unable to make action: Unable to manage service by websrvmng: websrvmng: Service /etc/init.d/apache2 failed to restart”. To get the server to start again I have to remove the Include line from the httpd.include file.
Can you see what I am doing wrong?
December 11th, 2007 at 11:55 am
Hi all!
I would like ALL domains on my server to only access their own httpdocs folder.
I would like not to edit every domain vhost.conf individually
I would like this to be by default for all newly created domains
I know we can set open_basedir in php.ini
can anyone help with the syntax?
something like: Open_basedir = “/var/www/vhosts//httpdocs/”
thanks all!
–
Thierry
December 19th, 2007 at 2:24 pm
Thanks a lot for this info about vhosts, it was bugging me for quite a while!
I am trying to enable directory indexing for a folder on my site, but no matter what directives i put in the vhost.conf file i either get an apache configuration error (like David’s post above, except i just check the configuration errors with
/etc/init.d/httpd configtestand then comment out the erroneous ones), or the folder keeps on telling me ‘Forbidden - You don’t have permission to access /folder/ on this server.’
I know the vhost.conf file is being read, that’s why i get configuration errors. I’ve even double-checked the http.include file.
What should i do to resolve this?
February 8th, 2008 at 8:58 am
I know this is an older post, but I found it very helpful - so thank you. A lot of people are afraid to use the command line, but you’ve made this simple (a lot simpler than Plesk’s docs, for sure!).
March 20th, 2008 at 10:20 am
Well Plesk I found this on the Plesk site blog:
‘Limited customization – It’s very hard to efficiently implement per-tenant database schema customization in a single database, and it’s not possible to use standard DBMS tools – like built-in indexing. Plus, the multi-tenant application cannot use script-based customization of the internal logic – what if a buggy script loops infinitely?
SmoothSpan Bob Warfield and Unreasonable Men argued that customization capabilities are often excessive and there is little harm in removing much of that flexibility. For newly written applications, it might even be true. But if an ISV has a customer base to migrate to SaaS model, telling customers that their solutions will be broken because some of the customizations don’t work anymore is hardly an option.’
Apparently Plesk is not heading their own blog…LOL because we all are doing nothing but loosing functionality and the ability to see what is going on, on our sites.
I’m paying an extra 10 bucks a month for this Plesk thing which basically has reduced my site to nothing, I’m flying blind and everytime it reloads the httpd.include file is over written which would be fine if it would actually use vhost.conf but it does not.
1. AwStats which is just as important as Apache does not function at all.
2. Customizable httpd.include per domain does not work with
vhost.conf and since Plesk is an unsecured script, (because it must run with open base directory on), we have lost HUGE functionality. You do not see this problem with or like this in Cpanel at ALL!
In the past 10 years I have had only 2 problems with Cpanel both related to the file manager and editor, very minor and were fixed in the next version. When I say fixed I don’t mean they said it was fixed and it wasn’t, it means it was fixed and has worked perfectly ever since.
I guess Plesk is like windows 3.1 and Cpanel is like linux
Now if you think I’m a little more than perturbed with Plesk you’d be correct. However, I have spent the last three weeks messing around with Plesk because it doesn’t work rather than having my attention on my business and customers where it belongs. DO YOU understand that? Can you comprehend the ramifications of placing UNTESTED, UVALIDATED and weak performing code on a server and claiming it to be a management utility?
I’m running a business, not a hobby and [B]I am spending more time and money trouble shooting Plesk code than I am running my business. [/B]
I can not recommend anyone use, buy or rent any server with Plesk installed it is a total nightmare where is Cpanel maybe clunky but it works hands down.
April 28th, 2008 at 3:01 am
This hint still applies and works successfully in Plesk 8.3, I’ve been manually modifying the include files and having to re-apply a patch to them anytime a user changed their sites. This was becoming rather annoying to manage, this vhost trick is awesome. I knew there had to be a way, I’m glad a google search brought me here.
And I don’t know what the big deal with people not being able to use Plesk like the last comment, I’ve had no problems with it and hosting a wide variety of PHP sites and open source projects with no problems for numerous clients. Some even programmed back in the PHP 3 days still work great in PHP5 via Plesk.
Again, thanks for this quick tutorial, works great!
Plesk 8.3 - OpenSuSE 10.2 Linux
- I
May 4th, 2008 at 10:59 pm
[...] I don’t know what you guys are using but this article might shed some light on this problem: Aaron Gadberry Blog Archive Using Plesk and vhost.conf This problem basically involves PHP’s open_basedir setting. Change your index.php file and try to [...]
May 5th, 2008 at 1:28 pm
I agree with Insolence in post #20. I’m using Plesk 8.3, too, and absolutely love it. I haven’t had a single problem that I couldn’t troubleshoot, and it makes managing dozens of busy sites a far simpler task.
HOWEVER (and this is a big however), I have 5-6 years of production-level “webmastering” under my belt. I could see how this would all seem very difficult and frustrating to the “average user”. Those who dislike Plesk probably didn’t read the manual or scour their web hosts’ knowledge bases, which often contain useful information relative to how Plesk is set-up on their specific servers.
One thing that I’ll mention AGAIN (the author attempts to make this point but it appears that many have ignored him anyway): don’t forget to tell Plesk to update its httpd.include file by issuing the following command in your shell of choice:
$ /usr/local/psa/admin/bin/websrvmng -a
May 11th, 2008 at 8:15 pm
Seems like a lot of knowledgable people on here. This is exactly what I need except I am using plesk on windows and for whatever reason there is no conf file under the vhost/domainname/ directory. Does anyone know how to do this on a windows server? Its driving me crazy and it would be a lifesaver.
August 13th, 2008 at 9:53 am
[...] of the sites are fully live versions So in order to get around this you need to put a file called vhosts.conf in your conf directory, for example, [...]
August 26th, 2008 at 2:09 am
I am trying to make a Documentroot param in de Vhost,conf but the i have a error that doesnt parse my PHP files ..? why does it do that when i change documentroot ?
September 11th, 2008 at 8:39 am
I have some subdomains configured in plesk, and everything is working just fine.
Now I need to redirect people that access to any other subdomain (except the ones configured in plesk) to a different default directory.
For example http://xpto.mydomain.com to “/var/www/vhosts/mydomain.com/httpdocs/default”.
I’ve tried to create a wildcard, with the code listed bellow, but it only works if I paste it to the end of “http.include”, which is discarded after any other plesk change.
If I use the “vhost.conf” as suggested here, I get errors, because the include line at “http.include” is inside the first and lead me to problems with the others subdomains.
Is there any other way to do this ? Am I doing something wrong ?
September 29th, 2008 at 4:30 pm
[...] 29, 2008 “/usr/local/psa/admin/sbin/websrvmng -u –vhost-name=domain.com”gadberry.com Posted in vps [...]
November 1st, 2008 at 5:24 am
Really good this help me to make Joomla work with Pelsk … (and other helps), is the best mention of specific vconf in Plesk