It’s no surprise that a good chunk of folks that follow Effective Programmer Facebook page are aspiring programmers that want learn about web development. Whats surprising is that the biggest challenge they face in terms of getting started is setting up a local development environment.
The good news is that learning web development is actually a great way to get in the field. I highly recommend it and have talked about learning web technologies in the past too. In today’s post I want to cover how to setup a local web development environment with PHP programming language so you can start making websites and not worry about all the nitty gritty of installing all the required tools and software. All you need is a computer and a bit of Grit.
Let’s get started.
Step 1: Install Docker
To make it super simple I have created sort of a starter kit that you can download from GitHub and you will be 80% done, but in order for the package to work you need to download and install Docker. The reason behind this requirement is that in order to get everything installed and configured on your computer– from your local web server to PHP engine to database — it is a lot of things to get right. With Docker and using the package I’ve built for you guys it will be take only few minutes and you can then just focus on making your first website.
Simply go to the Docker download page, and download and install docker on your computer.
Step 2: Download the starter package from GitHub
Now that you have Docker running, download the starter kit from GitHub, or if you already know how to use git, simply clone my repository using the git clone command show shown here:
git clone https://github.com/naveed125/docker-lemp-app.git
Alternatively just use the download zip file link and unzip it.
Step 3: Start the local development environment.
Alright, you are almost there. Simply open a command prompt on your computer, cd to the directory where you downloaded the starter package and use “docker-compose” command to startup everything, as I show below.
C:\> cd C:\projects\docker-lemp-app C:\projects\docker-lemp-app> docker-compose up -d Creating network "docker-lemp-app_default" with the default driver Pulling db (mysql:)... latest: Pulling from library/mysql 8559a31e96f4: Already exists a6b5dc864b6c: Pull complete Digest: sha256:8b7b328a7ff6de46ef96bcf83af048cb00a1c86282bfca0cb119c84568b4caf6 Status: Downloaded newer image for mysql:latest Pulling web (naveed125/nginx-php-fpm:latest)... latest: Pulling from naveed125/nginx-php-fpm e423b3f563c7: Pull complete 9644d0860cc7: Pull complete 77f061ce98c3: Pull complete Digest: sha256:4681feb29917026afde080562ca97a23815571510303604e0ffe1824ddc8d79a Status: Downloaded newer image for naveed125/nginx-php-fpm:latest Creating docker-lemp-app_db_1 ... done Creating docker-lemp-app_web_1 ... done
Step 4: Test your Environemnt
That’s it, you’re done and ready to build your web applications. Try it, open your browser enter http://localhost and you should see something like this.
If you are wondering,
locahostis just a special name for your computer, you are just telling your browser to connect to the web server running locally.
You’re all set
At this point your local development environment is ready. To make changes to your website just find and change app.php file in the src directory and refresh your browser to see the changes.
Look at you, a brand new web developer! Where do you go next? start with the official PHP tutorial and start building your very first website. Feel free to reach out if you need help.