PHP - Getting Started
What is PHP?
Section titled “What is PHP?”PHP was invented by Rasmus Lerdorf and its first release was in 1995. Lerdorf wanted a server-side scripting language where he could process logic and output HTML and other useful formats. On release, PHP stood for Personal Home Page, but the definition has since expanded to the recursive backronym PHP: HyperText Preprocessor. It is now a large part of the web, powering a variety of sites from WordPress blogs to Facebook.
Resources to Try
Section titled “Resources to Try”- If you prefer learning with a serialized course-like experience, try Codecademy: Learn PHP Intro and Codecademy: Learn Intermediate PHP.
- If you prefer checking out some documentation and examples on your own, try w3schools. Try modifying the examples.
Run PHP Locally
Section titled “Run PHP Locally”While sandbox environments are great, one of the best ways to learn is to jump in and start making something.
Download PHP
Section titled “Download PHP”Follow the official guide from the PHP group for your OS.
Create some files
Section titled “Create some files”Here are two files from w3schools that demonstrate creating a form and handling it server-side.
├── index.php└── welcome.php<html><body>
<form action="welcome.php" method="post">Name: <input type="text" name="name"><br>E-mail: <input type="text" name="email"><br><input type="submit"></form>
</body></html><html><body>
Welcome <?php echo $_POST["name"]; ?><br>Your email address is: <?php echo $_POST["email"]; ?>
</body></html>Submitting the form on index.php directs the client to welcome.php, where the body of the POST request is accessed from the $_POST variable.
Serve the application
Section titled “Serve the application”You can serve the application on any non-restricted port (1024-49151). Here’s an example of serving the application on port 8000.
# from `man php`# --server addr:port# -S addr:port Start built-in web server on the given local address and port# --docroot docroot# -t docroot Specify the document root to be used by the built-in web server
# The `.` after the `-t` flag specifies the current directory as the one to be served.php -S localhost:8000 -t .View the application in the browser on http://localhost:8000 and try submitting the form. Play with the code to see what happens.