DEV Community

Heather
Heather

Posted on

What do you need for a PHP local development environment?

Using a local dev environment is standard practice, and yet, getting a stack that is easy to set up and use is still a challenge. If you’re using a Mac, many tutorials recommend building the development environment natively, since Apache is bundled with macOS. 

Adding a few elements seems easy, after all, a local development environment for PHP includes at minimum two things:

  • A web server configured to compile and run your PHP scripts on the fly and serve them to your browser.
  • A database server to pull data and render it in your PHP application.

However, that isn’t enough in most cases. You may also want to make it easier to manage and test your application, so you would also need:

  • SSH access.
  • An email catch-all.
  • And what about local SSL support?
  • Virtual hosts to easily access your works-in-progress in your browser.

To set these up, even for one site, you’re looking at some detailed configuration. If you were just managing ONE site, it wouldn’t be a problem. However, to make it easier to add and manage multiple sites, you might also want:

  • A way to start and stop services.
  • Some way to manage those databases, like PHPMyAdmin.
  • Configuring specific versions of your PHP projects
  • A way to manage custom environment variables.

And once you starting adding all of those packages to manage these, you need some way to manage them and keep them up to date. Oh... and what if you want to add new projects without repeating the same setup each time? This is why Docker containers have gotten more popular in the last few years.

Docker shows up well comparison to other options like VMs when it comes to lightweight local development. Docker containers are faster and they don’t consume a lot of resources. With Docker Compose, you can manage different packages and dependencies. For example, you can set up different PHP environments per project, or add services like Apache Solr.

The main issue with Docker? That is a lot to manage and maintain and takes considerable knowledge of Docker to set up. So! There have been many local development tools released which package up the tools you need, and make it work. One of these options is DDEV-Local, which is completely free and open source. It comes with everything you need to create local development and quickly deploy to production.

Here's a video tutorial showing you how to set up DDEV-Local from scratch on macOS. This gives you a complete PHP development environment with developer tools like:

  • MySQL Client (mysql) – Command-line interface for interacting with MySQL.
  • Composer – Dependency Manager for PHP.
  • Drush – Command-line shell and Unix scripting interface for Drupal.
  • WP-CLI – Command-line tools for managing WordPress installations.
  • MailHog mail catcher for email capture and review.

Read more about the developer tools in the docs.

Need any help? Post your questions tagged with #ddev on Stack Overflow.

Top comments (5)

Collapse
 
belinde profile image
Franco Traversaro

I usually don't use a local web server: php -S localhost:8000 is usually enough, because normally you don't have to check for SSL in PHP. I don't use virtual hosts since forever, I just run php -S on different ports. For email catch-all I usually use Gmail pseudo aliases: myrealaddress+somerandomshit@gmail.com

For database management PHPMyAdmin is quite terrible: I use SQLyog, is for windows but run perfectly on linux with wine; the community version is fine, the commercial one has some tools very useful (code autocompletion with database references, synchronization tools of database data and/or structure).

Add just and IDE, whatever you want. With this environment I can do the 99% of my work. Every time I tried docker I got stuck, wondering "why I'm doing this?"

Collapse
 
garthvador profile image
Quentin Caillaud • Edited

I agree, most of the time php -S is good enough and simpler than a web server.

Collapse
 
perttisoomann profile image
Pert Soomann

Excellent breakdown.

On DB management, I found really neat tiny alternative to PHPMyAdmin couple of years back called Adminer - adminer.org/

PMA might have changed it since, but we ran into issues when browsing list of tables that had a lot of data and PMA just couldn't calculate the per table stats quick enough to be usable anymore.

Adminer shows tables, then uses AJAX to fetch any additional data.

It's just a single PHP file, with optional custom CSS themes, so very easy to set up.

Collapse
 
nearlythere profile image
Heather

Ooo that looks good! I wonder if the folks that bundle tools in #DDEV should think about that alternative.

Collapse
 
kyslik profile image
Martin Kiesel

Valet all the way.