🔍
👶 Kids📝 Blog About Contact 🚀 Get Started Free

PHP – Install

Learn how to install PHP on Windows, macOS, and Linux. Set up XAMPP or a standalone PHP environment and run your first local PHP script.

Installing PHP Locally

As you learned in the Introduction, PHP is a server-side language. That means your web browser (Chrome, Firefox, Safari) cannot understand or run raw .php files by double-clicking them. If you try to open a PHP file directly, you will just see the raw code!

To test and write PHP on your home computer, you need to trick your computer into behaving like a real internet web server. We do this by installing a Local Development Environment.

The Web Stack (AMP)

Running PHP properly requires three major components working together:

  1. Apache (or Nginx): The actual Web Server software that listens for requests.
  2. MySQL: The database management system.
  3. PHP: The processing language itself.

Together, these form an “AMP” stack. Instead of installing all three complicated parts separately, developers use free, pre-packaged software bundles that install everything seamlessly with one click.

Depending on your operating system, there are several fantastic options:

1. XAMPP (Windows, Mac, Linux)

XAMPP is the most popular, oldest, and most widely used cross-platform local server environment. It stands for Cross-Platform, Apache, MariaDB(MySQL), PHP, and Perl.

  • Pros: Totally free, incredibly well documented, massive community support.
  • Cons: The user interface feels extremely dated.
  • Download: apachefriends.org

2. MAMP (Mac and Windows)

Originally built strictly for Mac (Mac, Apache, MySQL, PHP), it is now available for Windows too.

  • Pros: Clean user interface, easy to switch PHP versions.
  • Cons: The “Pro” version requires payment for advanced features like custom local domains.
  • Download: mamp.info

3. LocalWP / Laragon (For specific use cases)

  • LocalWP: If you are learning PHP specifically to work on WordPress themes or plugins, LocalWP generates completely working WordPress instances instantly alongside the database.
  • Laragon: An incredibly fast, lightweight alternative specifically loved by the Windows community.

Testing Your Installation

Once you have installed and started your chosen server software (like clicking “Start” next to Apache in the XAMPP control panel), you must place your PHP files in a specific folder so the server can read them:

  • XAMPP (Windows): C:\xampp\htdocs\
  • MAMP (Mac): /Applications/MAMP/htdocs/

Step 1: Create a new file in that folder named test.php.
Step 2: Add the following code to the file and save it:

<?php
  echo "My Local Server is Running Successfully!";
?>

Step 3: Open your web browser and navigate directly to http://localhost/test.php. If configured successfully, you will see your message displayed!

Or, Just Keep Using CodesCompiler! 🚀

While setting up a local server is a crucial rite-of-passage for any developer, you don’t actually need it right now to continue learning. By utilizing our WebAssembly interface below, you can write, parse, and execute raw PHP scripts completely free in your browser right now!

Preview