Archive for the ‘Mac’ category

Snow Leopard and SCPlugin

February 4th, 2010

Snow Leopard BoxI recently upgraded my laptop to Snow Leopard and have, as of yet, not been wowed by it. Whilst in conversation with a friend I defended the OS and demanded that the latest release was not a Service Pack as he suggested and is an entirely new OS. I installed it and expected the world to tremble as I booted up, I wanted to see an instantly noticable improvement for the ‘average’ user such as myself.

No such luck

Since installing the update I have not noticed an increase in speed as was anticipated and to make things annoying I have had to completely reconfigure my local web server and find a new Subversion application to use. It took me about a week to recover fully from the upgrade. The laptop has been sadly crashing (albeit not catastrophically) once a month or so.

On the bright side though, and there is a really big bright side, my laptop now sports the latest version of the OS. OSX is still as pretty and user friendly as it ever was and, after a month or two of use, you really start to notice the differences and little tweaks that have been added. I had problems before the upgrade with deleting ‘locked’ (?) items from my trash (there was a keyboard shortcut I now know) but now there is a handy dialogue box that asks about it on emptying the can. There are a few other stylistic changes I notice although I am aware that the major change is the extension of integration of Cocoa which is nice (apparently).

How to recursively remove .svn directories

July 23rd, 2009

Regular readers may have clocked onto the fact that I use Subversion. Well the way it works it to keep a hidden set of directories within your checked out repository. It uses this to track any changes etc.. Each directory is called ‘.svn’ and is within each and every directory and subdirectory you have.

The problem

Now I know I am not alone in saying that when you want to upload the files to a remote server you have to do one of two things

  • Upload the files and .svn directories to your server which is likely to take twice the time and twice the disk space
  • Make a separate local copy of your files and then remove the .svn directories one by one.

I prefer to take option two although in recent months I have taken on the former through sheer laziness. I decided to look for a solution and found my answer…

The answer

For windows machines you need to create a secondary copy of your files to upload, this means it won’t wipe out your local repository files (the ones you want to keep). Next, create a ‘.bat’ file (batch file for executable scripts). The simplest way to do this is to open notepad and doing File > Save as > remove_svn.bat after copying in the code below. It needs to be saved in the root directory of your repository copy. This is important if not it will recurse all directories below the one it is placed in.

for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *svn') do (
  rd /s /q "%%i"
)

I have done all the hard work for you on this one.
Just click the following link:
Remove SVN Files (Windows) (82 bytes)

For Macs and other Unix based machines you need to do something similar. This time we simply run a command on the shell (or create a shell script out of it). Again this must be placed in the directory you want to recurse through.

find . -name .svn -print0 | xargs -0 rm -rf

The Credit

Credit for these snippets goes to the following sites. Whether they were the original authors or not I don’t know but credit where credit is due etc..

Mac version – http://snipplr.com/view/201/remove-all-svn-directories/
Windows Version – http://bluespark.tumblr.com/post/23853870/remove-svn-subfolders-on-windows-xp-vista

Subversion server sertup and configuration for dummies

March 7th, 2009

For those of you that don’t know what it is, Subversion (or SVN for short) is a popular open source version control system used all over the world. Previously people have used other systems like CVS however SVN seems to now be the standard. Firstly here is a little information about clients, skip past it for the server section.

Clients

An SVN client is (obviously) a piece of software that allows you to interact with a central ‘repository’ (or repositories if you work on version controlled files from multiple sources). They facilitate communication and interaction with the SVN server, actions like ‘checking out’ repositories, ‘committing’ your changes and ‘merging’ in other people changes to your own local copy.

This might be a little basic for this tutorial so I shall move swiftly onto client software. The Subversion project is hosted by tigris.org who release the source code for Subversion itself. Volunteers port the code onto different platforms. I can only recommend the software I have used to they are as follows:

  • TortoiseSVN – A free and very popular windows client with Explorer integration
  • SCPlugin – A free, yet buggy, Mac client whose advantage is integration with Finder
  • Zigversion – A Mac client which is free for personal use. No Finder integration (to my knowledge)

Server

This section will detail how to install and configure a Subversion repository on a Unix based system. It assumes that the ‘yum’ package is installed however for those of you who don’t have it or are unaware of what it does then please read Valerie Aurora’s Linux Basics guide where there is a helpful section called ‘Finding and Installing Software’.

First things first, install subversion and its dependancies using yum. This is a nice one liner to get the job done for you.

yum -y install apr apr-utils http-devel mod_dav_svn subversion

Yes it was that easy! One command just installed Subversion and it’s dependancies (let me know if i have missed any). The next thing to do is configure a new repository and setup access using htaccess.

The first thing to do is to create a new repository. For this tutorial I will be using ‘/usr/local/svn’ as a place to store repositories however you can put it anywhere you like on the file system.

Firstly, create the directory ‘svn’ using the mkdir command (within /usr/local/ :) ) and then chown it recursively to apache:apache. Move into it and use the following command to set up your first repository (which in this case is called test but obviously it can be anything you choose):

svnadmin create test

The above install process also adds a new config file into the apache conf.d directory (/etc/httpd/conf.d/). The config file is called subversion.conf, within which is an example block to uncomment to set up http access to the respository and set up htaccess permissions.

The most basic example of what to put in this file is below. It will set up a virtual subdirectory of your website so try to either make the name unique or not use the name on any of your sites on the same server. This example will set up a subdirectory called ‘svn’ so if your site is http://127.0.0.1 then your Subversion path will be http://127.0.0.1/svn

<Location /svn>i
	DAV svn
	SVNParentPath /usr/local/svn
</Location>

After making any changes to this file (and any file served by apache for that matter) then you must restart apache for them to take effect. You can then view your repository in your browser and assuming you see a blank page with something that resembles ‘Revision 0:’ or the name of your repository as a link then you are ready to start using it.

For those that run multiple sites using VirtualHost directives then the above section of code can be included within one as per the example below which should create access to Subversion on a site named ‘svn.localhost’.

<VirtualHost *:80>
	DocumentRoot /usr/local/svn
	ServerName svn.localhost
	<Location /svn>
		DAV svn
		SVNParentPath /usr/local/svn
	</Location>
</VirtualHost>

Access Control

You may want to configure access to your repository allowing only certain people and groups to have different levels of access. Subversion allows a couple of ways to do this but the most common seems to be htaccess. Configuring this is more or less the same as configuring htaccess. See the example below:

AuthType Basic
AuthName "Subversion"
AuthUserFile "/etc/httpd/conf.d/svn_passwd"
Require valid-user

The above 4 lines can be slotted in beween the ‘<Location>…</Location>’ tags. It tells Apache not to allow access to anyone except those that have their crudentials within a file (in passwd format) at the location specified. The ‘AuthName’ line is optional, all it does it put a name onto the box that pops up asking for login information.

The file that I have called svn_passwd can be situated anywhere on the system however it would be sensible NOT to put it anywhere that can be served by any of your websites. Generate the ‘svn_passwd’ file using the following command if it doesn’t already exist.

htpasswd -cm /etc/httpd/conf.d/svn_passwd admin

You will then be prompted for a password for the user and once entered (twice?), after Apache has been restarted you won’t be able to get access to your repositories without those details. The name of the user you choose for this doesn’t have to be a system user and if it is (like admin for example) then the password you use doesn’t have to match its counterpart.

After restarting Apache again you will be only be able to access your repository with a correct set of credentials defined in the htpasswd file.

That concludes the tutorial for now. I hope that I have given you a good round knowledge of Subversion server setup which in turn will enable you to easily run your own version control system. There will likely be snags along the way, there always are. If in doubt then Google it! or ask me (who will likely Google it anyway :) )

Resources

http://svnbook.red-bean.com

Setting up a PHP/MySQL Local Development Environment on a Mac (doing it properly)

February 25th, 2009

This tutorial will show you how to setup a Local Development Environment on your Mac the proper way (not using MAMP or XAMPP). I will also give examples of some of the software you can use for your day to day development including an IDE, SQL Browser and Subversion client.

Since OSX Leopard (I think), Macs arrive bundled with a local Apache server and a PHP install. The only real missing thing are MySQL and turning it all on. It’s not quite as easy as that as you are about to see but follow the instructions below and you should be up and running in half an hour (depending on typing speed ;) )

Why not use a 3rd party product?

You may ask why not use XAMPP or MAMP… This is entirely down to personal preference but seeing as Macs are bundled with most of the software required for local development, it seems silly to just ignore all that and duplicate all that functionality.

For those of you that would prefer the easier route then use one of the following links and download the files on their sites as instructed.

So… For those of you NOT taking the easy way out

Download the software

The first step is to download all the software you will need which in this case is simple, get the MySQL DMG Package from http://dev.mysql.com. If you prefer not to trawl their site then use the following link:

To save having to compile from binaries, MySQL have released a version in a Mac friendly DMG format. Just double click the file when it downloads and then it should be installed to the appropriate place.

Configure Apache

For this section you will need to be logged in as a user with Administrative rights on the computer (or someone in the ‘sudoers’ file). At this stage it would be wise to backup the file we are about to edit.

Open your Terminal (which lives in /Applications/Utilities/) and type the following

sudo vi /private/etc/apache2/httpd.conf

You will be asked for your password again to confirm that your user can use the ‘sudo’ command and then be entered into ‘vim’. You can substitute ‘vi’ for any of the other terminal based text editors, pico, nano, etc..

Within the file you need to comment a line which will enable PHP to function on the computer. Find a large block of lines that each start ‘LoadModule’ and in the list you will see a line that looks like:

#LoadModule php5_module      libexec/apache2/libphp5.so

Remove the preceeding hash (#) character.

Next we need to tell it to look for the index.php file when a root url is given and no filename (http://www.google.com as opposed to http://www.google.com/index.php). There will be a block of code that looks something like the following:

<IfModule dir_module>
    DirectoryIndex index.html index.htm
</IfModule>

Add index.php to the list of files on the middle line so it looks like the following:

<IfModule dir_module>
    DirectoryIndex index.html index.htm index.php
</IfModule>

Save and close the file. If you are not logged in as an administrator and didn’t use the ‘sudo’ command then you will likely see an error telling you the file is read only and cannot be saved. In this case you need to go back and do it all again using ‘sudo’.

We will need to start/restart Apache now to make sure that nothing is broken. Firstly though, run a test on the settings through Apaches internal validator:

sudo /usr/sbin/apachectl configtest

If you see no errors then run the next command which will restart Apache. If there are then revert httpd.conf back to your backup and start the process of editing it again.

sudo /usr/sbin/apachectl restart

Test it’s all working

We can now test that PHP is functionning by creating a test PHP file at the following location:

/Library/WebServer/Documents

You should see a number of files and images including an index.html file. Create a new file called index.php and put the following line inside:

<?php phpinfo(); ?>

Open your browser and navigate to:

http://127.0.0.1

Assuming you don’t see an apache welcome page or a server error then everything is working so far. If you see the apache welcome page then it might be a priority issue in the file naming. Just go to the place where you saved your ‘index.php’ file and delete the ‘index.html’ file (and any other files if you aren’t going to use them for something). On trying again it should show your file.

That concludes the main part of the tutorial. You should now have a local Apache server that supports PHP and MySQL by default. If you are not interested in software or running multiple local sites (virtualhosts) then thanks for reading!

For the rest of you…  Read on

Adding .htaccess Support

By default there isn’t a standard .htaccess file for this. It’s a simple fix however, just add the following code to your httpd.conf file and restart Apache as previously mentionned. You can then create .htaccess files in your web servable directories to do anything you need them to.

AccessFileName .htaccess

Multiple sites

If you would like to run more than one local site then you would need to set up Virtualhost directives in your httpd.conf file. First go to the bottom of the file and add the following line.

NameVirtualHost *:80

Then you can add the following block for as many local sites as you want to run.

<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents/wordpress"
ServerName wordpress
</VirtualHost>

The above block will look for a site called ‘wordpress’ at the path specified (it can be anywhere on your system).  You can specify several other options within the VirtualHost block and it has been thoroughly documented elsewhere. The most useful extra thing to add is another AccessfileName line in case you wanted to call it something else for example. Remember that you will need to restart Apache after you make any changes to the http.conf file before any of your changes can take effect.

You may have noticed that I called the above site ‘wordpress’, this assumes there is a local site by that name. Without adding the next part, none of it will work. You need to edit a file called ‘hosts’ which lives at ‘/private/etc/hosts’. This contains a number of lines that follow a standard format. You will need to add a new line to the file for each site you want to add. For my example I would need to add the following line.

127.0.0.1    wordpress

You don’t need to restart apache after editing the hosts file, it will all just work.

Recommended Software

Subversion
Tigris.org, the people that make the popular Windows software Tortoise SVN have written a free SVN client called SCPlugin. It integrates Subversion controls into Finder making it easy to work with version controlled files without using a dedicated application. It’s also free!

I have also heard good things about Zigversion which is free except for commerical use. Worth a look if SCPlugin is a little flaky.

IDE
I personally have used numerous IDEs over the last few years but settled on Eclipse (PHP version) more recently. Like alot of ported software, not everything works on the Mac version however it nicely does the trick for me. It handles projects and basic autocomplete if you use it. Again it’s free! which helps somewhat.

As for paid software I used to use Zend on the PC however it was very slow and didnt recover well when the computer was coming out of hibernate mode. It does everything Eclipse does however and not bad for the price. The new version is based on eclipse anyway.

A friend of mine is very much in love with a new IDE written specifically for the Mac called Coda. It isn’t free but at $99 it is apparently worth the investment.

MySQL Tools
At work I use Navicat and am very pleased with it. Everything works and it’s very fast. Nothing has changed on the Mac version so it is still my favourite. It isn’t free but worth the money and they have a 30day free trial if you need convincing.

If you are after free then I would recommend MySQL Query Browser. It does what it says on the tin and most importantly allows you to throw the pile of garbage that is PHPMyAdmin in the bin if you haven’t already done so. It’s available from MySql along with some of their other useful tools like MySQL Workbench and MySQL Administrator.