A local development environment is the set of tools that allows you to run and test PHP on your own computer.
To write HTML you only need Notepad. To write PHP, we need something more powerful: a Server.
As we explained in the introduction, PHP works in the “backend”. Your browser doesn’t understand PHP, so we need to simulate a web server on your own computer to interpret the code before displaying it.
We call this a Local Development Environment.
What do we need to install?
Basically, we need the “Combat Pack” of web development, often known by its acronym (WAMP/LAMP):
- Web Server: (Usually Apache or Nginx). It’s the “receptionist” that accepts requests.
- PHP: The brain that processes the code.
- Database: (MySQL or MariaDB). Where we will store the information.
Installing these components one by one manually is tedious and error-prone. That’s why we use “all-in-one packages”.
The options: which one do I choose?
There are several valid options. The best one depends on your operating system and how much you want to deal with infrastructure while learning.
XAMPP, the classic
It’s the veteran. You probably used it in university or saw it in old tutorials.
- Pros: Works on Windows, Linux, and Mac. It’s very well-known.
- Cons: Changing versions or adjusting each component is less convenient than in other alternatives.
- Verdict: It’s still valid to start if you already have it installed and updated.
Docker, reproducible environments
Docker creates isolated containers and allows you to describe the project environment through configuration files.
- Pros: Makes it easy for the team to use equivalent versions and services, although production won’t necessarily be identical.
- Cons: Adds concepts and configuration that can distract you if your immediate goal is to learn PHP.
- Verdict: It’s a very useful option, but you can leave it for later.
Laragon, the recommendation for Windows
If you are on Windows, Laragon is a particularly comfortable option to follow the course.
- Pros: Simplifies installation and management of common services.
- Highlighted Feature: Allows changing PHP versions and creates automatic virtual domains (you can go to
myproject.testinstead oflocalhost/myproject). - Verdict: This is the option we will use in the Windows examples.
Note for Mac/Linux users: Laragon is only for Windows.
- macOS: You can use Herd, Homebrew, or MAMP.
- Linux: You can install PHP and the necessary extensions with your distribution’s package manager.
Let’s get to work: installing Laragon
Let’s set up the winning environment in 3 steps:
Download: Go to the official Laragon website and download the Full version.
Installation: “Next, Next, Next.” No mystery here.
Start: Open Laragon and press the “Start All” button.
If you see Apache and MySQL turn green… Congratulations! You now have a web server on your machine.
Checking the PHP version
We need to ensure we are using a supported branch. Nowadays, it’s preferable to work with PHP 8.4 or 8.5.
- In Laragon, click the Terminal button.
- Type the following command and press Enter:
php -vYou should see something like PHP 8.4.x or PHP 8.5.x.
If you see this, you’re ready to write code.
The code editor
Please, don’t write code in Notepad. You need tools that help you (autocomplete, error detection, syntax highlighting).
The industry standard today is Visual Studio Code (VS Code). It’s free, lightweight, and from Microsoft.
Recommended extensions
To make VS Code help you with PHP like a professional, install these extensions (search for them in the box icon on the left):
- PHP Intelephense: Adds autocompletion, warns if you use variables that don’t exist, and helps you navigate the code.
- Material Icon Theme: (Optional) To make your files look nice and organized.