Lion web server with PHP and MySQL without MAMP

I’ve almost always used MAMP (Mac, Apache, MySQL, PHP) to test and develop websites locally before publicizing online. It’s a pretty simple and straightforward solution when you want a local temporary web server that you can turn on and off as you please. Though you can get the same local web server using already built in features on your Mac (which in fact uses Apache, like MAMP). The setup is maybe a bit more advanced than the installation of MAMP but knowing how to, for example, enable PHP on the pre-installed OS X web server can be good to know when you have to write some quick changes at your parents house.

This guide aims to describe how to start the Mac OS X web server, enable PHP and install and configure MySQL on your local Lion (10.7) installation.


1. Start the built-in web server

In order to start the default web server on your system, you’ll need to activate it from the System Preferences. You can do this from the terminal app too but I’ll show how to do it the visual way.

  1. Chose System Preferences from the Apple Menu ().
  2. Got to Sharing.
  3. Check the Web Sharing box.

You’ll notice that the righthand part of the window changes, showing two links: one with your username in it and one with only the address to your computer. To check that the web server is started you can click on the link with only the address. A browser window should pop up directing you to the address and show the text “It works!”. This webpage is opened from the computers web folder which you can find at /Library/WebServer/Documents

Theres also the possibility to create individual user web directories. I prefer to have this enabled since I can conveniently find my personal user web directory at ~/Sites In Lion, this isn’t enabled by default so you’ll have to activate it for every user that wants it:

  1. (Optional) Click the big Create Personal Website Folder to enable your user website at http://youraddress/~username

2. Enable PHP

Per default PHP isn’t enabled in the built-in Apache installation but it is installed. To verify your PHP version you can open up the and write php -v

To enable PHP you can, in the, follow these steps:

  1. Write sudo pico /etc/apache2/httpd.conf and enter your account password.
  2. Use the arrow keys to navigate down to the line #LoadModule php5_module libexec/apache2/
  3. Uncomment the line by removing the # symbol.
  4. Press control+x and then y followed by Enter to save
  5. Restart Apache by typing sudo apachectl restart

You can verify that PHP works by creating a document in your ~/Sites folder named test.php with the contents <?php phpinfo(); ?> and navigate to http://youraddress/~yourusername/test.php with a web browser. If a, oh so pretty, test page with a bunch of information about PHP shows up you’re good to go. Note that you have to create the personal website folder (as described above) for this to work. If you didn’t, just use the computers web folder and skip the username in the address field when browsing.

3. MySQL

Lion in fact ships with the database PostgreSQL and you can view the installation version by writing psql --version in the However, since for example the publishing tool WordPress as of the time writing only supports MySQL, the PostgreSQL installation is to no help.

I’ll describe how to install MySQL using the ‘official’ packages. There’s many other ways to install MySQL, one of my personal favorites is by using Homebrew, especially if you want other packages on your system. The ‘official’ installation is more straight on subject though and you’ll can get an optional prefPane and other nifty features like startup scripts:

  1. If you haven’t already, go to the MySQL download page and get the latest x86, 64-bit .dmg version for Mac OS X (as of the time writing this is 5.5.18 and the title says Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive but it will work just fine on 10.7 Lion).
  2. Mount the DMG-file (double-click on it) and start the setup through, in my case, mysql-5.5.18-osx10.6-x86_64.pkg found on the image.
  3. Follow the onscreen instructions to complete the installation.

Now MySQL is installed and you can use the command sudo /usr/local/mysql/bin/mysqld_safe & to start the MySQL daemon and shut it down safely with sudo /usr/local/mysql/bin/mysqladmin shutdown

3.1 Add MySQL to the PATH environment variable (optional)

The commands listed above are long and hard to remember so I recommend adding /usr/local/mysql/bin/ to your PATH environment variable, for example you then just have to write mysqladmin and not /usr/local/mysql/bin/mysqladmin to access the administration program. Write the following commands in the

  1. echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile
  2. . .bash_profile

The first command adds the path to the file .bash_profile and the second reloads the file (yes, there’s two dots with a space between them in the second command).

3.2 Install the Preference Pane and Startup Scripts (optional)

To add the MySQL preference pane:

  1. Go to the mounted .dmg and double-click the MySQL.prefPane file.
  2. Click the Install button.

A new preference pane appears on your where you can start/stop the server. If you want to use the Automatically Start MySQL Server on Startup option you’ll need to install the startup scripts:

  1. Go to the mounted .dmg and double-click the MySQLStartupItem.pkg file.
  2. Follow the onscreen instructions.

3.3 Configure PHP to use correct mysql.sock

Per default PHP tries to use /var/mysql/mysql.sock when connecting to MySQL. When installing MySQL the mysql.sock is located in /tmp/mysql.sock. If we moved this file the preference pane would stop working so what we want to do is tell PHP to use /tmp/mysql.sock. To do this, once again open up the

  1. sudo cp /private/etc/php.ini.default /private/etc/php.ini
  2. sudo pico /private/etc/php.ini
  3. Search for mysql.default_socket by pressing control+w, writing it and press Enter.
  4. Change the row to mysql.default_socket = /tmp/mysql.sock
  5. Press control+x and then y followed by Enter to save
  6. sudo apachectl restart

3.4 Change root password for MySQL

The root password is left blank on new installations, this is not acceptable. To change the password write this in (if you’ve added mysql to the PATH):

  1. sudo mysqladmin -u root password [new password]

Replacing [new password] with any secure password you can come up with.

3.5 Test PHP – MySQL connection

  1. Create a test.php file somewhere accessible from a browser with the following contents:

$address = 'localhost';
$user = 'root';
$password = 'yourrootpassword';
mysql_connect($address, $user, $password) or die(mysql_error());
echo "Successfully connected to MySQL";

  1. Replace yourrootpassword with the password you specified in 3.4
  2. View test.php in a browser too see the result

4. Finished

Now you should have a working server with PHP and MySQL running to play around with. Maybe you want to install phpMyAdmin to manage the database or install WordPress to develop themes and plugins.

In order to shut down or start the web server and MySQL daemon you just go to the System Preferences and enable/disable the services.

Custom folder icons in Mac OS X Lion

Since I converted to Mac OS X a couple of years ago a feeling to keep my OS nice and tidy has grown slowly but steadily. Today I installed a small Subversion server in my home folder to keep track of my programming changes and discovered that the folder didn’t look as nice as I wanted to. A big blank folder spot in the middle of my vanilla Apple folders, gasp! Searching the net for a minute my patience ran short and I decided that I had to do something about this myself, right away.

This post is a guide to make your own Apple-like folders. It’s not pixel-perfect in any way but a good starting point for anyone who wants to try. The result is something like this (or whatever icon you want to make):

Requirements for this tutorial:

  • Mac OS X
  • Photoshop
  • AppleFolderIcon.asl (Free Photoshop CS5.1 layer style made by me)
  • Xcode developer tools (Found on your Mac OS X install medium)
  • IconDroplet (Free)
Note: Some pictures is in swedish since my OS is in swedish, shouldn’t be any problems for the tutorial though :)

1. Find the default folder icon

Most of the familiar Mac OS X (Snow Leopard) icons can be found in:

Here you’ll find the file GenericFolderIcon.icns which is the default icon for folders.

2. Extract the PNGs

Every .icns file consists of 5 different images representing the various sizes an icon can have: 512×512, 256×256, 128×128, 32×32 and 16×6. In order to make a custom folder icon we have to create four of these since the default folder icon only has four
(well, we can use only one size but the end result isn’t as good).

I used to extract the files since the conversion preserves the transparency and quality: Upload your GenericFolderIcon.icns and download the (Linux) PNGs sized 512, 128, 32 and 16.

3. Import layer styles

Using the layers I’ve created, download, you can pretty much get vanilla-like Apple folder icons from any black/transparent shape. The download is an .asl-file that contains four different layer styles used for each size of the icon. Just double-click the file and Photoshop will import them.

To check that the styles are imported, go to: Edit → Preset Manager… → Select Styles from Preset Type and look for the four blue styles (presumably at the end).

4. Create the icons!

Open up the GenericFolderIcon_512x512x32.png that you downloaded in Photoshop and create a new layer (⇧ + ⌘ + N). Then draw or paste you desired form or logo into the new layer. For this tutorial you can test with the custom Subversion logo I made, link.

It’s important that you only use black as color if you want the icon to look Apple-like since the layer styles uses black as base when you apply them, or else you get the wrong facet. I don’t say the layer styles create a perfect Apple-like-facet but it’s the closest I got.

When you’re satisfied with your new layer you apply the style you previously installed. Select (Window → Styles) and the upper right box on the screen changes to “Styles” (With default settings in CS5.1). Scroll down the styles and you’ll find the four blue styles you imported.

Be sure to choose the right style depending on your icon size, hover the styles to see details.

Now you should get something that looks pretty much like an Apple folder with a custom bevel. Now you have to do this for the other icon sizes so you’ll have a set. Follow these previous instructions but be sure to choose the correct layer style for each one!

Tip: You can paste your 512px-sized black shape into the smaller 128px icon layer and resize it to 25 % of it’s original size since 128 is 25 % of 512. Select the whole black-shape layer with ⌘ + A. Copy and paste it into the smaller icon image and then do a free transform with ⌘ + T. At the upper bar you’ll see two percent fields named W: (width) and H: (height). Move the shape into place and you’re done. You can use this little trick with the other sizes aswell, just make the 32 to 16 transisiton 50 %.

When you’re done (phew!) you’ll have four different sizes of the same icon. Save each one in PNG format ( ⇧ + ⌘ + S  → Select PNG from the Format: dropdown → Save).

5. Packaging

Now comes the use of Xcode developer tools. Navigate to /Developer/Applications/Utilities and start up Icon Composer. This application is used to create .icns files. Just drag and drop your files from finder into the respective size-box in Icon Composer. Don’t mind about the 256 box. When you’re done, save using the menu.

Now there’s one little thing left to do in order to be able to use your custom icon, usually you just right-click, choose “Get Info” and copy/paste the icon at the top left. If you try that with the .icns file you just created you’ll discover that this icon has taken the place of your gorgeous custom icon.

IconDroplet is a tool “that takes raw icon files (*.icns) and turns them into files that are embedded with the icon. After the files are processed you can “Get Info” on the resulting files and copy/paste the icons to other items.” (description taken from macupdate).

So, download IconDroplet and just drop your .icns file on the application. It creates a file in the same directory as your .icns file.

6. Using

Select and copy the icon

To use your new icon, right-click the file IconDroplet made and select “Get Info”. In the upper right corner you’ll see the icon you made. Left-click it once and copy it (⌘ + C). Then right click and do the same thing to the folder that you want to have the new icon, only paste is instead of copying it (⌘ + V).

You’re done, congratulations! And my home folder has a prettier Subverion folder.

Administration Dashboard

I wrote a simple function for modifying the way the dashboard is shown for different user roles. For example I don’t want my subscribers too see all the system magic like stats:

// initiate the function
add_action( ‘wp_dashboard_setup’, ‘remove_dashboard_widgets’ );

function remove_dashboard_widgets() {

global $wp_meta_boxes;

// if a user cannot edit posts he or she will only see the latest comments
if ( ! current_user_can( ‘edit_posts’ ) ) {



// if a user cannot update the core he or she will not see
// the wordpress news on the dashboard

if ( ! current_user_can( ‘update_core’ ) ) {





More information on this can be found in the codex:

%d bloggers like this: