Aaron Gadberry

Help – v. helped, help·ing, helps

Was this site helpful?
My Amazon.com Wishlist

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.

47 Responses to “Using Plesk and vhost.conf”

  1. James Says:

    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?

  2. Stucco Says:

    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.

  3. Steve Says:

    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!

  4. Hugo Says:

    Thanks for this post – it really helped me getting open_basedir sorted.

    – Hugo

  5. Rebecca Says:

    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

  6. RedDawnAirsoft Says:

    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?

  7. indiainternet Says:

    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?

  8. jerry Says:

    If you need to add more directories try this:

    php_admin_value open_basedir “**Directory 1**:**Directory 2**”

  9. Tim Says:

    isnt it possible to create a file that goes for all vhosts?
    I want to add a open_basedir to all my vhosts…

  10. replica coach handbags Says:

    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

  11. Joe Butka Says:

    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”

  12. Andeh Says:

    Used this method to relax open_basedir restrictions, was editing the httpd.include file before, found this method much more efficient. Thank you!

  13. Aaron Says:

    As a side note you can use vhost_ssl.conf to set the https settings for your site.

  14. Ivo Says:

    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 :)

    php_admin_value open_basedir = “/var/www/vhosts/redirecteddomain.com/httpdocs:/var/www/vhosts/firstdomain.com/httpdocs”

  15. David Says:

    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?

  16. Thierry Says:

    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

  17. szalinski Says:

    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?

  18. Jesse Thouin Says:

    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!).

  19. Ryan Says:

    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.

  20. Insolence Says:

    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

  21. Cant figure out Bootstrapper Video Tutorial - Page 2 - Zend Framework Forum Says:

    […] 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 […]

  22. Ben Says:

    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

  23. Neil Says:

    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.

  24. Evilprofessor.co.uk » Blog Archive » Custom php.ini with Plesk Says:

    […] 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, […]

  25. webdesign Says:

    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 ?

  26. carlos Says:

    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.

    
    <VirtualHost 60.190.200.123:80>
    	ServerName   mydomain.com:80
    	ServerAlias   *.mydomain.com
    	DocumentRoot /var/www/vhosts/mydomain.com/httpdocs/default
    	CustomLog  /var/www/vhosts/mydomain.com/statistics/logs/access_log plesklog
    	ErrorLog  /var/www/vhosts/mydomain.com/statistics/logs/error_log
    </VirtualHost>
    

    Is there any other way to do this ? Am I doing something wrong ?

  27. Using Plesk and vhost.conf « RussenReaktor’s Weblog Says:

    […] 29, 2008 “/usr/local/psa/admin/sbin/websrvmng -u –vhost-name=domain.com”gadberry.com Posted in vps […]

  28. Totrk Says:

    Really good this help me to make Joomla work with Pelsk … (and other helps), is the best mention of specific vconf in Plesk

  29. Scott Thompson Says:

    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.

  30. Robert Bartlett Says:

    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!

  31. sb Says:

    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. ;)

  32. diastasi Says:

    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

  33. Peter Dekkers Says:

    Well, perhaps people would not forget it if it was mentioned in the httpd.include file. ;)

    Too true. It’s a bit all over the place, the Plesk documentation and help, isn’t it.

  34. Ricardo Martinez Says:

    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

  35. Amy Says:

    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?

  36. reinforced concrete Says:

    Agrh…. again plesk – always in trouble ! :)

  37. Ihsan Faisal Says:

    Thanks, you helped me understand plesk better..

  38. vinayak Says:

    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

  39. Mike Says:

    Thanks! Saved me 30 mins of troubleshooting :)

  40. Geeko Says:

    Thank you much !!
    This configuration helped me a lot!

  41. Ron Says:

    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.

  42. Mike Says:

    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

  43. Separate PHP Error Logs for Multiple Domains with Plesk | David Seah Says:

    […] to modify the Plesk vhost.conf file so everything plays nice. Posted in Computers and tagged Servers. Bookmark the permalink. […]

  44. Configuring Plesk to recognize vhost.conf – Steedan Crowe Says:

    […] 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/ […]

  45. JN Says:

    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.

  46. olebot_ Says:

    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

  47. Danny Says:

    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

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>