Introduction to PHP and Server-Side Basics

Jul 31, 2024

PHP 101 Notes

Introduction to PHP

  • PHP is a server-side scripting language.
  • It is used to create dynamic web pages.

Code Interpretation

  • Code written by developers is rendered into a display in the browser.
  • Browsers function as interpreters of code, converting source code into visual displays.

Client-Side vs. Server-Side Processing

  • Client-Side: HTML, JavaScript, CSS (processed by the browser).
  • Server-Side: PHP (processed by the server).

Server Configuration

  • Servers run specific software to serve web pages:
    • Apache: Web server that handles requests.
    • MySQL: Database management system.
    • PHP: Pre-processes server-side code.
  • Common setup: LAMP stack (Linux, Apache, MySQL, PHP).

Understanding Server Requests

  1. Browser makes a request (e.g., google.com).
  2. Request is translated into an IP address via Domain Name Server.
  3. Browser connects to the server using the IP address.
  4. Apache receives the request for a specific file (e.g., index.php).
  5. Apache checks if the file has PHP code:
    • If yes, sends it to the PHP processor.
  6. PHP processes the code, potentially querying MySQL, then returns to Apache.
  7. Apache sends the interpreted output back to the browser.

PHP as a Pre-Processor

  • PHP code outputs HTML, CSS, or JavaScript.
  • Allows for interactive, dynamic web pages versus static ones.

Example Workflow (Google Search)

  • User types a query; request sent to Apache.
  • Apache forwards the request to PHP.
  • PHP queries MySQL for results.
  • Results are sent back through Apache to the browser.

Conclusion

  • PHP adds interactivity and dynamic capabilities to web applications.
  • Enables complex operations beyond static content.