Category Archives: Mac OS X

Apache, PHP and MySQL on Snow Leopard

I have enjoyed using MacPorts for a number of reasons, and I have written about it several times. Recently, I have had to rely on it more, and I have grown frustrated with it to the point that I had to abandon it altogether.

I upgraded to Snow Leopard (10.6) last week. It broke my install of MacPorts, but they actually tell you to reinstall after an OS upgrade like this. So I did that, but I could not get Apache 2 and PHP running again to save my life, not to mention MySQL.

So I instead relied on the factory installs of Apache and PHP. It turns out they have gotten a lot better with Snow Leopard. All I had to do was reinstall MySQL which meant I lost my databases but I was prepared for that to happen by then anyway.

Here are the instructions to get Apache, PHP and MySQL running in Snow Leopard.

Install Apache/PHP/MySQL on Snow Leopard

It worked perfectly for me except for one thing. PHP short tags are off by default. So make sure to turn them on or check your code to make sure you are not using PHP short tags, or your PHP code will not work.

I may continue to use MacPorts for other things, but for now I am no longer using it for my dev environment. Maybe one day I will give it another shot if I need it.

Install Apache, PHP and MySQL on Leopard with MacPorts

Running selfupdate on MacPorts is a good way to keep your MacPorts software up to date. The problem is when I did this, all my settings were overwritten. I should also mention that running selfupdate on my MacPorts install caused all my virtual hosts to get overwritten as well. I wrote a post last year on how to install Apache and PHP on Mac OS 10.5 with MacPorts, but following that post didn’t help me get up and running again. So I figured I would write a new one that would actually have the right information.

Here are the install instructions you need for installing Apache, PHP and MySQL with MacPorts. I had already installed Apache and PHP, but MySQL wasn’t working. I have MySQL server already installed and running, but PHP wasn’t finding it. I already had multiple databases set up, so I did not want to reinstall MySQL. All I had to do was follow the instructions in step 4. It fixed the problem, but there were a couple of settings that needed to be changed first.

After you install PHP, it gives you a 2 part message. Part 1,

Your php.ini contains a line that will prevent php5-mysql
and other PHP extensions from working. To fix this,
edit /opt/local/etc/php5/php.ini and delete this line:

extension_dir = "./"

is correct. Deleting that line is how you find the right extensions. Part 2,

To use mysqlnd with a local MySQL server, edit /opt/local/etc/php5/php.ini and set
mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket
to /opt/local/var/run/mysql5/mysqld.sock

did not work for me. For my MySQL server, that socket does not work. Instead, I found this article that tells you the correct socket on Leopard to set:

mysql.default_socket = /private/tmp/mysql.sock

That fixed everything for me, except for my virtual hosts. Again, your mileage may very. These instructions worked for me on my machine with the software I have.

MacPorts Commands

I use MacPorts to handle my installs of apache, php, etc. on my Mac. If you are using MacPorts on your Mac like I am, you may want to remember these handy codes to manage your MacPorts packages.

sudo port selfupdate

Update MacPorts to the latest version

port installed

List installed packages

sudo port upgrade outdated

Automatically upgrade outdated packages

With MacPorts, it really is that simple to install and then make sure you have the most current version. I love it, and I highly recommend it to everyone else.

Install Apache and PHP on Leopard with MacPorts

If you have a Mac with Leopard installed, you should have Apache and PHP installed on it by default. If you try to modify your PHP installation however, this is where you run into problems. This was easy to do with Tiger, and I had written several articles on how to do this. Eventually, when I installed Leopard, my dev environment no longer worked.

I found a solution to this problem with MacPorts. The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac OS X operating system.

With MacPorts, it’s easy to install Apache and PHP into an environment you control. MacPorts makes it easy to add libraries to configure your installation however you want. It also makes it easy to update the software whenever you need to. I recommend using this to install your own dev environment on your Mac. Here is a good tutorial for installing Apache and PHP with MacPorts.

Note: the shortcut apache2ctl didn’t work for me because I am using .bash_profile on my machine instead of .profile which MacPorts installs. If you have this problem, you need to add a line of code to .bash_profile. Add the line below to .bash_profile and the shortcut apache2ctl should work.

alias apache2ctl='sudo /opt/local/apache2/bin/apachectl'

Using Web Inspector in Safari 3

I am really digging Safari 3. One of the cool features in Safari 3 is web inspector. Web inspector is a tool mainly for web developers to use in debugging web pages. It is basically Firebug for Safari.

Web inspector is not new. It has been available for a while in Safari 2. But it has been redesigned for Safari 3. Here is a screenshot of it.

The tricky part is that you need to enable it in order to use it. First, if you are using Tiger, you need to get 10.4.11 in order to make sure you have Safari 3. If you are using Leopard, you already have Safari 3. Once you have it you need to be able to use command line in Terminal. To enable Web inspector, open up Terminal and type the followwing command.

defaults write WebKitDeveloperExtras -bool true

Now you have it enabled. To use it, restart Safari and right click on any element on a web page and select Inspect Element. This will open up Web inspector.

I won’t take the time here to give a thorough review of everything it does, but play around with it and test it out. It lets you view the underlying code of your page along with the CSS applied to each element in the correct cascade order of the properties. It also gives you an error view and a network view. The network view shows you how each item on the page downloaded and how long it took. There is also an element inspector that lets you view each element that was downloaded that can be very useful for developers.

I also have to comment on how fast Safari 3 is. I noticed while using it that it is much faster than Firefox. It was enough to get me to switch to Safari from Firefox while using a web application. It’s that much faster.

So there you go. If you aren’t using Safari yet, I just gave you two good reasons to check it out.

Safari 3 for Tiger is Now Out

You may or may not know that Apple released Safari 3 with Leopard. If you are like me, you were wondering when it was coming out for non-Leopard Mac-users, or if they were going to release it at all. Well, today is the day. Safari 3 is now available on Tiger. Read about it here.

To get Safari, you need to get Mac OS 10.4.11 which is out today. You can either get it through automatic upgrades or install it manually. It requires a restart if you were wondering. It appears to be worth it. I haven’t installed it yet, but from what I hear, it is much improved over the previous versions.

What are the improvements? Surfin’ Safari has a list of ten new things in Safari 3. The biggest performance improvements in my opinion are the enhanced rich text editing, faster javascript and DOM and faster page loading. Chris in my office installed Safari 3  already and noticed those 3 things right away. Hopefully, enhanced rich text editing means that I can use WordPress, which uses TinyMCE for editing, in Safari now. I also think the developer tools will be useful. I can’t wait to try it out!

Installing PHP 5 on Mac OS X

Okay, so I have been running PHP 4 locally on my Mac OS 10.4, but I recently needed to upgrade to PHP 5. In addition, PHP 4 will no longer be supported after the end of this year. The installation instructions are the same as for PHP 4, which is not a big deal. I also installed libcurl, which is not included by default for some reason.

Why am I posting this here then? So I can reference it, whenever I need to recompile PHP again. I am installing new libs all the time, it seems like, so it helps to know what I have done each time so I can do it again the next time. This is the third or fourth time I have done this, so I won’t go into that much detail. If you need more details, look at my other posts.

For step one, download and unzip PHP 5. Then, open the folder and run configure, make and sudo make intall, like this.

./configure --prefix=/usr/local/apache2/php
--with-gd --with-mysql=/usr/local/mysql
sudo make install

Remember to change your file paths, if they are different than mine. Restart Apache, and you’re done!

Apache 2.2 Included with Leopard

So here’s one more reason to upgrade to Leopard, especially if you are a developer. Leopard reportedly comes with Apache 2.2 installed. A co-worker of mine got it yesterday and was able to confirm this. This is the first I have heard on what software packages are installed with Leopard other than Ruby.

This is great news for developers. Mac OS 10.4 only comes with Apache 1.3 installed. You can upgrade to Apache 2 like I did by installing it yourself, but this way you have to manually stop and start Apache. As if I already needed a reason to upgrade, now I have an even better one. Good job on this Leopard guys!