SVN 0.2 PECL Extension for PHP --------------------------------------------------------------------------- It took me two days to figure out how to compile the PECL extension 'svn' for PHP5 on Dreamhost. It's not difficult, but it's not a walk in the park. There are lots of dependencies. These instructions can be applied to other hosting environments where shell is allowed, although the dependencies will change. Be sure to do the necessary research before plowing ahead. The instructions here are specific to Dreamhost's server configurations. == Dependencies == Before you embark, you'll want to add $HOME/bin to your $PATH variable in .bash_profile: PATH=$HOME/bin:$PATH If you've previously installed your own libraries or executables, this step may have already been done. You may also want to consider using a prefix directory that is not your $HOME directory, in that case, specify the directory in some other variable and replace all instances of $HOME below with that variable. === Autoconf (2.61) === A very useful tool, and also one that Dreamhost doesn't have. This particular PECL package will need it, so download the source code from GNU's website, unpack it, and then install. wget http://mirrors.kernel.org/gnu/autoconf/autoconf-2.61.tar.gz tar -xzf autoconf-2.61.tar.gz cd autoconf-2.61 ./configure --prefix=$HOME make make install === Subversion (1.4.3) === Dreamhost comes with `svn` installed, however, it does not provide the necessary includes and headers necessary to compile our extension. Best to install your own version. Subversion, itself, has oodles of dependencies, but the Subversion developers have been so kind to provide an subversion-deps-x.y.z.tar.gz file on the downloads page. Download this file and the main source code file. Run in the newly created subversion-x.y.z/ directory: wget http://subversion.tigris.org/downloads/subversion-1.4.3.tar.gz wget http://subversion.tigris.org/downloads/subversion-deps-1.4.3.tar.gz tar -xzf subversion-1.4.3.tar.gz tar -xzf subversion-deps-1.4.3.tar.gz cd subversion-1.4.3 ./configure --prefix=$HOME make make install This should do the installation, with all the dependencies. Subversion will recursively configure and make all of Subversion's dependencies. == PHP (5.2.1) === Once again, Dreamhost comes with `php` installed. It even has `php5` installed. However, the `phpize` it has installed is out-of-date and will not work for PHP5 websites, so you'll need to install your own local copy. (If you're using PHP4, using the default may work). Download the PHP source code that synchronizes with the version Dreamhost is running (for my case, it was 5.2.1, you can check using `php -v` or `php5 -v`). Do the standard kaboodle: wget http://us3.php.net/get/php-5.2.1.tar.gz/from/this/mirror tar -xzf php-5.2.1.tar.gz cd php-5.2.1 mkdir $HOME/local-php ./configure --prefix=$HOME/local-php make make install We don't care about compiling the extensions because all we're after is phpize. Furthermore, we're not installing it into a directory that's in our path ($HOME/bin v. $HOME/local-php/bin) because we don't want this installation to supplant Dreamhost's own version of PHP (you may have command line scripts that rely on Dreamhost's specific version.) If you're using an alias: alias php="/usr/local/dh/cgi-system/php5.cgi" In order to overload calls to `php` with the PHP5 binary, this procedure is not strictly necessary, but it doesn't hurt to play it safe. == Installation == Finally, we can install the PECL extension. We will download the source code, set up the environment with phpize, run autoconf to set up the configuration, and then do the standard configuration kaboodle, but without `make install`. Sound confusing? It is. wget http://pecl.php.net/get/svn-0.2.tgz tar -xzf svn-0.2.tgz cd svn-0.2 Standard procedures. No surprises here. autoconf The developers of svn have been so kind not to provide a configure.sh script. So we'll use autoconf to generate it. `phpize` also seems to have trouble finding the autoconf binary, so lets make life easy for them. $HOME/local-php/bin/phpize Alright, we're calling phpize to setup the environment. However, you'll notice that we didn't call `phpize`, but we called the full path. This is essential to make sure we're calling the *right* binary. For PHP 5.2.1, you should see this in the output: Configuring for: PHP Api Version: 20041225 Zend Module Api No: 20060613 Zend Extension Api No: 220060519 If you went against my advice and added $HOME/local-php/bin to the path, you might be able to get away with calling only `phpize`. Be sure to check the numbers though. ./configure --with-svn=$HOME This little gem took me two hours to figure out. Accept my hard-earned knowledge gratefully! The config.m4 file will not check your PATH for the necessary Subversion includes, so you will need to tell the configure script explicitly where to find your locally installed copy of Subversion (remember, Dreamhost's version does not contain the proper includes!) Also, although config.m4 seems to check the $PHP_SVN environment variable, it really doesn't. So don't try to use it. Note that we didn't specify a prefix, that's because we're not going to make install. make Compile the extension. The prized 'svn.so' file will be in a newly created modules folder. Copy it over to somewhere easily accessible. You can now use your extension via: dl('/path/to/svn.so'); That's it! == And now... == Documentation for the SVN extension is woefully lame. Try these resources: * http://www.edoceo.com/intmain/20060808-pecl-svn-package.php - lists the available functions, and some usage info. * http://cvs.php.net/viewvc.cgi/pecl/svn/svn.php?view=markup - test script for the extension, it offers some concrete usage examples. Don't run it though! * http://cvs.php.net/viewvc.cgi/pecl/svn/examples/ - more example scripts * http://svnbook.red-bean.com/en/1.2/svn.developer.usingapi.html - The Subversion Book's explanations of the APIs. Not PHP specific, but should give you some ideas for experimentation. Some common pitfalls: * To specify a repository URL on a local filesystem, you'll need to use the file:// schema. * If the SVN extension errors out, it will often result in an internal server error. I suspect the developers will want to rectify this sometime. Cool stuff: * http://www.akbkhome.com/blog.php/View/86/FlexySvn_A_subversion_browser_using_the_php_svn_bindings.html - The authors of the SVN extension also have hacked together FlexySVN, which is an XUL/Javascript/PHP based Subversion repository browser. Credits (won't help you, but certainly helped me): * http://livedocs.phpdoc.info/index.php?l=en&q=install.pecl - Contains instructions on how to install PECL extensions manually. I suppose this could have all been automated using `pecl`, but I didn't want to install it. :-P * http://svn.haxx.se/users/archive-2005-06/0383.shtml - The mailing list post that got things working for me. I'll be working on more indepth documentation for the SVN extension as I stumble my way through it. Thanks for reading!