Help me upgrade PHP on my MacOS X so I can run xDebug!
December 4, 2013 7:54 AM   Subscribe

I want to upgrade the native version of PHP on my Macbook running MacOS X and I am not having much luck. Snowflakes inside...

I am running through the Murach book "PHP/MySQL". In chapter 6 he goes over how to debug a PHP application using Netbeans and xDebug. First you have to get Netbeans and xdebug working on your computer - in my case a Macbook running MacOS 10.8.5.

I tried the instructions listed in the appendix of the book (download Netbeans, then download the xDebug binary) first to no avail. Netbeans works great but xDebug fails to load and I can't work any of the exercises thereafter until I do.

I should mention I started with XAMPP which worked fine but couldn't get xDebug to work with it. So I tried MAMP, same thing. Then I uninstalled both of these and thought I would go the brute force method and try upgrading native PHP and installing mySQL without MAMP or XAMPP, by following these 2 guides:

Works great except instead of the latest version of PHP, I still get the old one reported when I do a "php -v". Also, absolutely no php pages work now under apache.

Is there a better way to do this? Do I even need to fool with xDebug to learn PHP/mySQL?! I've spent waay too much time on this now as it is.
posted by dukes909 to Computers & Internet (19 answers total) 1 user marked this as a favorite
Have you tried installing Homebrew? It's a command line package manager for Macs, and lets you install newer versions of programs, including PHP.
posted by gryftir at 8:02 AM on December 4, 2013

If you've installed PHP already but are still getting the "old" version when you do 'php -v', it most likely means that you need to update your $PATH so that the new php version gets precedence.

If you type in the 'which php' you'll see where php is currently executing from. Typing 'echo $PATH' will show you what your current path environment variable is. I'm not sure where your "new" php lives, but it's directory needs to be BEFORE the old php directory in your $PATH. Google how to set your path, there are better instructions than I can type up here.

That being said - I really don't think you need xdebug if you're just starting out. I'm a professional php developer, been doing this for longer than I am willing to admit, and xdebug is a giant pain in the ass. Don't get me wrong, having a debugger is a huge help, but given it's PITA status with php, you instead get very adapt at:

throw new \Exception(); //using the exception, assuming it's not caught, stops execution AND tells you where you stopped, which die() does not do.

Also - on preview, I also highly recommend using homebrew to manage things like this on your machine.
posted by cgg at 8:05 AM on December 4, 2013

Starting with the basics. When you put a test php file in your Sites folder, and visit "http://localhost/~dukes909/test.php" - does it run the PHP? Or spit the raw PHP onto the page?
posted by derbs at 8:08 AM on December 4, 2013

Yes on the homebrew, that's part of the 2nd set of instructions I linked to.

I have /usr/local/bin in my path but it's after /usr/local. I can correct that but it doesn't explain why apache doesn't recognize php files anymore..?
posted by dukes909 at 8:09 AM on December 4, 2013

@derbs: No
posted by dukes909 at 8:09 AM on December 4, 2013

PS: PHP pages worked fine prior to upgrading PHP!
posted by dukes909 at 8:12 AM on December 4, 2013

No? You mean you see the raw PHP? Or just a blank page? Or an error message?
posted by derbs at 8:12 AM on December 4, 2013

Ok, you're going to have to do this:

• Click on your Finder icon
• Press CMD-Shift-G, and type in "/etc"
• This shows you the contents of the etc folder. Find a folder called "apache2"
• In apache2 - there should be a file called "httpd.conf"
• Duplicate a backup of it just in case
• Open httpd.conf with a text editor of your choice
• Find the line:
#LoadModule php5_module libexec/apache2/

• Does this line have a # at the start? If so, remove it
• If not, your problem is elsewhere
posted by derbs at 8:19 AM on December 4, 2013

No, PHP pages won't load. Actually, now that I am looking I get a "Unable to connect" error! Crap, I thought I had apache working before.

I get no errors returned when I run:
"sudo apachectl start"
and in fact, if I try it again:
"org.apache.httpd: Already loaded"
posted by dukes909 at 8:20 AM on December 4, 2013

No that was one of the instructions in the 2nd link above. That line in the httpd.conf is already good to go.
posted by dukes909 at 8:20 AM on December 4, 2013

Ah ok sorry. So you're getting an 'unable to connect' error when you try and load any php page?

I know with MAMP and others, you browse to http://localhost:8001 or whatever port. Are you sure you're not trying to use 8001?
posted by derbs at 8:23 AM on December 4, 2013

No, it's port 80. No pages load now, even simple one line of text html pages.
posted by dukes909 at 8:24 AM on December 4, 2013

Ok, I'm seeing errors in /var/systemlog:

Dec 4 10:25:58 mcb[1] (org.apache.httpd[1058]): Exited with code: 1
Dec 4 10:25:58 mcb[1] (org.apache.httpd): Throttling respawn: Will start in 10 seconds

What's error code 1?
posted by dukes909 at 8:29 AM on December 4, 2013

Stumped. Try this:

• Try using
• Try using http://{your-ip}/~whatever/test.php
• Open a terminal and type "telnet localhost 80" - does it say "Connected to localhost"...?
posted by derbs at 8:30 AM on December 4, 2013

Ah... is something else listening on port 80?
posted by derbs at 8:31 AM on December 4, 2013

In httpd.conf, what's in the 'listen' section?
# Listen: Allows you to bind Apache to specific IP addresses and/or.....
posted by derbs at 8:32 AM on December 4, 2013

Ok, I found a syntax error in the httpd.conf - now apache is running and I can load all pages: html and php.
phpinfo.php however reports the old version: 5.3.26
posted by dukes909 at 8:34 AM on December 4, 2013

Try installing via this route, I've never tried compiling my own
posted by derbs at 8:38 AM on December 4, 2013

Thanks Derbs - this worked!
posted by dukes909 at 9:02 AM on December 4, 2013

« Older wireless charging or other fix for galaxy s3 with...   |   What lab tests should I get? Newer »
This thread is closed to new comments.