How to use a Mac mini as a private web development server
Tucked away in a dark corner, quietly gathering dust, was a Mac mini. We'd bought it a few years ago to replace a Mac G3 Blue & White, and for around 6 months it served as our primary development machine in the business, before being replaced by a far more capable G5 tower. The Mac mini was so cute, and in perfect working order, and it seemed a shame to leave it on its own. So, inspired by Apple's recent announcement of the Mac mini Server (basically a Mac mini without a CD drive, specially designed to be a server) and various companies specialising in Mac mini dedicated servers, we decided we'd have a go at making our little Mac mini into a server too.
Why? Well, it means we can develop our web sites from anywhere on our network, knowing that all the project files are kept centrally in one place. That makes it safer and easier, though it has taken almost all day to get working. And that's why we're writing this guide - to help anyone else thinking about doing the same thing.
The goal: a fully functional web server running Apache, PHP and MySQL, which is accessible from any computer on the local network but not from the outside world.
Setting up the operating system
We are using a 1.42Ghz PPC Mac mini, running Mac OS X Tiger (10.4). Nothing special, not even particularly powerful. But that doesn't matter.
First of all we get it connected to the network. We've connected it straight to the router with a CAT5 cable, ensuring a reliable connection. Here's an important setup note - make sure it's using a fixed IP address! You can do this by going to System Preferences > Network > Configure, go to the TCP/IP tab and from the Configure IPv4 drop down select 'Using DHCP with manual address'. (Actually, we didn't do it that way, we fixed the IP address from the router end, but not all routers support that option)
Now for some server-friendly housekeeping.
- Turn off the screensaver (saves unwanted processor usage).
- Make the desktop background a solid colour rather than an image.
- Turn off the power saving features - make sure the hard disk doesn't get put to sleep, nor the screen (though ours hasn't got one attached, but it ensures that everything ticks along normally).
- Turn on Apple Remote Desktop in the Sharing options, so we can access the machine remotely and not need a keyboard, mouse or monitor attached to the mini.
- Mute the sound.
Installing Apache, PHP and MySQL
Although Mac OS Tiger is able to natively run Apache and all the other web services that go with it, we found it a little tricky trying to get all of that working, so we eventually opted to install MAMP instead. MAMP is completely free and gives us Apache, PHP, MySQL, and various tools like phpMyAdmin too, and we won't be needing the extra functionality of the non-free MAMP Pro. Just download the .dmg and drag the folder to your Applications folder. We dragged the MAMP program down onto the dock too for easy access. Run MAMP and you'll get a little control box come up, and hopefully you should get two green lights come on telling you that Apache and MySQL are both running.
Now to set up MAMP. Click on the Preferences button on the MAMP control panel. We made sure that MAMP was set to start and stop the servers when starting and quitting MAMP respectively (those are the default settings, so just leave them ticked). We unchecked the "Check for MAMP Pro when starting MAMP" option, simply because we know we're not using MAMP Pro. We also unchecked the option to open the default start page.
In the Ports tab, we changed the Apache port to '80' and the MySQL port to '3306'. Those are the public-facing ports, which means that people on the outside will be able to use the server.
In the PHP tab we told MAMP to use PHP 5, and set the Cache option to 'eAccelerator', but that last setting is optional.
Click OK and Apache will restart. Mac OS will ask for your password; this is because we're using port 80, which is a special port, so enter your password. We'll sort out a workaround for that later on, so that you don't have to enter your password every time you restart the server!
Now if you go to http://localhost/ you should find yourself looking at a basic page telling you that everything is working. At this point everything is still local, and no one other than you will be able to see anything, but we'll come to that in a minute. Right now you can just sit back and marvel at how you've just set up a working web server running Apache, PHP and MySQL. Put a test file in /Applications/MAMP/htdocs/ and look at it in your browser just to make sure.
Making the server visible to the network
From here on in it starts to get a little more complicated. For starters, go back to the Sharing options in the System Preferences, and make sure Web Sharing is turned off. Web Sharing is the built-in version of Apache, which if turned on will also be trying to use port 80 and will get in the way. Tempting as it is, make sure you're using MAMP instead of Web Sharing.
Of course, turning off Web Sharing also turns off the Firewall settings, meaning that all incoming requests to port 80 are blocked. We found a post by Rob Wilkerson about making MAMP publically accessible, which came in very handy. His article does a good job of explaining the whys and wherefores, but I'm just going to quote the step-by-step instructions he gave (starting with the Firewall tab open in the Sharing preferences):
- Click the New button next to the services list
- Select Other in the Port Name drop down list
- Enter 80 in the TCP Port Number(s) textbox
- Leave the UDP Port Number(s) textbox empty
- Enter HTTP (or any other descriptive text) in the Description textbox
- Click OK
That sets up a custom firewall setting that allows port 80 to be active, meaning that other people on the network can get to our MAMP-powered Apache. Give it a try from another computer, using the local IP address of the server computer (probably something like http://192.168.0.x/ - this is the fixed IP address you specified earlier for the server). If everything has gone according to plan, you should see whatever file is in the /htdocs folder of your MAMP installation.
Now, you may be thinking "what about the MySQL port, doesn't that need to be listed there too?" We thought that. We wanted to be able to remotely access the MySQL databases using Sequel Pro, so we put '80,3306' in the TCP port number box above, which would allow requests to both those ports. However, we found we were still unable to connect to it, and we abandoned that idea in the end. You can still manage the databases using phpMyAdmin though, which is bundled with MAMP, so just go to http://192.168.0.x/phpMyAdmin/ and it should load up (note the capitals in phpMyAdmin - we found that it was case sensitive).
You may also be thinking "isn't my computer now accessible from the outside world too?" Not necessarily. If you are behind a router (which most people are, unless you have a full-on network already, in which case you wouldn't need to be setting up a Mac mini web server) then it's probably set up to reject any incoming requests, so all your computers should be protected. It's worth checking though, if you can, just to make sure, but in most cases routers have to be brutally persuaded to let incoming port requests in, and even then they need to be directed to the right local computer, so you should be fairly safe at the moment.
Enabling file access on the network
Now that the server itself is working, we need to be able to transfer files to it easily and reliably. In System Preferences > Sharing, make sure Personal File Sharing is ticked. That will make certain files accessible to other computers on the network. As well as our trusty Mac mini we also have a G5 tower here, which is where we normally do our development, so that's where we'll be transferring files from. If everything is set up normally, if we open up Finder we should find our Mac mini server sitting there on the network, ready for us to connect to it. The G5 is running Leopard, incidentally.
Now here's an important bit (which took us ages to work out). When you connect to the server, make sure you connect with a proper user account rather than as a Guest. If you connect as a Guest you will be able to access some areas of the server but not all, and there are all sorts of problems with permissions that arise there too. We spent ages trying to figure out why the files we'd transferred couldn't be accessed by Apache, and it turned out that the files were owned by 'nobody', which meant that neither the G5 nor the mini could actually use the files! By logging in as the active user on the server, you ensure that the files are properly owned by the server, meaning it can read and write the files and serve them up as you'd expect.
Making the MAMP document root accessible
By default MAMP has its document root at /Applications/MAMP/htdocs/. That's fine if you're using MAMP on the same computer you're developing on, because you have access to everything. But on a server you don't have access to the Applications folder, so you need to tell Apache to look elsewhere for those files. We're going to make use of the Sites folder in the home folder, which is what Mac OS would have used if it were using the built-in version of Apache, but you can choose to put your files anywhere you like (within reason).
Open /Applications/MAMP/conf/Apache/httpd.conf in your favourite editor (I use Smultron, which is sadly no longer in development, but there are plenty of others out there). This is a huge file, but most of it is made up of comments, so don't let that put you off. This is all the setup information needed to run Apache, so don't tinker with anything you're not absolutely sure about.
About a third of the way through the file you'll find a line that looks like this:
DocumentRoot "/Applications/MAMP/htdocs"
We changed that to:
DocumentRoot "/user/user_name/Sites"
obviously changing 'user_name' to the username of whatever account you'll be using on your server. That tells Apache where to look for its web files. A few lines later you'll also find a line like this:
<Directory "/Applications/MAMP/htdocs">
Change that location too. Save the file and close it. To make those changes take effect you need to restart Apache, so go back to MAMP and Stop and Start the servers. If you now go to http://192.168.0.x/ you should see the default index.html file in your Sites folder, showing that MAMP is correctly finding your web files.
Starting the server automatically
As we're setting up our Mac mini as a server, we don't want to pay any attention to it if we can help it. It should just be there, ready to serve up our web pages when we want them. Here we made a bit assumption, based on our particular working hours - we don't need our server on 24-7. You might do, so feel free to skip this bit.
In System Preferences > Energy Saver, click the Schedule button. We told it to automatically power on at 9am and turn itself off again at 7pm, both for Weekdays only. You may want to adjust those hours to your liking. The Mac mini is already very power efficient, being made mostly of laptop parts, but turning it off overnight is no bad thing. We made sure we muted the sound earlier, so when it boots up it won't chime and surprise anyone who happens to be in the room when it magically comes to life!
Starting MAMP automatically
By setting MAMP Apache to use port 80, Mac OS X requires us to enter our password every time the server starts or stops. This isn't a bug, it's a security feature, and in most cases it's the way we should prefer the operating system to protect us. But in the context of a web server it's an annoyance, possibly even a failure if it doesn't start up. Thankfully, thanks to an article on StringFoo about starting MAMP silently, our problem can be relatively easily solved.
The technique involves creating two .plist files and placing them in the /Library/LaunchDaemons/ folder of the server. Refer to that article for details. Basically what this does is start the Apache and MySQL servers when the server starts up, bypassing the MAMP control panel, and thus also bypassing the need for you to enter a password. Make those files, copy in the code from the article above, restart the computer, and Apache and MySQL will start up automatically. You'll notice that MAMP doesn't start up, but don't worry, it's still doing its job, and you can test this by trying to access a file on the server via the browser. If you do need to change a setting in MAMP, or stop the server for any reason, just open up the MAMP control panel again (it'll ask for your password) and carry on as normal.
.htaccess files
Now, if you're used to dabbling with Content Management Systems like MODx, WordPress, Joomla, CMS Made Simple, etc.... then you'll be wanting to use an .htaccess file to give you friendly URLs and redirections. Since we're using the same Apache as is used on normal web servers, this is right there out of the box. You just need to find a way of creating those .htaccess files.
By default Mac OS X hides files beginning with a full stop, as those are hidden system files. If you try to rename ht.access to .htaccess it will probably give you an error and tell you off for trying to create a system file. Fair enough, in most cases you wouldn't want to. To make Mac OS X allow you to create hidden files, you first need to tell it to show them in Finder. We find Tinkertool a fantastic little program, which gives us quick access to a whole load of hidden features and settings in the operating system, one of which turns off hiding of system files. Tick that box and click 'Relaunch Finder', and Finder will relaunch itself showing system files. Now if you go to the network drive in Finder where the server files are you should be able to create a .htaccess file. Just remember to go back to Tinkertool and hide those system files again, otherwise you run the risk of changing things you really shouldn't, not to mention having a whole load of system files making everywhere look messy!
The final result
After all that, we finally have a Mac mini set up as a web server, turning itself on in the morning and off again in the evening on weekdays only, serving up our web sites only to the local network, making use of Apache, PHP 5 and MySQL 5, with files accessible from another computer across the network via Finder, with MySQL databases being managed via phpMyAdmin, all with friendly URLs and the potential for plenty more customisation via the Apache httpd.conf file. We're happy with this setup, as it provides everything we'll need for now, and we hope this article is useful for others too. And if you notice a glaring security hole or a potential problem, please do get in touch and let us know!
This post was originally published on www.matthewdawkins.co.uk.
Copyright © Matthew Dawkins 2009
About Matthew Dawkins
Matthew is a web designer based in Somerset, UK. He has a passion for CSS and design, and runs his own web design business.







Write a comment