PHP Install & Setup: Step-by-Step Guide for Beginners

Step 1: Choose a PHP Installation Method

There are two ways to install PHP:

  1. Manually install PHP (Advanced users)
  2. Use a local server environment (Recommended for beginners)

Step 2: Install a Local Server Environment (Recommended for Beginners)

Using a local server package is the easiest way to set up PHP, as it includes PHP, Apache, and MySQL in one package.

Windows:

โœ… XAMPP (Recommended)

  1. Download XAMPP from Apache Friends.
  2. Run the installer and select:
    • Apache
    • MySQL
    • PHP
  3. Click Next and complete the installation.
  4. Open XAMPP Control Panel and start Apache & MySQL.

๐Ÿ“Œ Check PHP Version

  • Open http://localhost/dashboard in your browser.
  • Or create a new file phpinfo.php in C:\xampp\htdocs\ with:
<?php
phpinfo();
?>
  • Open http://localhost/phpinfo.php to verify installation.

โœ… WAMP (Alternative for Windows)

  1. Download WAMP from wampserver.com.
  2. Install and launch WAMP.
  3. Click the WAMP icon in the system tray and start the services.

macOS:

โœ… MAMP (Recommended)

  1. Download MAMP from mamp.info.
  2. Install and start MAMP.
  3. Open http://localhost/MAMP/ to verify installation.

โœ… Using Homebrew (Advanced Users)

  1. Install Homebrew if not already installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install PHP:

brew install php

Verify installation:

php -v

Linux:

โœ… Using Terminal (Ubuntu/Debian)

  1. Update system packages:
sudo apt update && sudo apt upgrade -y

Install PHP and Apache:

ย 
sudo apt install php libapache2-mod-php -y

Restart Apache:

ย 
sudo systemctl restart apache2

Verify installation:

ย 
php -v

โœ… For Red Hat/CentOS:

  1. Install PHP:
sudo yum install php

Restart Apache:

sudo systemctl restart httpd

Check PHP version:

php -v

Step 3: Configure PHP (Optional but Recommended)

  • Locate your PHP configuration file (php.ini):

    • XAMPP: C:\xampp\php\php.ini
    • WAMP: C:\wamp64\bin\php\php.ini
    • Linux/macOS: /etc/php.ini or /etc/php/7.x/apache2/php.ini
  • Enable error reporting for debugging:

display_errors = On
error_reporting = E_ALL

Set timezone:

date.timezone = "America/New_York"

Step 4: Test Your PHP Installation

  • Open your text editor (Notepad++, VS Code, Sublime Text).

  • Create a new file: test.php.

  • Add the following code:

<?php
echo "PHP is working!";
?>
  • Save the file in the server root directory:

    • XAMPP: C:\xampp\htdocs\test.php
    • WAMP: C:\wamp64\www\test.php
    • Linux/macOS: /var/www/html/test.php
  • Open your browser and go to:

http://localhost/test.php

Step 5: Next Steps

โœ… Install a Code Editor (VS Code, PHPStorm, Sublime Text)
โœ… Learn PHP Basics (Variables, Loops, Functions)
โœ… Connect PHP to MySQL Database


๐Ÿš€ Done! Now youโ€™re ready to start coding with PHP!
Would you like a guide on PHP with MySQL setup next? ๐Ÿ˜Š