Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to I enable PHP on my MacBook?

I have tried a lot of online tutorials on how to enable PHP on a Mac and nothing seems to work. I'm hoping another 'Mac' person out there knows the secret to what I am missing. =)

MacBook Pro (15-inch 2.4/2.2 GHz), Mac OS X (10.6.8)

Posted on May 1, 2012 8:29 AM

Reply
21 replies

May 1, 2012 11:00 AM in response to emilymagnuson

Create a file called 'test.php' with this line of code in:


<?php phpinfo(); ?>


Save the file in this folder:


/Library/WebServer/Documents


This should be the default folder. If not check the DocumentRoot directive in /etc/apache2/httpd.conf. Note that we're using the global webroot folder here, not the user's web folder which will be something like ~username/sites/<sitename>. If you've been trying to test by using your user's webspace rather than the global webroot folder then that might be the problem.

May 2, 2012 9:03 AM in response to emilymagnuson

Where did you put sayHelloWeb.php?


If you put it in ~/Sites/scripts/, then you would use something like the following URL: http://localhost/~emilymagnuson/scripts/sayHelloWeb.php


If you put the script in /Library/WebServer/Documents/scripts, then you would use the this URL:

http://localhost/scripts/sayHelloWeb.php


If PHP is working, you will get some kind of output or a 500 Server error indicating a coding problem. If you get back the source to your PHP script, then PHP is still not configured correctly.

May 2, 2012 9:12 AM in response to emilymagnuson

To test whether PHP is working on your Mac create the test.php file that I suggested earlier. If that doesn't work then PHP is not working and you have some configuring to do. If it does work then you have a coding problem with your web-page. Do that so we can determine where your problem lies. The thing is, a file not found error doesn't imply that PHP is not working on your Mac, so let's establish once and for all whether it is or not.

May 2, 2012 10:40 AM in response to Zyriab

Okay, here is the HTML for the page...


<html>

<head>

<link href="../css/phpMM.css" rel="stylesheet" type="text/css" />

</head>



<body>

<div id="header"><h1>PHP & MySQL: The Missing Manual</h1></div>

<div id="example">Example 1-1</div>



<div id="content">

<h1>Welcome!</h1>

<p>Hello there. So I hear you're learning to be a PHP programmer!</p>

<p>Why don't you type in your name for me:</p>

<form action="/scripts/sayHelloWeb.php" method="POST">

<p><i>Enter your name:</i> <input type="text" name="name" size="20" /></p>

<p><input type="submit" value="Say Hello" /></p>

</form>

</div>



<div id="footer"></div>

</body>

</html>



*****Here is the PHP*****


<html>

<head>

<link href="../../css/phpMM.css" rel="stylesheet" type="text/css" />

</head>


<body>

<div id="header"><h1>PHP & MySQL: The Missing Manual</h1></div>

<div id="example">Example 1-1</div>


<div id="content">

<h1>Hello, <?php echo $_REQUEST['name']; ?></h1>

<p>Great to meet you. Welcome to the beginning of your PHP programming odyssey.</p>

</form>

</div>


<div id="footer"></div>

</body>

</html>

How to I enable PHP on my MacBook?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.