Leon's Weblog

November 30, 2007

Configuring Website on a 1and1 Shared Host

Filed under: Software Dev — Leon @ 2:39 pm

Recently, I was working on a project to setup a new website on a 1 & 1 shared host. Shared hosts are a cheap alternative to VPS and managed servers but they come with a mixed bag of restrictions that limit your ability to configure the server. I was looking for a host for under $10/month that offered SSH access and had a typical LAMP setup. This is how I configured the rest.

Update 10/9/2009: Please read my updated article on setting up a 1&1 Shared Host.

PHP Configuration

To use PHP 5 by default, add the following line to the .htaccess file under the htdocs folder.
AddType x-mapp-php5 .php

Need to setup custom PEAR modules? No problem, just follow this guide. Contrary to the guide, however, I would install PEAR into a ~/opt subfolder so that you have a place to install other applications and libraries in the future. Also, add the ~/opt folder to your list of “Protected Directories” using 1 & 1’s config panel.

Adding PEAR to PHP’s include_path was another challenge. I found that the best way to do this is inside the PHP code by using the following command (messing with php.ini files in every directory of your project is too much of a hassle).
ini_set("include_path", ".:/usr/local/lib/php5:/homepages/xx/xxxxxxxxxx/htdocs/opt/pear/php");

mySQL Configuration

1&1 keeps their mySQL servers behind a firewall which makes it impossible to access them using local client tools. The only way in is via SSH using the CLI or using web based config tools like phpMyAdmin. I was also unable to pick my own database name or create my own account (1&1 creates one for you). This took me a while to accept but I had to give in eventually.

As a consequence, when configuring PHP applications such as WordPress, you have to set the database settings to the cryptic database name and login account created by 1&1. Also, remember to change the host name from "localhost" to the host name provided. 1&1 actually offers a guideto setup WordPress although they state that support for this 3rd party software is not provided.

Subversion Configuration

Configuring a Subversionrepository was a bit more of a challenge but luckily it is not impossible. First, login to the shared host via SSH and download the latest Subversion source code from their site. I created a local ~/tmp folder under htdocs for this. Note that we will need to get the code for the dependency libraries as well because 1&1 does not have them installed.
> wget http://subversion.tigris.org/downloads/subversion-1.4.5.tar.gz
> wget http://subversion.tigris.org/downloads/subversion-deps-1.4.5.tar.gz
> tar -xzvf subversion-1.4.5.tar.gz
> tar -xzvf subversion-deps-1.4.5.tar.gz

At this point we have the folder ~/tmp/subversion-1.4.5 containing all the needed source code. We need to configure the project to install it into the ~/opt/svn folder, build/compile the code, and install it.
> cd ~/tmp/subversion-1.4.5
> ./configure --prefix=/homepages/xx/xxxxxxxxxx/htdocs/opt/svn
> make
> make install

If all goes well (which it should), the last thing to do is to include the compiled svn binary into our path so that we can issue the svn command from any directory. It is best to set the $PATH variable in the .bash_profile file so that the setting gets applied every time that you log in.
> echo 'export PATH=$PATH:$HOME/opt/svn/bin' >> ~/.bash_profile

To test our configuration, just check the version of the SVN binary (remember to log out and back in to make sure the $PATH gets set… or just do it once manually). We should also cleanup the temp files that we created and create a new Subversion repository while we are at it.
> svn --version
> rm ~/tmp/subversion* -r
> svnadmin create ~/opt/svn/repos

Note that we will only be able to connect to our Subversion repository using the svn+ssh protocol because we will not be able to get an actual Subversion server setup. TortoiseSVN is a great Windows tools for connecting to your repository. However, for this to work, we also need to set the $PATH in the .bashrc file (we only setup the .bash_profile so far). This guide explains why.

Your mileage with other Shared Hosting providers may vary. Hope this helps…

20 Comments »

  1. Hey thanks for the link and especially thanks for the SVN setup steps I’ve been planning to research that. I’ll create a post and link back to this info. Thank you!

    Comment by Brian Layman — November 30, 2007 @ 2:47 pm
  2. This works great for me until I get to the step

    ./configure –prefix=~/opt/svn

    it gives me an error saying: configure: error: expected an absolute directory name for –prefix: ~/opt/svn

    It appears that I’m doing something wrong. I am trying to load subversion-1.4.6 rather then .5… would that make a difference

    Comment by Mike — February 7, 2008 @ 2:15 am
  3. Mike,
    The minor version difference for SVN would not cause that error. Check that you don’t have a typo in the command. It should be “–prefix” (i.e. two hyphens not one). Otherwise, try expanding the “~” out to the full path (/homepages/xx/xxxxxxxxxx/htdocs/opt/svn). The “prefix” option is used to specify where the compiled binaries should be installed. Good luck.

    Comment by leon — February 7, 2008 @ 10:33 am
  4. thanks for posting this…I thought we would have to find a new host to let us use svn, but this tutorial worked like a charm!

    Comment by Tim — February 13, 2008 @ 10:04 am
  5. Hey

    I was able to successfully install subversion however I am not able to connect to it properly via svn+ssh or any other way than locally.
    It keeps telling me:
    bash: svnserve: command not found
    svn: Connection closed unexpectedly

    Did you get similar errors? It seems svnserve is not in the PATH. I have since created a .bash_profile file and added that to it. Now when I log in svn commands are available immediately but still if I want to svn+ssh to it I get this error. I have a 1and1 shared hosting. I’m pulling my hair out.

    I’d really appreciate any help
    Thanks
    Chris

    Comment by Chris — February 19, 2008 @ 3:52 pm
  6. Chris,
    The first thing that I would check is that both the .bash_profile and .bashrc files are present and contain the PATH variable. These files usually contain the same information and it is a common practice to reference one file from the other. If you can login over SSH and use the SVN command locally then the .bash_profile is working. If the same command doesn’t work over SVN+SSH then its an issue with th .bashrc (the settings in .bashrc are specifically for remote connections).

    Also, make sure you are connecting to the repository using svn+ssh (not over the native SVN client-server protocol). I created the repository while being logged in so I did not need the svnserve command to be executed remotely (only the svn command). I connect to the repository using the following URI:
    svn+ssh://user_id@server_name.onlinehome.us/kunden/homepages/XX/XXXXXXX/htdocs/opt/svn/repos/project_name/trunk

    I’ve been using this setup on 1&1 for several months without a problem so you are probably overlooking something minor.

    Comment by leon — February 19, 2008 @ 10:31 pm
  7. Thank you. Just in case anyone else has this problem, you need to have both .bashrc and .bash_profile, then everything works like a charm

    Comment by Chris — February 19, 2008 @ 10:53 pm
  8. Hi Leon,

    Thanks for posting these instructions for loading a SVN repos on 1&1. I have followed your directions above, with the exception that I am installing 1.4.6. All seemed to go well, until I tried accessing it from the client.

    I am able to view my empty repository using the Repo-browser (Tortoise), however, when I try to do the import, it fails with the following error message: “the requested name was valid and found in the database, but it does not have the correct associated
    data being resolved for.”

    Could you give me some ideas about how I might fix that?

    Thanks!

    The client is running in Windows XP

    Comment by Teresa — April 21, 2008 @ 11:27 am
  9. Teresa,
    I’m not sure how the Tortoise SVN import command works (which protocol and URI is used etc…). It looks like you are getting a Windows/Winsoc error.

    If you are able to create a repository on the host and check in/out content with your client, then the simplest solution is to just copy the files that you would like to add to the repository (using WinSCP or your sFTP client of choice) and use the SVN import command on the host directly. If checking in/out doesn’t work you may be using the wrong URI (make sure the path is correct for the SVN+SSH connection… that gets me too sometimes)

    Leon

    Comment by leon — April 21, 2008 @ 12:07 pm
  10. Leon,

    Is your SVN configuration still going strong on 1and1?

    Comment by Chad Upton — May 27, 2008 @ 8:29 am
  11. Were you able to get multiple svn user accounts to work? I tried to but failed. I documented my results here:

    http://www.john-lai.com/?p=27

    basically, i tried svnserve daemon mode, svnserve inetd mode, public key authentication….all attempts failed.

    Do you have any advice?

    Thanks

    Comment by John — September 8, 2008 @ 9:11 pm
  12. John, I think that this pushes the limit for what a 1&1 Web Host can provide. You have already tried everything that I could think of. If you have a team of developers, why not get a VPS or use SourceForge?

    Comment by leon — September 8, 2008 @ 9:45 pm
  13. […] The link below explain more things you can do on 1and1 shared hosting. Credits: lbsharp.com […]

    Pingback by 1&1 Hosting SVN — September 29, 2008 @ 3:09 pm
  14. […] Vía(Eng): [LINK] […]

  15. Hi,

    Just found your blog on Technorati & Digg upcomming news feeds and read a few of your other posts.
    ISeems good contents,Keep up the good work. Look forward to reading more from you in the future.

    Thanks,
    Michael

    Comment by Michael David — August 1, 2009 @ 5:13 am
  16. Hi,

    Thanks for this tuto.

    I’m also trying to make svn working on a 1&1 host but have some problems…

    I’ve follow all these instructions but tortoise can’t access to my repository.

    The commande “svn –version” answer me but not “ssh svnserve” one (“ssh: Could not resolve hostname svnserve: Name or service not known”)

    I’m trying to connect to the repository I’ve create before at ~/Svn/projects/Portfolio by this adress in tortoise: svn+ssh://u******@s*******.onlinehome.fr/kunden/homepages/**/******/htdocs/Svn/project/Portfolio

    Any idee to solve my problem?

    Many thanks 🙂

    Comment by Dark — September 23, 2009 @ 3:20 pm
  17. Hi everyone,
    Anyone tried this recently (I’m using build 1.6.13)? It builds but when I try to install I get an error saying that it can’t create directory ‘/homepages/xx’. I then replaced the ‘x’s with the appropriate number and it gets further but gives me an error ‘cannot install `libaprutil-1.la’ to a directory not ending in /homepages/xx/xxxxxxxxxx/htdocs/opt/svn/lib’. Any ideas? I don’t know much about Linux so I’m kinda stuck now.
    Thanks, Jason

    Comment by Jason — October 10, 2010 @ 11:33 am
  18. Oops, error on first attempt from my comment above is ‘cannot create directory ‘/homepages/xx’: Permission denied’. Thought the extra info might be important.
    Thanks again, Jason

    Comment by Jason — October 10, 2010 @ 11:35 am
  19. Hey Leon

    Having loads of problems trying to get Pear to work on 1 and 1 and came across this and got all excited. Unfortunalty the link for instructions on what to do seems to have expired. you havent got a copy anywhere have you?

    Thanks

    Matt

    Comment by Matt — February 7, 2011 @ 9:01 pm
  20. Hi there Leon,

    Firstly – thanks for the knowledge, had no idea I could install SVN on a shared host, this is a great money saving tip. I salute you! However – I have attempted the install several times (with version 1.6.15), the install completes with no errors, yet whenever I run svn –version, it displays svn, version 1.4.2 (r22196) compiled Aug 6 2009, 20:42:02. Of course, if I now try to check anything out through my client, I get the familiar error: Expected FS format “2?; found format “4?. It’s almost as if I have a version running on this box, that I cannot upgrade… very frustrating, so near, yet so far! FYI – I have a dedicated managed server with 1and1.co.uk.

    Any ideas? I am baffled by this

    Cheers

    Dan

    Comment by Dan — February 21, 2011 @ 12:11 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment