Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this movie, we're going to learn how to enable PHP on our Macintosh. If you remember the overview, I told you that OS 10.8 ships with PHP 5.3 already built in. Now it's already there, but it's not enabled, it's not turned on, meaning that Apache isn't ready to serve up PHP files. We're going to have to make a change to make that happen. In addition, 5.3 isn't the newest version of PHP. So we're also going to want to upgrade to a newer version, and I think it's instructive for you to see how to do that process. But we're going to start out by just getting version 5.3 up and running by enabling it. Let's see how.
So here I am in my terminal program, and I'm just going to start by typing php -v. And that's going to return the version of PHP that I have installed. You can see that I have PHP 5.315, yours might be slightly different. Notice also that it tells me that it's running Zend Engine v2. We talked about that in the history section, that PHP now runs on a Zend Engine. So, PHP is installed and we have version 5.3. But it's not active yet. We need to tell Apache, hey Apache, you need to be prepared for some PHP files, be prepared to process those.
And you do that by loading up one of your modules that knows how to interpret PHP. That module's included. It's just not turned on. So, in order to do that, we need to do some configuration to Apache. We're going to start by moving to Apache's configuration directory. That's going to be cd space slash etc slash apache2. This is where apache's config files are stored. If we type ls we will get a list of those and you can httpd.conf that's the file that we want. We know httdp is the nickname for Apache and conf for the config file. So in order to edit that, I'm going to use sudo to get my maximum amount of Unix privileges.
And then nano for my simple text editor. And then I'm going to edit that httpd.conf file. It's going to ask me for my password, that's the password I'm using when I'm installing software on my Mac. And here it is. Now, I have the conf file now open, I can browse this and make all sorts of changes and configurations to Apache. But I'm really only looking for one change, which is PHP. So, instead of browsing through this long document, says it's 500 lines long. I'm going to go straight to it, and you can see that one of the options at the bottom is Where Is. And the way to get that is Ctrl + W, and that will allow us to search for some text.
And what are we going to search for? PHP. So PHP and hit Return. It takes us straight there. So here it is, the PHP5 module. This is the module that gives Apache the knowledge about how to interpret PHP code. But it's not loaded right now. And how do I know that? Because this pound or hash sign that's at the beginning is telling it that this line is commented out, and not to be loaded. So I need to take that out. You won't be able to just use your mouse and click there. We are on the Command line. We want to use your Arrow keys. So move your cursor over to the L and just hit Delete to get rid of that. Now it has been un-commented, the next time that Apache loads this config file it will also load the module and to be able to read PHP code. So let's hit Ctrl + X to exit, Y in order to save the changes, and then Return to save them in the file name it suggests.
Okay, so that's been added to Apache but we need to also restart the server. We know how to do that. apachectl restart. Now it restarted. Now those changes have taken effect. PHP is loaded up, inside Apache, and it's ready to process our PHP files. Now, don't just take my word for it, let's actually try it out. Let's navigate to our sites directory, that's inside our user root which is that little squiggle followed by the forward slash and then our sites directory.
By list you'll see that I have my index.html file in there. I'm going to make a new one now using nano. And we don't need sudo in front of nano this time, we'll just making a simple text file, we don't need high level privileges. And I'm going to call it my_phpinfo.php. That's going to be the name of my file. It's going to open up here and I'm going to write my very first PHP code here. So just follow along. It's going to be a less than sign, a question mark php, a space phpinfo open and close parenthesis, semicolon space, question mark and then greater than sign. We'll talk about what all of these things mean, but the short version is that I've got PHP tags on either side of a command telling it what to do. So the beginning and ending bookends that have the question mark and the less than, greater than signs, those are the PHP tags telling it, hey, PHP is inside here. And then the command in the middle is the PHP info function that's being called. So now we go to our browser, and we request Apache to load up this PHP page. It's going to see that it ends in .php.
It's going to see the PHP tags. And it's going to process this command that's here in the middle. And we'll see the results of what that function will output. So let's do Ctrl + X to exit, Y to save our changes, and Return to keep that file name. We can see that it is here in my site's directory. Let's go to our browser, let's try it out. Localhost, remember, we need to put our username in front of this. And then my_phpinfo.php. So there it is.
It loaded it up, that PHP. And it processed it. And the results to the output of HTML decribing the entire configuration of PHP on this system. It's extremely useful command. First of all, because it tells you all the configuration, so you could review that and see how things are configured, see if there are any problems. But also, just because it is the simplest test that you can do to prove to yourself that PHP is working on this system. If the phpinfo page works, then Apache is able to handle serving up PHP, the problem's gotta be something else.
So that's it. We've now enabled PHP. And we could go ahead and we could start working with this and you can go through this tutorial. And almost everything that I'm going to show you in the tutorial is going to work just fine with version 5.3 of PHP. However, I want us to see how we can upgrade to a newer version. And we're going to do that next.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97489 Viewers
61 Video lessons · 84721 Viewers
71 Video lessons · 68914 Viewers
56 Video lessons · 101358 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.