DEV Community

Hikari
Hikari

Posted on

PHP Local Development Environment Setup Guide: Everything You Need in One Article

What is a PHP Local Development Environment?

A PHP local development environment is a server environment simulated on a personal computer, allowing developers to develop, test, and debug PHP applications even without an internet connection. It's like having a mini "server" inside your computer, enabling you to work on PHP programs offline. This is the essence of having a PHP local development environment.

Typically, this environment includes the basics for running PHP programs, a web server (like Apache or Nginx), a database server (such as MySQL or MariaDB), and possibly other tools and services (like phpMyAdmin, Redis, etc.). The purpose of setting up such an environment is to simulate real website operations on your computer, allowing you to thoroughly check everything before actually launching your website online.

Image description

The benefits of using a PHP local development environment include:

  1. Rapid Iteration: Developers can quickly modify and test code in a local environment without the need to frequently upload files to a remote server.

  2. Offline Development: Developers can work without an internet connection, which is particularly useful when traveling or in areas without network access.

  3. Environment Control: Developers have the freedom to configure their local environment to match the configuration of online servers, ensuring application compatibility and stability.

  4. Security: Sensitive data (like database contents) is not exposed to external networks during local development, enhancing project security.

How to Create a PHP Local Development Environment?

There are two main ways to set up a PHP local development environment

  1. Manually setting it up (not recommended due to complexity and time consumption)

  2. Installing an Integrated Development Environment (IDE) software package (more common and recommended)
    Here are a few convenient and easy-to-install integrated development environments for your consideration:

XAMPP

XAMPP is a widely used PHP development environment that is cross-platform, compatible with Windows, Linux, and Mac OS X. It packages Apache server, MySQL database, PHP, and Perl into an all-in-one software package, making it highly suitable for beginners to quickly establish a development environment.

Image description

Pros:

  • Compatible with multiple operating systems.

Cons:

  • May not be as efficient as professional server environments for large or complex projects.
  • Default configuration may not be secure enough for production environments.
  • Only supports running one website, not suitable for multi-project environments.
  • Lacks free SSL certificates.
  • Slow version updates. Download

ServBay

ServBay is designed specifically for macOS and integrates popular services like Caddy server, MariaDB, PostgreSQL databases, Redis, Memcached, and other NoSQL databases, along with database management tools like phpMyAdmin and adminer. It simplifies network request routing and management through local DNS services. Additionally, ServBay includes a standalone development package, allowing developers to recompile and integrate unique or customized software, greatly enhancing the smoothness and efficiency of Web and PHP development.

Image description

Pros:

  • Allows running multiple hosts simultaneously, improving development efficiency.
  • Enhances local development security.
  • Supports custom domains and local DNS services, and the ability to recompile and integrate unique software.
  • Low system resource usage.
  • Supports SSL certificates and HTTPS access.

Cons:

WampServer

WampServer is a web development environment designed for Windows, integrating Apache server, MySQL database, PHP, and phpMyAdmin. Its features are similar to XAMPP, offering an intuitive user interface for managing server configurations and databases. It supports quick switching between PHP versions, enabling developers to easily test different PHP environments.

Image description

Pros:

  • One-stop installation simplifies the development environment setup.
  • Easy management of server settings and service startup/shutdown without deep backend configuration knowledge. Cons:
  • Only supports Windows.
  • Updates are delayed, and users may need to manually update for new features and security patches. Download

Laravel Homestead

Laravel Homestead is an official Vagrant box designed specifically for Laravel application development but can also be used for general PHP projects. It provides a complete, unified virtual development environment without the need to install PHP, web servers, or any other server software on the local machine.

Image description

Pros:

  • Provides a unified development environment without additional server software installation.
  • Optimized for Laravel application development but suitable for other PHP projects.
  • Based on Vagrant, supporting multiple host operating systems.

Cons:

  • Initial setup may be complex for users unfamiliar with Vagrant or virtual machines.
  • Virtual machines may consume significant system resources.
  • Complex architecture, challenging maintenance. Download

Docker

Although Docker is not specifically designed for PHP development, it offers a containerized approach to create, deploy, and run applications. By using Docker, developers can easily install PHP, web servers, databases, etc., in containers, achieving a fast, consistent development environment setup.

Image description

Pros:

  • Provides a consistent development environment, easy to deploy and scale.
  • Supports Windows, Linux, and Mac, with containers performing consistently across systems.
  • Uses fewer resources compared to virtual machines. Cons:
  • Steep learning curve, requiring understanding of containerization concepts and Docker operations.
  • Container configuration and network setup may be complex for beginners. Download

PHP Built-in Web Server

Starting from PHP 5.4.0, PHP has included a simple web server. With a simple command, developers can quickly start a web server for development. This built-in web server is particularly suitable for small projects or quick testing during development.

Image description

Pros:

  • No additional installation required, easily started with a simple command.
  • Suitable for small projects or quick testing, uses minimal resources. Cons:
  • Not suitable for complex development and testing needs.
  • Performance is not as good as professional web servers. Download

Conclusion

Each development environment has its unique advantages and suitable scenarios. The choice depends on individual development habits, project requirements, and operating system platforms. This article aims to help you find the most optimal and suitable PHP local development environment for you.

Top comments (12)

Collapse
 
aerendir profile image
Adamo Crespi

You forgot symfony cli: no no no, this is a big no 😬

Collapse
 
hikarimaeda profile image
Hikari

Thanks for your suggestion. I'll look into it :)

Collapse
 
javdome profile image
Javi Domenech

For Windows, Laragon is the Best.

Collapse
 
hikarimaeda profile image
Hikari

Agree.
I'm Mac user.

Collapse
 
nasoma profile image
nasoma

The cons listed for Laravel Herd are simply not true. There's nothing complex about setting up Laravel Herd, it has nothing to do with vagrant or virtual machines.

This looks like a LiesGPT article.

Collapse
 
hikarimaeda profile image
Hikari

I don't think we're talking about the same thing.

Collapse
 
meiyo profile image
Meiyo

Herd and Homestead are not the same thing.

Collapse
 
n3m3s7s profile image
Fabio Politi

Hi,
And what about Laravel Herd? (I think some days ago they made a Windows version too)

Collapse
 
fullfull567 profile image
fullfull567

herd is quite simple, lots of functions have to paid to unlock, including service management

Collapse
 
erickmercedesc profile image
erickmercedesc

For Window i'm in love with Laragon

Collapse
 
icolomina profile image
Nacho Colomina Torregrosa

I'm docker fan :)

Collapse
 
meiyo profile image
Meiyo

Laragon is interesting.
Herd have potential... but not worse the price to me.