Thursday, April 24, 2014

Change the document root

I am using a dedicated CentOS server, with access to WHM and cPanel. 
What I want to do is unload my moodle code into a nice, organized file structure within my "File Manager" on cPanel." The end result should be that I can put my moodle code here:

public_html/moodle
public_html_moodledata

And still reference my site like this:  www.mysite.com 
(instead of normally having to extend the url like:   www.mysite.com/moodle/)

Since I have root ssh access on my server, I am going to edit where the documentroot points to. 

Login to SSH
Since I'm using a windows machine to access my server, I went ahead and downloaded PuTTY, a free ssh client. 
  1. I opened up putty and input my server's IP address. 
  2. I logged in as the root user. 
    1. If logged in as another user, use the command su -  command to enter root password and gain root access.
  3. Now we need to open and edit your domain file. Again, you can only do this as root user. Type in the following command:   vi /var/cpanel/userdata/USERNAME/DOMAINNAME
    1. An example would be:   vi /var/cpanel/userdata/testuser/mysite.com
  4. Now the file should be open within PuTTY. Click the "i" key to start editing mode, and use arrows to navigate to the section of text called "documentroot."
  5. Change that text to say:     documentroot: /home/testuser/public_html/moodle
  6. Rebuild the Apache conf and restart Apache. You can do this through SSH:
    1. /scripts/rebuildhttpdconf
    2. service httpd restart
  7. Or through the WHM panel. Type in the search bar "Apache Config". Go to the page.Save and rebuild.
  8. The change will be immediate. Simply clear your browser cache and force refresh the page!
I used this blog guide as a reference:
http://blog.servint.net/2012/03/30/the-tech-bench-changing-a-document-root-in-cpanel/