Guide to Moodle with Vhost setup and Plesk (& Moodledata permission issues)

Guide to Moodle with Vhost setup and Plesk (& Moodledata permission issues)

by Tarik Dzekman -
Number of replies: 9

I have had so many issues installing Moodle and in searching the forums have found that many people had similar issues, though mine perssisted. So I figured I'd write a little guide with my experiences in it to help others in their search.

I'm running moodle with mediatemple.net on a dedicated virtual server. Specs are:

    * CentOS release 5 (Final)
    * Apache (version 2.2.3)
    * Perl (version 5.8.8)
    * PHP (version 5.2.5)
    * MySQL (version 5.0.22)

This should help with pretty much any Linux/Unix OS on a Vhosts/Plesk setup.

First skip the install.php process and edited the config.php file directly. In order to do this you need to make the folder moodledata outside of your httpdocs directory.

Unfortunately you likely can't do that without root access. So SSH into the server with root and mkdir moodledata in your vhosts/domain.com/ directory.

chmod the directory to 777 (try different permissions once you get it to work). chown the directory with -apache -apache

Now you need to turn off php safe_mode in your php.ini file likely located in your /etc/ folder. Just change safe_mode on to safe_mode off. Then restart your appache server, but if you follow the rest of the instructions you'll need to do that later anyway.

Funny thing is - this will get you past the installation phase. Unfortunately, won't let you do anything inside Moodle. You won't be able to create courses or add users. If you follow your error log it will say open_basedir restrictions in effect, </../../moodledata> is outside the specified path(s). Or something similar.

There are many posts in the forum for ways to deal with open_basedir restrictions and only one of them worked for my vhosts setup...

in /var/www/vhosts/domain.com/conf create a file called vhost.conf

Inside put:

<Directory "/var/www/vhosts/domain.com/httpdocs">

php_admin_flag engine on

php_admin_value open_basedir "/var/www/vhosts/domain.com/httpdocs/:/var/www/vhosts/domain.com/moodledata:/tmp"

</Directory>

If you do this you'll be able add users and even upload users from a csv file with the right plugin. You'll need to enter this command in your SSH console:

/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=domain.com

And restart your server.

Unfortunately, if your setup is like mine, this will still leave you with one more problem. If you try to upload files to sitefiles or to courses it will say "the site administrator needs to fix file permissions". And if you check your server logs it will give you the same open_basedir restrictions error as before.

You also need to create another entry in your vhost.conf file:

<Directory "/var/www/vhosts/domain.com/moodledata">

php_admin_flag engine on

php_admin_value open_basedir "/var/www/vhosts/domain.com/httpdocs/moodledata/:/var/www/vhosts/domain.com:/tmp"

</Directory>

The first entry ensures that httpdocs can write to moodledata but this second one ensures moodledata can write back to httpdocs. Don't forget to:

/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=domain.com

and restart your apache server.

As an alternative, if you want, you MIGHT be able to turn off open_basedir restrictions inside your php.ini file. I didn't get to trying this but have a feeling that it won't work.

The reason it won't work on a vhost setup is that the open_basedir command is located in A LOT OF PLACES, not just php.ini. In some places it's turned on, in others it's turned off. You essentially need to specify whether it's on or off on a PER DOMAIN but also PER DIRECTORY basis.

Hope this helps someone,

-T

Average of ratings: Useful (1)
In reply to Tarik Dzekman

Re: Guide to Moodle with Vhost setup and Plesk (& Moodledata permission issues)

by Lenny Fudenna -
Thank you for writing this up. I was really frustrated with getting errors on the moodledata folder not being writable and these instructions worked perfectly. Had no idea it was because I was running it on a vhost. Thank you!!!
In reply to Tarik Dzekman

Re: Guide to Moodle with Vhost setup and Plesk (& Moodledata permission issues)

by Miguel Ángel Marcos -
Thank you very much for your precise explanations, Tarik Dzekman!! They have really been a great help and indeed they have made possible the succesful migration of our CMS. Keep up the good teaching!! Take care! Kind regards from Spain.
In reply to Tarik Dzekman

Re: Guide to Moodle with Vhost setup and Plesk (& Moodledata permission issues)

by Stephen Overall -
Let me add my thanks as well. I also followed your directions and was able to get through a successful Moodle install on my new VPS account on the first try. Whew! What a relief... thank you for sharing your expertise!

Now-- I'd like to have two Moodle installations (running off separate databases) on the same VPS account domain, each Moodle storing its uploaded files in its own moodedata directory above the web root-- say, moodledata1 and moodledata2.

Question: How would one write the vhost.conf <Directory></Directory> entries to run two separate Moodle installations each with a separately named moodledata directory above the web root?

Would the Moodle variable php_admin_value open_basedir be confused by two different moodledata directories?
  • moodledata1
  • moodledata2
Thanks.

Steve
In reply to Stephen Overall

Re: Guide to Moodle with Vhost setup and Plesk (& Moodledata permission issues)

by Stephen Overall -
Me, again. Just encountered and resolved a strange behavior involving the "php_admin_value open_basedir is in effect" error message.

I spent much of today struggling with installing Moodle on a different domain also hosted on my new VPS Plesk account. I went through exactly the same procedures described above by Tarik as I did yesterday, but instead of sweet success, I encountered the "open_basedir in effect" error message from hell on the second page of the Moodle installation process. Arghhh!!!

Looking carefully at the error message, I noticed an inconsistency in the message-- the first part of the error message mentions the directory "moodledata" is not in the permitted directory "moodledata1"-- which is true since I had named the moodle data directory placed above the web root "moodledata1". But here was the Moodle install.php file apparently looking for the directory moodledata, seemingly before it had asked me for the name of the data directory. Odd. I've never seen that script behavior before.

So I decided to try feeding install.php what it seemed to be asking for. I renamed moodledata1 to moodledata, changed the references in my vhost.conf file, reconfigured vhost, restarted Apache2, and then pointed my browser to install.php-- and this time Moodle sailed through the installation without a hiccup!

This is very strange, I think, because I have installed Moodle several other times on non-VPS hosts (shared hosting with Cpanel access) using various custom names for the Moodle data directory without Moodle ever complaining.

Has anyone else run into this problem?

I was hoping to install a second Moodle on the same domain to serve as an archive, but if I can only name and use ONE Moodle data directory... then that's a problem.

Puzzled for now. But at least my single Moodle installation is working. thoughtful
In reply to Stephen Overall

Re: Guide to Moodle with Vhost setup and Plesk (& Moodledata permission issues)

by Stephen Overall -

By the way, here are the original directions for "Including Directives into Web Server Configuration File" as found on page 312 in "Appendix A. Advanced Features" in the Parallels Plesk 9 Administrator's Guide posted here...

http://download1.parallels.com/Plesk/PPP9/Doc/en-US/plesk-9.0-administrators-guide.pdf

Needed to silence the dreaded "open_basedir restriction in effect" Moodle install error message.

In reply to Tarik Dzekman

Re: Guide to Moodle with Vhost setup and Plesk (& Moodledata permission issues)

by Noel Chidwick -

Certainly helped me!

I've just upgraded a server to Plesk 10x and that meant I had to reset this all over again. Note that I used:

/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain <domain name>

instead of:

/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=domain.com 

In reply to Noel Chidwick

Re: Guide to Moodle with Vhost setup and Plesk (& Moodledata permission issues)

by Urs Giezendanner -

I had the same Problem with Plesk 10.4.

First I made with the same prositure as writen in this post. 

Then I tried to make it in the Plesk PHP settings-> open_basedir -> Enter custom value:

/var/www/vhosts/domain.dom/httpdocs/:/var/www/vhosts/domain.dom/moodledata:/tmp:/proc:/usr/bin

and it works fine, without any shell-work.

In reply to Urs Giezendanner

Re: Guide to Moodle with Vhost setup and Plesk (& Moodledata permission issues)

by Michele Mason -

Hi Urs,

I also followed all the instructions in the Guide above (thanks Tarik) but couldn't get the SSH console command to work and still was not able to install Moodle so then I read somewhere about doing the setting in Plesk by going to the domain and customising the PHP settings as you did and then I was able to install Moodle successfully. But I wasn't able to upload any files which I think was because I couldn't get the SSH console commands to work. So I tried this command;

/usr/local/psa/admin/sbin/httpdmng --reconfigure-server

and that seems to have worked for me (so far), I'm using Plesk 10.4.4 and I absolutely hate it, it is so restrictive and the documentation is rediculously lacking in any explinations on how to overcome these kinds of issues and the support team are even worse. If I had a choice I would not be using Plesk but unfortunately it comes with my VPS.

In reply to Michele Mason

Re: Guide to Moodle with Vhost setup and Plesk (& Moodledata permission issues)

by Urs Giezendanner -

Hi Michele

Perhaps you did not understand well... I did noch chance anything with SSH.

Only the change in Plesk to :

/var/www/vhosts/domain.com/httpdocs/:/var/www/vhosts/domain.com/moodledata:/tmp:/proc:/usr/bin

In Plesk-Panel --> Hosing Settings --> PHP Settings --> open_basdir --> Enter custom value.

worked well.

I like Plesk wink