For the new year, we decided to take the plunge and migrate from our old friend, Windows server 2003 with IIS 6 over to Apple’s Lion Server on a shiny new Mac Mini with 8 GB of RAM and a quad processor. The conversion from Microsoft’s to Apple’s server operating system is not too bad, though much is different between the two systems. This article discusses some issues and resources for reference for those that are new to Lion.
MySQL
So, first off, we host web sites using IIS 6. Some of our sites utilize WordPress, which means that we use a back-end mySQL database, and we also run php. Neither of these applications were originally written for Windows, so both run ok there, but with issues over time. Lion, of course, underneath is really a flavor of Unix. This makes mySQL and php happy. And, the nice people at Apple even have pre-loaded php onto Lion server for you. However, you will need to install mySQL on your Lion box ahead of time for this conversion. Here is a link to downloads for mySQL. Here is also a very good walkthrough of installing and verifying your php, Apache, and mySQL installations.
Also note that with mySQL that there are three separate installation packages that you have to run – the main one is called mysql-5.5.19-osx10.6-x86_64.pkg (yes you want the 64 bit version of this application, not that crappy 32 bit thing you were running on your sad Windows server), but you also need to run the MySQL.prefpane and MySQLStartupItem.pkg so that you can get to this in the Preferences Pane and have it set to automatically run when you reboot).
Remote Access
Oh, but wait. You might be wondering how you get into your Lion box in the first place to do all of this stuff. For Windows people, we are used to the whole Remote Desktop thing (or if you are truly desperate, breaking out that spare monitor, mouse and keyboard and plugging them into your shiny new server). Don’t worry: Apple has some tools for the sysadmin’s remote access. If you are using, perish the thought, a Mac workstation or laptop, you can use Screen Sharing. To connect for the first time, you authenticate to the Lion server with a blank user name, and the password is the Mac Mini’s hardware serial number. From there, you will walk through the initial setup steps (like giving your box a network name, and the like). Apple also shows you the other couple of options here (because, no, you are not the only person to want to access your box remotely).
The Server and Server Admin Apps
Ok, so now you have you setup the box and have installed mySQL, php and your Apache server. In case you don’t know where Apache is (because you like to click a play button in the services applet in Windows), there is an application in Lion aptly called, “Server.” Within that is a big “on/off” button for the web server that you can click to get Apache running. By the by, there is a more sophisticated set of server tools called “Server Admin” that all the cool kids have downloaded to their Lion server. (Click here to download that). You can also do this stuff at the command line in the application called “Terminal” which is in the Utilities group of Applications. I won’t get into the command line in this article, though there are a number of good references out there if you like that kind of thing (and sometimes, that is the best way to do something!).
Setting Up the Web Root Location
So you now have some setup choices to make, like where you are going to put your web site directories for the web sites you want to host on your Lion. I’d say put them somewhere isolated, perhaps in their own little folder in the root where you have a way to limit access. In Lion’s world, this will be a location where “Everyone” will have access, because, you know, the world wide web can come to your little box and see the contents. I’d guess that putting all this stuff in the middle of your server’s system files would be a bad idea. If you bought a server with two harddrives, and you aren’t going to mirror the one to the other, you might use the other disk to locate your web files. Or you could create a partition from the free space and isolate your web files from the rest of the server’s files. Do what you need to do here.
Local DNS for Dev
Once you get things setup, you can then copy your files from your production IIS server over to their new location on the Lion server. By default, Lion is running DNS for the .home domain (the equivalent of the .dom domain in Windows – local only). However, you can’t configure DNS with the “Server” application. Instead, you need “Server Admin” (aren’t you glad you already downloaded this and installed it? Oh, you didn’t do that yet. Well, come on.) DNS lives there (or you can do your unix command line voodoo if you are in to that sort of thing). The home domain is configured and your server is in it. If this server is an internet DNS server, you could configure this server to run DNS for an internet domain here. However, if you want to test your migrated web sites (why would anyone test anything before putting it into production?), you can configure your names here.
Setting up your Web Pages
Once you have done this, you can then declare your new sites in the “Server” application in the Web application. You add a domain at a time (like test1.home, test2.home, or something lame like that), and tell the web service the location of the files for each site. You’ll note that the service doesn’t ask you what the default document is for your web site; I think it is assuming that the default page is index.htm (or index.php if you are running php). If you have a funny named default page, you will probably have to edit httpd.conf to modify the line for DirectoryIndex as follows (or you can just rename your page to index.php/index.htm. I know, I know, that is too much effort):
#see below, replacing the text in square brackets #with your unusual default page DirectoryIndex [yourcrazyindexpagename].[crazyextension]
Now, you are going to chuckle a bit at this point once you have added your multiple domains into DNS and you configure your multiple web sites, because Lion only will serve up one. I don’t know why Lion ships this way. But there is a solution. Edit httpd.conf and add some entries for multiple domains as noted in the article. You can also alias subdomains if you want, like http://www. The downside to this is that if you have to change IP addresses later, you will need to edit internet DNS, add these addresses to your Lion server’s network settings, and then come back here and edit httpd.conf. And for some reason with Lion, Apple has taken away a GUI configuration for Apache for advanced things like this. Maybe someone out on the interweb will write one for those of us that are sad and don’t like trying to change these oddly named text files in the System directory. Also, even more sadly I note that the Snow Leopard version actually had a GUI to do this and Apple took it away from us sysadmins. I now wander alone in the desert, cast out by Apple.
Ok, I’m out of cheese so I will stop whining. Needless to say, Apple has its problems too. If they had everything figured out, we wouldn’t know what to do with ourselves and would probably not have a fabulous job in IT.
FTP
By the by, you might want to configure ftp access to your web server. Here is an article to do that. (If you are going to allow ftp access, this is yet another reason to isolate your web files from the rest of your server files). FTP access might be helpful if you are going to upload and download files from the web server periodically, and you can stop and start the service if you want to further limit access. Probably best to also not use root as the user to access files by ftp (or just post your social security number, date of birth, license number, bank account numbers, and all your passwords to all of your accounts to the internet – you know, whatever).
Setting up new MySQL Databases
So, just a few more things to do in order to get your web sites up and running. If you are using WordPress, you will want to export the tables in your production mySQL database to your new Lion mySQL database. Ahead of this, you can get ready by creating blank databases on the Lion mySQL server with the same names as in production. This can be done by logging into mySQL from Terminal, and running the commands:
create database [databasename];
grant all privileges on [databasename].* to "[webusername]"@"localhost" identified by "[password]";
flush privileges;
In addition, if you have already copied the web files to your Apache server, and configured Apache to serve up these pages, you should be able to run the initial WordPress setup on your Lion box (won’t impact production), and you should be able to get into the wp-admin section and check out your plugins and themes to make sure they are good before importing your data into your mySQL database. This will create blank tables with the default data of a default WP install – these will all get overwritten in the next step below.
Export/Import MySQL Database Tables
Happily, mySQL for Windows comes with an application you can use to export your database into a single .sql file that you can then execute in mySQL to import the tables and their data. In Windows, the program is called “mysqldump.exe” and it is installed in Program FilesMySQLMySQL Server 5.0bin. You run this program at the dos prompt. With the proper syntax, it will create a .sql file where you tell it to, which you can then use to import all of your data and tables into your fresh mySQL install on Lion. Here is an article on the syntax for using this function.
Once you have your .sql file for your database, and you have copied it to your Lion server, you can use mysqlimport from within the Terminal application in order to import these tables and data into the appropriate shell database you have for your WP site. I’ve found that this process works better than using the Export/import features within WP admin, particularly if your site has custom tables for a particular widget or plugin. My site, for example, had a customized menu that didn’t work in the new site until I just exported all of the data and tables and imported into the Lion install. You can also simply execute a command at Terminal to process the .sql file that is created by exporting using mysqldump that looks like this:
mysql -u root -pYourPasswordHere NameOfYourDatabase < /locationofyourMySqlExportFile.sql
Once you run that command, mysql will import and overwrite whatever is in the shell database that you have on your new mysql server. Of course, if you have anything in there that you want, it will be overwritten.
So that’s it. Ha ha. This is not a thing you do in a half an hour, even for an experienced sysadmin. But this is a perfectly reliable way of hosting web sites. Lion’s not bad, mostly because you are just running Apache, php and mySQL, all of which work pretty well and have been around for quite a while. But Lion is cute and cuddly. For the most part, as long as you avoid those fangs, claws, and don’t get squished under the command line. Happy computing!