1. 3
    Start the built-in PHP web server
    2m 36s

Start the built-in PHP web server

Mark Shust
InstructorMark Shust
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 2 years ago

Usually when you are building a website, you’ll have a web server such as Nginx or Apache that sits in front of the PHP service. But in this lesson, we’ll use a much simpler method: use the built-in PHP web server!

Instructor: [0:00] Usually when you are building a website, you'll have a web server, such as Nginx or Apache, that sits in front of the PHP service. Then some configuration needs to be added so that web server can properly serve web requests who handle PHP files.

[0:16] You'll definitely want to set up this external server/PHP combo on production sites, but right now we just need to learn PHP.

[0:25] We'll use a much simpler method, use the built-in PHP web server. You'll want to first open up terminal.

[0:32] You can do this right on your host with the terminal app, or if you are using PhpStorm, you can go to View, Tool Windows, Terminal. We can see that this works the same way as the normal terminal app.

[0:48] Let's call the PHP binary again, but this time passing in the --help argument. This gives us the available arguments we can pass to this PHP script.

[1:00] One of those being the -S command, which runs the built-in PHP web server. This argument expects an address port combo to be passed in after the -s flag.

[1:17] Let's go ahead and call PHP -S, and the address here will always be localhost since we are running it on our own machine, followed by a colon, followed by any available port.

[1:32] Note that you cannot use any port lower than 1024, as those are considered privileged ports that require higher security privileges. It's common to use port 8000 for this built-in web server.

[1:47] The default port for web servers is 80. Just adding a couple zeros at the end, makes this easy to remember.

[1:55] Now that we have our web server started, we can visit this localhost 8000 address in our web browser, and we'll see a not found page. Don't worry, this is actually great.

[2:08] This purple background at the top, lets us know that the builds in PHP server is serving up this request.

[2:16] If we check out our terminal again, we will see that there is some output to the console here, showing the web server accepting the request, serving it up, and then closing out this web request.

[2:28] Now that you have your editor set up and a web server running, it's time to start writing some PHP.

egghead
egghead
~ 2 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today