Mac OS X, his built-in Apache, SVN and PHP, and using WebSVN

First to say I really have a svn repository for everything. As for this I like to use some functionalities to browse and use SVN smartly. And well nearly everthing you need is already on your Mac ( if you are a mac ;-) ).


So first for the Apache.

Apache

If you go to your System-Preferences and then to Sharing, you will see an entry called “Web-Sharing”. If you enable this feature your apache will start up.
WebSharing
To check if your Apache is running point your browser to http://localhost. You should see the following:
ApacheWorking

Fine, now for some more Details on the built-in Apache we need later on. The Apache has some folders and configuration-files that we will use later and that are the only ones you will mostly need to edit.

Folders

Folder / File Meaning
/Library/WebServer/Documents This is your Web-Root-Folder. Everything here will be reachable after localhost
/Users/yourUser/Sites The built-in Apache is configured to use UserDirs. This is configured to the Sites folder. So if you open http://localhost/~yourUser you will
find WebSites or other things that are placed in yout Sites-Folder
/private/etc/apache2 Well here you’ll find your user specific configuration of your Apache Installation.
/private/etc/apache2/httpd.conf This is the common config file. Here you will enable or disable built-in modules or edit your domain-name or change the DocumentRoot if you ou want to.
/private/etc/apache2/users/yourUser.conf The specific configuration for your user. Here you will add all configurations that are for this user only.

So far so good, as mentioned this is about to use SVN on your Mac. And here we go:

SVN

So you have SVN already shipped with your mac. Therefore just open your Terminal and type svn help. Hopefully you will see the following:
svnHelp

For the next step, integrating your SVN with the apache, we need to create at least one Repository.
As for me, I created a folder /Users/Shared/repository. Here are all my svn-repositories. To create a new repository go to your terminal and enter the following

svnadmin create /Users/Shared/repository/myFirstSvnRepo


As our Apache is running under the user www, we have to change the rights on the repository or change the owner of the repository as SVN needs write-access. Use one the following:

  # Change Owner
  sudo chown -R www /Users/Shared/repository/myFirstSvnRepo
 
  # to allow other access
  sudo chmod -R 757 /Users/Shared/repository/myFirstSvnRepo
  # to allow group access
  sudo chown :www /Users/Shared/repository/myFirstSvnRepo
  chmod -R 775 /Users/Shared/repository/myFirstSvnRepo

Ok, now we should integrate this into the Apache. So open the following file in your favourite Editor:

/private/etc/apache2/users/yourUser.conf

Add her the following lines:

  LoadModule dav_svn_module     libexec/apache2/mod_dav_svn.so
  <Location /repos>
    DAV svn
    SVNParentPath /Users/Shared/repository
  </Location>

If you just want one SVN-Repository reachable use SVNPath instead of SVNParentPath and specify the repository directly. Fine, lets test this. Restart your apache by sending the following command in your terminal:

sudo apachectl restart

Now point your browser to http://localhost/repos/myFirstSvnRepo. You see something like:
SVN-Initial-View

Ok, and we should create one folder in this repo so type the following

svn mkdir http://localhost/repos/myFirstSvnRepo/trunk -m "test"

If you see a Committed Revision 1. you are fine. Now for a second nice feature.

WebSVM

Download WebSVN from here. Extract the files and either copy the folder to your DocumentRoot or copy it somewhere you like and create a symbolic link in your DocumentRoot. As I prefer the latter, here is how you do it:

  # ln -s /REALPATH SYMBOLIC-LINK-NAME
  ln -s /PATH-TO-YOUR-WEBSVN-FOLDER websvn

After you’ve done this, open the Apache Conf (/private/etc/apache2/httpd.conf) and search for the following String

#LoadModule php5_module        libexec/apache2/libphp5.so

Found?
Great, uncomment this line by removing the #. Restart your Apache. Remember the command? (ok, here it is again: sudo apachectl restart)

Now browse this url http://localhost/websvn

Hmm… nice… but not what we expected, right?
WebSvn-Without-Config

But WebSVN tells us, what we are missing, so let’s go, last step, creating the config. You can simply go to your WebSVN Folder/include and copy distconfig.php to config.php. Then open config.php and find the following lines and enter your paths:

// $config-&gt;setSVNCommandPath('Path/to/svn and svnlook/ e.g. c:\\program files\\subversion\\bin');
...
// $config-&gt;parentPath('Path/to/parent (e.g. c:\\svn)');

And now try to refresh your Browser… should now look like this:
WebSVN Working

Congratulations, WebSVN is up and running!

You can now take a deeper into the config.php file, there are a lot more things to configure.

So, hope you had fun discovering how much your Mac has already available for you!

Autor: Michael Kloss
Datum: Thursday, 28. May 2009 15:26
Trackback: Trackback-URL Themengebiet: mac

Feed zum Beitrag: RSS 2.0 Diesen Artikel kommentieren

14 Kommentare

  1. 1

    Wonderful documentation, really clear and easy to follow – thank you !!

  2. 2

    [...] after writing the last post about using SVN with all your built-in tools on the mac I felt over the built-in svn version. As I had updated my svn via MacPorts and therefore set my [...]

  3. 3

    Thanks for that I wasn’t looking forward to installing and configuring mod_dav

  4. 4

    [...] von Apache2, SVN, PHP und WebSVN zusammenbaut, hat Michael Kloss in seinem Blogeintrag: Mac OS X, his built-in Apache, SVN and PHP, and using WebSVN sehr gut [...]

  5. 5

    Hi there,

    first off, thanks a lot for taking the time and writing this tutorial.

    However, I ran into a problem which I’m unfortunately not able to solve myself.

    I have uncommented the line which will load the libphp5.so, restarted apache but when browsing to http://localhost/websvn I get an error 404 Not Found.

    I would have expected to get the error message from WebSVN but just that 404. Additionally, could you please explain what paths one should enter into the WebSVN config? The paths to the repository? Or to SVN executables?

    Would be great if you could lend a helping hand here!

    Thanks again for your efforts!

    Bernhard

  6. 6

    Ok, I think I got the path that belongs to

    $config->parentPath(‘Path/to/parent (e.g. c:\\svn)’);

    According to your example this should be
    /Users/Shared/repository

    right?

    But what about the SVNCcommandPath?

    Bernhard

  7. 7

    Yes, exactly, that is the path from my example. The SVNCommandPath is ‘/usr/bin/svn’ if you switched the symbolic link or ‘/usr/local/bin/svn’. But I will update this post with the paths from my example, thanks for the comments.

  8. 8

    Thanks for the update. Any idea why I get the 404 though?

    Bernhard

  9. 9

    Hi again,

    sorry to bug you again but I can’t get it to work. I have deleted the first repository, created a new one, well, basically started from scratch but still am getting the 404 error everytime I call the URL http://localhost/websvn.

    I have the WebSVN files in my utilities applications directory /Applications/Utilities

    Here’s what I did in terminal:

    $ svnadmin create /Users/Shared/repository/sampleRepo
    $ sudo chown -R www /Users/Shared/repository/sampleRepo
    $ sudo chmod -R 757 /Users/Shared/repository/sampleRepo
    $ svn mkdir http://localhost/repos/sampleRepo/trunk -m “justTesting”

    Committed revision 1.
    $ sudo pico /private/etc/apache2/httpd.conf
    $ ln -s /Applications/Utilities/WebSVN websvn
    $ sudo apachectl restart

    I do see my sample repository in my browser it’s just that websvn is not mapped correctly to the URL http://localhost/websvn.

    Any ideas?

    Thanks in advance!

    Bernhard

  10. 10

    Ok, please disregard. I’m just plain stupid :)

    For anyone interested (although it’s embarassing): I didn’t create the symlink in the server’s document root…

    Anyway, thanks for your time!

    Bernhard

  11. 11

    You’re welcome, sorry, had a lot of work to do, so I could not answer as soon as I wished…
    but nice to read that you have finally made it.

    Michael

  12. 12

    Excellent post, helped me set up my svn (didn’t manage to get websvn up yet though since it gives us a couple of warnings on the webpage and nothing else)

  13. 13

    Hello, Very good tutorial. But the easier way to setup a complete versionning environment with apache, subversion and Trac (edgewall), you can try SPMPT. It’s a package which include Subversion server, Trac, python and mod_python. It’s works out of the box.

  14. 14

    Thanks for the tutorial, gave me the help I needed to get SVN going on OS X!

Kommentar abgeben