3 Ways to Create a Local PHP Development Environment

Get PHP Local Dev Environment | InMotion Hosting

For many users just starting out in web development, one of the greatest challenges is not learning the code itself but seeing your results in the browser. The problem is, you need to first set up a proper PHP development environment to get your code to run in the browser.

If you use PHP Composer, no worries, it’s available in all InMotion Hosting accounts.

PHP Is a Server-side Scripting Language

As you’re just starting out in coding for the web, you are probably already aware that the web code you write locally must be run in a web browser. HTML and JavaScript will run in a web browser by default. However, in order to run PHP files, the PHP program must be running.

In a web hosting account, PHP is enabled by default. This is why PHP is referred to as a “server-side scripting language.” But, you don’t need a server to start running PHP code locally.

Run Default PHP Server

This is the easiest way to instantly get PHP code into your browser, but it’s also limiting for development of larger projects. If you’re looking for a quick and easy way to see the output of some basic PHP functions, you can use the PHP built-in web server.

All you need is a folder, with a PHP file in it, and a terminal session. In order to start the PHP server in that folder, run this command from the location where the files are located:

php -S localhost:8000

If you go to that address localhost:8000, you will be able to see PHP running beautifully in your web browser.

Bear in mind, you need to have PHP already installed on your computer. But if you have a Mac, for example, PHP is already installed, and you can run this command right away.

Easy Ways To Get a LAMP Stack Going

If you don’t have PHP installed, you can go ahead and install it, but there are easier ways to get PHP and other software for web development all in one package. You’ve probably heard the term “LAMP stack,” which stands for Linux, Apache, MySQL, and PHP (all important web development software). However, you don’t need the “Linux” part in order to get the rest. There are apps available for Mac and Windows that give you everything you need for web development in your current operating system.

Below we will cover some of the most popular options:

Laragon
a free app that lets you run the “AMP” stack from within Windows. Some of the features include SSL and a suite of one-click installs for popular programs like WordPress. Get a local WordPress development site up and running in a few seconds. (You know you’ve always wanted one.)
MAMP
Mamp (free) and Mamp Pro (paid) give you a local development environment complete with the necessary apps. The pro version lets you more easily create multiple hosts with a comfortable user interface.
XAMPP
Like the above MAMP package, XAMPP gives you many of the same tools, but in a slightly different interface.

You’ll find that virtually all “AMP” products give you the same basic effect, however they will differ in other factors concerning user interface. This is why it’s best to do a trial of each in order to get a feel for them and see which one works best with your work style.

Virtual Containers For PHP Development (Master Level)

Using “AMP” stacks is an easy, fun way to get started with your web development. You can literally run a complete web server with one simple installation. For learning the basics of web development, and most professional applications, this is enough.

However, on the higher end, some developers prefer to use virtual containers. A container is basically a small virtual computing environment with the bare minimum software required to simulate a whole server.

The advantage of using a container comes with the ability to replicate the precise conditions in virtually any other container. This way, your development environment can match your production server exactly.

Even better, all of the most popular container software is free. However, they are rather difficult to learn. However, becaue they’re free, you can install one and follow a course online to start playing around. Docker has proven to be one of the more popular container solutions, but there are others out there for you to try out.

One thought on “3 Ways to Create a Local PHP Development Environment

  1. If you are macOS user, ServBay.dev is a good tool, especially for the beginners. It handles all PHP, MariaDB, PostgreSQL versions, plus redis and memcached. Run multiple PHP instances simultaneously and switch easily. This tool has made my PHP dev simpler. Worth a shot!

Was this article helpful? Join the conversation!