Media Temple Articles

RSS Feed - Tag Media Temple

Auto-Update SVN on Media Temple (gs)

Tags: Media Temple, Linux | on 9/10/08

I wanted to update SVN every 5 minutes on my Media Temple grid service (gs) account. Here is the steps I took to make that happen.

First, I created a shell script with the SVN Update (I'll show how in a minute). I got this error:

Error validating server certificate

For some reason SVN wasn't reading my trusted server list, so I asked (mt) about it.

Josh Kline at Media Temple pointed out the issue. I'm not sure why this isn't documented somewhere, so I'm blogging it.

SVN looks for the config, including the trusted server list, in $HOME/.subversion
Your cron jobs run with HOME=/home/#####, but when you ssh in HOME=/home/#####/users/.home
running svn with --config-dir /home/#####/users/.home/.subversion will fix the problem.

That said, here are the steps to get SVN to auto update every 5 minutes. SSH in, you will have to go through the steps to enable SSH.

Bash:
  1. cd data
  2. mkdir scripts
  3. vi cron.sh

In your cron.sh, use the config command that Josh suggested (replacing ##### with your id)

Bash:
  1. svn update SVN_PATH --config-dir /home/#####/users/.home/.subversion

Go into the (mt) control panel under Cron Jobs and configure one to run your shell script.

There you have it, you now have svn auto updating on shared hosting.

CakePHP on Media Temple (dv) 3.5

Tags: CakePHP, PHP, Linux, Media Temple | on 18/6/08

A good thing to do when deploying CakePHP websites is to load one copy of the CakePHP core files onto your server, and point all of your domains to that core directory. 

Media Temple's Plesk default configuration does not let PHP access files outside the website httpdocs. So we need to configure the domain's settings to have access to the root /cake folder, or wherever you happened to put the CakePHP root files.

First, let's make a new config file in our domain. Make sure you replace domain.com with your domain.

Bash:
  1. cd /var/www/vhosts/domain.com/conf/
  2. vi vhost.conf

Then basically we are over riding the default settings of Plesk with our own. Setting open_basedir to allow the /cake path.

Apache:
  1. <Directory /var/www/vhosts/domain.com/subdomains/tools/httpdocs>
  2.         <IfModule sapi_apache2.c>
  3.                 php_admin_flag engine on
  4.                 php_admin_flag safe_mode off
  5.                 php_admin_value open_basedir "/cake:/var/www/vhosts/domain.com/subdomains/tools/httpdocs:/tmp"
  6.         </IfModule>
  7.         <IfModule mod_php5.c>
  8.                 php_admin_flag engine on
  9.                 php_admin_flag safe_mode off
  10.                 php_admin_value open_basedir "/cake:/var/www/vhosts/domain.com/subdomains/tools/httpdocs:/tmp"
  11.         </IfModule>
  12. </Directory>

Now we need to reload the vhost to include that loads our new config file.

Bash:
  1. /usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=domain.com
  2. service httpd graceful

Great! Now we can have a central set of cake files and use it for each domain.

SVN Authentication and Auto Update

Tags: Media Temple, Linux | on 24/11/07

Media Temple Dedicated-Virtual dv hosting

During the first two parts of my series on setting up a Media Temple dedicated server, I setup subversion (SVN) on apache. Now I want to show you how I setup basic authentication and a SVN hook to automatically deploy files to the server (called continuous integration). This is great because you can check in your files to SVN and see them on the server immediately.

Adding Basic Apache Authentication to your Subversion (SVN) Repository

First lets give apache access to the SVN database (the $ symbol just means it is a shell command).

Bash:
  1. chmod g+s /svnroot/db

Now create a password file with htpasswd, name the file whatever you would like. I chose to make my file hidden by adding the period before the name.

Bash:
  1. htpasswd -cm /etc/.htaccess yourusername

It will prompt you for your password. Now go back to your httpd.conf and than add the last four lines below to your Location code block  - we are adding to what we did in part 2 of the media temple setup series.

Apache:
  1. <Location /svn>
  2.   DAV svn
  3.   SVNParentPath /usr/local/svn
  4.   AuthType Basic
  5.   AuthName "Subversion repository"
  6.   AuthUserFile /etc/.htaccess
  7.   require valid-user
  8. </Location>

For security reasons, we also need to make sure and hide the .svn folders from having apache publicly display them:

Apache:
  1. # Disallow browsing of Subversion working copy administrative dirs.
  2. <DirectoryMatch "^/.*/\.svn/">
  3.     Order deny,allow
  4.     Deny from all
  5. </DirectoryMatch>

Restart apache and when you try to access SVN you should be prompted for authentication. Great, SVN is now secure! You can also add more security by adding SSL to your dedicated server.

Creating a Subversion (SVN) Hook to Auto Update Your Server

I want to automatically deploy my files to my httpdocs without having to manually go in and update the files. So to accomplish this you need to create a SVN hook that runs after every commit.

First, copy the post-commit template from your svnroot/hooks folder. And lets also use chmod to give the file rights to execute.

Bash:
  1. cd /svnroot/hooks/
  2. cp post-commit.tmpl post-commit
  3. chmod +x post-commit

Now we need to create a little C program. You should have GCC installed. This will compile our little C program. Create a new svnupdate.c file and put this code in. Don't forget to change the directory path: "public_html_directory"

C:
  1. #include <stddef.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. int main(void)
  5. {
  6.   execl("/usr/bin/svn", "svn", "update", "/public_html_direcotry/",
  7.         (const char *) NULL);
  8.   return(EXIT_FAILURE);
  9. }

Complile the file with this command. It will take the whatever.c and compile it into a binary file.

Bash:
  1. gcc -o svnupdate svnupdate.c

Try executing the binary to see if it works with the env command.

Bash:
  1. env - ./svnupdate

Alright now copy the whatever binary into your hooks folder. And we'll also run a couple commands to give it proper priveledges:

Bash:
  1. cp whatever /svnroot/hooks
  2. cd /svnroot/hooks
  3. chown root:root svnupdate
  4. chmod +s svnupdate

Then lets tell the post commit hook to run our binary file name, "svnupdate".

Bash:
  1. vi /svnroot/hooks/post-commit

Inside it the post-commit hook tell it to run the binary using the absolute path:

C:
  1. /svnroot/hooks/svnupdate

Test it out by checking in a file to subversion. It should automatically update at the directory we set in the C program.

Installing Subversion on Apache

Tags: Media Temple, Linux | on 21/11/07

Media Temple Dedicated-Virtual dv hosting

Note on June 24, 2008: Media Temple released their (dv) 3.5 which has a new set of developer tools, subversion and yum are installed - so you should be able to skip past the first few steps. You still may need to install mod_dav apache module with, "yum install mod_dav".

How to install subversion on a Media Temple dedicated virtual (dv) 3.0 linux server.

In the first part of setting up a dedicated server with Media Temple, I found out how to install PHP5 and learned some basic linux commands. I quickly realized how difficult linux can be if you don't know what you are doing. Luckily, YUM made my life a lot easier.

YUM is helps you easily install packages with simple commands on linux. First, lets install YUM and use it to install subversion. Run these commands one-by-one:

Bash:
  1. rpm -ivh --nodeps http://centos.mirror.vpslink.com/centos-4/4.5/os/i386/CentOS/RPMS/libxml2-python-2.6.16-10.i386.rpm
  2. rpm -ivh --nodeps http://centos.mirror.vpslink.com/centos-4/4.5/os/i386/CentOS/RPMS/python-elementtree-1.2.6-5.el4.centos.i386.rpm
  3. rpm -ivh --nodeps http://centos.mirror.vpslink.com/centos-4/4.5/os/i386/CentOS/RPMS/python-sqlite-1.1.7-1.2.1.i386.rpm http://centos.mirror.vpslink.com/centos-4/4.5/os/i386/CentOS/RPMS/rpm-python-4.3.3-22_nonptl.i386.rpm
  4. rpm -ivh --nodeps http://centos.mirror.vpslink.com/centos-4/4.5/os/i386/CentOS/RPMS/python-urlgrabber-2.9.8-2.noarch.rpm
  5. wget http://centos.mirror.vpslink.com/centos-4/4.5/os/i386/CentOS/RPMS/yum-2.4.3-3.el4.centos.noarch.rpm
  6. rpm -Uvh yum-2.4.3-3.el4.centos.noarch.rpm

To check if it is installed run this command:

Bash:
  1. rpm -q yum

Now we need to install subversion and to run it through apache we need mod_dav_svn (apache 2 modules).

Bash:
  1. yum install subversion
  2. yum install mod_dav_svn

I found a few articles on setting up subversion, but I'll walk you through how I got it to work. First I needed a home location, I chose to call this "svnroot".

Bash:
  1. svnadmin create /svnroot
  2. svn mkdir file:///svnroot

Now, I want to import the httpdocs of my subdomain into the <project>/trunk. You can name your project whatever you would like. Don't forget to replace the domain, subdomain and project name in this next command:

Bash:
  1. svn import /var/www/vhosts/<domain>/subdomains/<subdomain>/httpdocs file:///svnroot/<project>/trunk/dev -m 'Initial import of dev httpdocs'

To test that my files were imported correctly and the svn repository was created successfully, I ran this command.

Bash:
  1. svn checkout file:///svnroot/<project>/trunk/dev #/svnwork

Vuala! - it downloaded my httpdocs to the #/svnwork directory. Now lets setup our SVN through apache. First, lets give Apache access to the folder:

Bash:
  1. chown -R apache.apache /svnroot

Next, lets jump in the apache config and load the proper modules and set the svn location.

Bash:
  1. vi /etc/httpd/conf/httpd.conf

Press 'i' to insert into the document and in the LoadModule section add these two lines:

Bash:
  1. LoadModule dav_svn_module modules/mod_dav_svn.so
  2. LoadModule dav_svn_module modules/mod_authz_svn.so

And lets add the SVN location for apache to access. Careful, this does not add any authentication so you are giving free reign to your SVN server until then. Add this to your apache config:

Bash:
  1. <Location /repos>
  2.   DAV svn
  3.   SVNPath /svnroot
  4. </Location>

Hit esc and than :x to quit and save the file. Restart your apache server, you should get an ok message [ok].

Bash:
  1. /etc/init.d/httpd restart

Now download the windows subversion client and install. Let's test to see if our Apache subversion module worked. Use 'http://<server ip address>/svn to see verify it worked.

Media Temple Dedicated Server Setup

Tags: Media Temple, Linux | on 5/5/07

Media Temple Dedicated-Virtual dv hosting

I wanted a web hosting server that I can hyper-tweak to my needs. So I opted for a dedicated server with Media Temple. I have little knowledge in linux, but I am going to embark on this road to server greatness. I want to get these things on my server to start: subversion, PHP5 and MySQL5 (PHP5 comes pre-installed now). Here I'll walk through my experience setting up my dedicated virtual (dv) server.

You have to request admin access and dev tools to be installed. So I sent a support ticket and it took a day. Here is a list of the dev tools that are installed.

Opened VI (text editor) as part of the tutorial and couldn't figure out how to get out of it once you start editing a file. So I found this article which told me to exit by hitting ESC than typing :x http://www.cs.colostate.edu/helpdocs/vi.html

Than I had to learn Putty/Linux so I looked up my commands here: http://www.ss64.com/bash/

Some good, general commands...

Bash:
  1. ls ...list directories
  2. mkdir <name> ...create a directory
  3. rm <filename> ...remove file
  4. wget <url> ...get a package
  5. cp <file> <directory> ...copy file to directoy

 

That's it for day one of my dedicated server setup.