PHP Install & Setup: Step-by-Step Guide for Beginners
Step 1: Choose a PHP Installation Method
There are two ways to install PHP:
- Manually install PHP (Advanced users)
- 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)
- Download XAMPP from Apache Friends.
- Run the installer and select:
- Apache
- MySQL
- PHP
- Click Next and complete the installation.
- 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
inC:\xampp\htdocs\
with:
<?php
phpinfo();
?>
- Open
http://localhost/phpinfo.php
to verify installation.
โ WAMP (Alternative for Windows)
- Download WAMP from wampserver.com.
- Install and launch WAMP.
- Click the WAMP icon in the system tray and start the services.
macOS:
โ MAMP (Recommended)
- Download MAMP from mamp.info.
- Install and start MAMP.
- Open
http://localhost/MAMP/
to verify installation.
โ Using Homebrew (Advanced Users)
- 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)
- 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:
- 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
- XAMPP:
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
- XAMPP:
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? ๐