Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this movie were going to learn to work with the Apache Web Server. You'll remember in the overview movie, that I told you that the Apache Web Server is already installed on Mac OS 10.8. I also want to mention that there is an alternative that you could use instead of the Apache Web Server. Starting with PHP version 5.4, there is an included Web Server. It's a very simple, lightweight web server, easy to start up, easy to stop, and not very robust. I want us to go ahead and learn to use Apache, partly because it's the most popular option out there. But also because when you finally deploy your application, you're likely to want to use Apache for serving your actual application to the general public. So let's go ahead an learn how to use it now.
You always will have this PHP simple development one there, if you decide you want to switch over an start using that. But I don't want to use that as a crutch, an then not know how to use Apache. So let's work with Apache first. Now, even though we already have Apache installed, it doesn't mean that it's simple to get to. It's not something that sits inside your Applications folder. It's a program that runs under Unix, which is under the hood of Mac OS X. We used to be able to interact with it, from the system preferences, and from the sharing preferences, menu. But starting in 10.8, that changed because the option here that said Web Sharing was taken away by Apple. It used to be that we could just go to Web Sharing and click on the check box next to it and it would turn on Apache.
Click it again and it would turn off Apache. It was a way for us to have a graphical user interface to interact with this program that's in Unix. But they took that away, but that's okay. We don't actually need it. We can do it by going directly to units. If you go to your Applications folder, you'll see that you have a folder called Utilities. And inside there is a program called Terminal. And this is the command line utility that will allow us to interact with Mac OS X. I could just click on this and launch it, but because we're going to be using Terminal a lot, I'm going to go ahead and drag it down here to my Dock, and then launch it from there. So here we are, we just have a Command Line that will let us type commands to be sent to Unix for it to execute those commands.
And it'll come back with responses to our screen. If you've never worked with the Command Line before. Don't be intimidated by it. It's pretty easy once you get the hang of it. Now, yours likely looks different than mine. I've just simply gone up to Terminal > Preferences and customized some of my color and font settings. You can pick different things for yourself as well. I wanted something that was more easily readable by you. All right. So let's now check out Apache. The first thing you need to know about Apache is that it has a nick name. It's nickname is HTTPD. You may recognize the HTTP from when you write a URL in your browse.
That stands for the Hyper Text Transfer Protocol. The D at end stands for Daemon. A Daemon is a little program that sits waiting to respond to requests. So what is Apache? Well, it's a Hypertext Protocol Daemon. It's sitting there waiting to respond to web requests. So this is its nickname. So, httpd -v, will tell us the version that we're running. So, this lets us know that we have Apache installed and that it's version 2.2. In my case, it's .22. Now, if you have something different than that, Apache 2.3 or something later, don't worry.
It really doesn't matter what version of Apache you have. Its role in this whole process is pretty simple. It's going to take our PHP, process it, spit it out as HTML. Any features or enhancements that come in later versions of Apache aren't going to affect us. Now, incidentally, if we had said Apache -v, it comes up and says, I don't know what that command is. In this case, It is called by it's nickname. So sometimes you'll see it one way, sometimes you'll see it the other. Is Apache actually running? There are two ways that you can tell this. One is by doing a special Unix command that you don't need to know all the ins and outs of. But ps space aux and then pipe that through with that upright bar. And then after that, grep httpd.
What we're doing is we're saying spit out a list of all of the processes running on this machine. But send them to the grep search command and tell it to look for lines that have httpd in them. When I hit Return, it comes back and says oh I see one process running, and that is the grep command that you just entered, the search command. So it's not actually running. The only thing that's there was my search for it. If it was running we would have expect to find at least one other instance being returned to us. Something showing the actual process, the Daemon.
That's running and as a process waiting to respond to web requests. The other way we could do it is to launch a browser. And from the browser, we can ask for http:// and then local host. That's a special name that means go to my local IP address and tell me what you find. And it comes up and says, I'm sorry, I couldn't find anything. If Apache had been running, we would have gotten a result. So, let's go back and let's see how do we make Apache run. To do that, we're going to need to have another command. There are three commands I want us to learn and they're all very similar.
What they do is start, stop and restart Apache. And we do that with Sudo Apachectl, that's for Apache control, so we're controlling Apache, Apache control start, and Apache control stop, and then Apache control restart. The sudo at the beginning of each of those is a Unix thing. It's saying, Unix, with my highest level of access privileges, I want to execute this command. So that's what it's asking for. And once we issue any of these commands, it's going to pop up and say you know what, I need to have your password.
And that password will be the same password that you use whenever you log into your Macintosh or whenever you're installing new software. And it comes up and says hey, I need your highest level of access privileges to do this. That's the password it's talking about. Let's try it now. Okay, so here we are in the command line again. So it's sudo apachectl and then start. So it'll come up and it will ask me for my password. Now, yours may have come up and asked you with a big scary message saying, hey, be really careful about using sudo. If you're not sure what you're doing stop now.
Ignore that message. It's just a simple cautionary message that runs the first time that you run sudo. After that, you can just type your password, hit Return, and it comes up with no response. Now that also is a change, unfortunately, for the worst. It used to be that it would come up and say, Apache has now started, but they took that away, it doesn't come back and tell us anything. So, how do we know it's started? Well, we can do two things, we can issue the same command for the command line. I can use my up arrow to go back up there and just save myself some typing and then hit Return. Now, you see it came back with some more stuff.
It shows me these processes that are running. You don't have to worry about what they are or what all that means, you can see that the processes exist. We also can go to our Firefox and if we just hit reload on the page, we come back and we get something that says it works. Now, we know that Apache is working. That's a default page that Apple has. It works with the exclamation point. If you see that, Apache is running and is accessible via local host. Now on your own you can try stopping it, starting it restarting it, issue all three of those commands.
I'm not going to go ahead and that though, I think you can do those on your own. We do need to do a little bit more configuration of Apache though. And we'll do that in the next movie.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 92180 Viewers
82 Video lessons · 104056 Viewers
71 Video lessons · 75374 Viewers
56 Video lessons · 106747 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.