Using Plesk and vhost.conf
9th February 2006 - By Aaron Gadberry
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 configtest
and 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
January 12th, 2009 at 11:43 am
Thanks for the help, this worked beautifully, trouble was that the httpd reload didn’t take the changes for me, but the websrvmng call did the trick (bowing) many thanks.
February 25th, 2009 at 7:14 pm
Just wanted to say that I was following along after migrating from one Plesk enabled host to another, using the built in Migration tool, when I couldn’t get my sites to run at all on the new host.
In the old host, I had exactly the same vhost.conf file, so I was perplexed.
In my troubleshooting, I determined that safe_mode and open_basedir are tied together.
You can’t have open_basedir specified, if safe_mode is on. You have to turn off safe_mode.
The example above:
php_admin_value open_basedir “/var/www/vhosts/yourdomain.com/httpdocs:/php/includes”
Only works if safe_mode is disabled in the php.ini file.
So, if under normal circumstances, you have safe_mode on, then you’d do this:
php_admin_flag safe_mode 0
php_admin_value open_basedir “/var/www/vhosts/yourdomain.com/httpdocs:/php/includes”
Peace!
February 27th, 2009 at 3:02 am
It works! Thanks!
“This is the part that everyone forgets”… Well, perhaps people would not forget it if it was mentioned in the httpd.include file. ;)
October 29th, 2009 at 12:29 pm
You dont believe how much this “This is the part that everyone forgets”… thing helped me.
I try since one year lots of things cause the vhost.conf did not worked.. hahaha
Thanks thanks thanks
November 9th, 2009 at 9:04 pm
Too true. It’s a bit all over the place, the Plesk documentation and help, isn’t it.
November 20th, 2009 at 9:41 pm
Hi.
I’m trying to use vhost to have all my .htacces rules there. the Include in the httpd.include file on my conf directory is there and nothing happends.
this is the vhost file i’m using to test.
php_admin_value open_basedir “/var/www/vhosts/contenido.lapulga.com.do/httpdocs”
#php_admin_value display_errors = on
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^celulares.html$ index.php?op=cat&cid=4
all the time i get 404 not found when i try to access mydomain.com/celulares.html
any help?
the server is using red hat with plesk 8.6
thanks
April 19th, 2010 at 10:49 am
I know this is a really old topic, but I’m having a problem when adding a section in the vhost.conf. Everything is working, but when I add this content (which is the only content I’m adding to that file), I get this error:
cannot occur within section
It makes no sense and I can’t restart my Apache service. However, if I take both and tags out of the file, everything is fine and dandy, except that my main domain snubee.com doesn’t work. The subdomains however do work!
Any ideas?
June 6th, 2010 at 1:41 am
Agrh…. again plesk – always in trouble ! :)
August 15th, 2010 at 7:24 am
Thanks, you helped me understand plesk better..
September 30th, 2010 at 5:13 pm
Hi!I am having windows hosting in plesk environment.I am trying to redirect my blog from non www to www. few days back I have tried one script in index.php and it was managing it nicely but recently due to plugins my site had lots of problems and now this redirect stopped working.somefiles are over written and hence cannot redirect the non www to www.
kindly help me in this regard.
thanks in advance
December 7th, 2010 at 10:07 pm
Thanks! Saved me 30 mins of troubleshooting :)
January 26th, 2011 at 4:25 am
Thank you much !!
This configuration helped me a lot!
May 23rd, 2011 at 8:19 am
I know this is an old topic but still valid. I tried creating subdomains to use a shared cert. Example mycart.com (port 80) = mycart.securecheckout.com (port 443). Using the vhost.conf would not work for this. What I had to do was remove the subdomain and add the virtual domain to the httpd.conf this looks similar to what Carlos had above but 443 instead. Point the Document Root to the path of the site you want to use the shared ssl cert on.
August 29th, 2011 at 10:25 pm
I know this an old topic but I think this will help a few people like my self who struggled to figure out how to add more domains/aliases to point to the same website. I found my self looking everywhere for a solution but couldn’t find anything solid and had to get bits and pieces of info to finally figure it out. So here it is step by step for you:
How to point additional domains to the same website on CentOS 5.x with Plesk 10?
1) Create a vhost.conf in your faivorit editor and add the following to it:
ServerAlias yourdomain.com
ServerAlias http://www.yourdomain.com
No need to put … here. Just put each domain as you see it above on separate lines.
2) Save the vhost.conf file and upload it to the server at the following folder:
/var/www/vhosts/yourdomain.com/conf/
3) Once the vhost.conf is uploaded to the folder in step 2 you will need to run the following command line with putty or ssh to publish the new aliases to Apache:
/usr/local/psa/admin/sbin/httpdmng –reconfigure-domain yourdomain.com
The old/obsolete way of doing this would be to use the following command line:
/usr/local/psa/admin/sbin/websrvmng -u –vhost-name=yourdomain.com
4) If you followed my instructions above as I listed here you should not see any errors at all. If you are using Plesk 10 and you use the old/obsolete commands you will get the following warning message:
WARNING: You are using obsolete option, use corresponding option of httpdmng.
But this should still work for you and you can disregard this message.
5) Now test your new domains and they should all be pointing to the correct website.
I hope this helps anyone looking to setup multiple domains to point to the same website.
Mike
September 14th, 2011 at 11:48 am
[…] to modify the Plesk vhost.conf file so everything plays nice. Posted in Computers and tagged Servers. Bookmark the permalink. […]
January 13th, 2012 at 9:24 am
[…] Aaron Gadberry has a great tutorial including some great comments explaining more complex scenarios such as symlinks. Check it out: http://www.gadberry.com/aaron/2006/02/09/plesk_vhost/ […]
January 27th, 2012 at 8:37 am
I am getting the following error, how do I resolve this peacefully?
The ScriptAlias directive in /var/www/vhosts/rxbluepill.com/conf/vhost.conf at line 12 will probably never match because it overlaps an earlier ScriptAlias.
March 23rd, 2012 at 10:23 pm
I’m trying to redirect permanently all of the https request to a folder located inside of my httpdocs
What should I type in the vhost_ssl.conf file to accomplish this? I want to point the request to a folder called portal
March 2nd, 2014 at 1:26 am
This trick to get a vhost.conf file to work is what I have been missing.
I have also discovered that the vhost.conf file is the only place where you can tune the duration of a FastCGI time-out, by including
IPCCommTimeout 900
or whatever number of seconds your application may require.
By the way, if you are running only PHP scripts (and this is notably the case if you have a Drupal site), a high value here is safe enough since you will be protected by the PHP max_execution_time variable [which can be temporarily overriden by set_time_limit()] but either of these being set above the FastCGI limit will not work