Getting Started with PHP

PHP (Hypertext Preprocessor) is a popular server-side scripting language used for web development. In this tutorial, we’ll go over how to install PHP and run your first PHP script.

Step 1: Install PHP

Follow these steps to install PHP on your system:

  1. Download PHP: Visit the official PHP website at php.net/downloads and download the latest stable version.
  2. Install PHP: Follow the installation instructions specific to your operating system:
    • Windows: Use the PHP installer or install PHP as part of a package like XAMPP.
    • Mac: Use brew install php if you have Homebrew installed.
    • Linux: Use your package manager, for example: sudo apt install php (Ubuntu/Debian).
  3. Verify Installation: Run php -v in your terminal or command prompt. You should see the PHP version displayed.

Step 2: Set Up a Local Server

To run PHP code, you need a local server. Here’s how to set one up:

  • Using XAMPP: Download and install XAMPP. Start the Apache server from the XAMPP control panel.
  • Using the Built-in PHP Server: Navigate to your project folder and run php -S localhost:8000.

Step 3: Write Your First PHP Script

Create a new file named index.php and add the following code:

<?php echo "Hello, World!"; ?>

Save the file in your server’s root directory (e.g., htdocs for XAMPP).

Step 4: Run Your Script

Open your browser and navigate to http://localhost/index.php. You should see:

Hello, World!

Next Steps

Now that you’ve set up PHP, explore its syntax and features. Try creating dynamic web pages and connecting to a database like MySQL. Happy coding!