Dockerize your Laravel App or any PHP projectsHardik
I have spent dozens of hours understanding how it actually works by experimenting with different commands it has.
Face the same issue as other developers do, I want to run different PHP versions in my computer without installing multiple software like (Xampp, Wamp, easyPHP etc.)
So the solution is Dockerizing my PHP projects.
In this article we’ll cover/learn how to install:
- PHP (7.3) — This can be any version you want
- MySQL (5.7) — Again you can modify as per your project needs
- Nginx Server
- PHPMyAdmin — for development purpose
Before we get started, make sure you have Docker installed.
I have done all the work for you, just clone this repository and follow the steps mentioned below:
Cone the repository
git clone https://github.com/Tech-49/Docker-PHP-MySQL-Nginx php-app
Build the services & start the server. This will take a while to download all the images for the first time.
Make sure all the services are running
If you see everything is “Up” under the status column then the next step is to test your application.
Head over to the browser and type
http://localhost:8080 you should see the following output.
For PHPMyAdmin type
Username : homestead
Password : secret
If you want to change this credential you can do it from
Some useful commands:
- To SSH to your container use
docker exec -it <container_name> /bin/bash
- Execute commands without login to ssh (For example Laravel app)
docker exec -it php-app_app1 php artisan migrate
- To build the app
- To restart all the services
- To stop all the services
Once you SHH to your container you can install Laravel using composer. For example:
composer create-project --prefer-dist laravel/laravel lara-app