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

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.

25 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 ?

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>