This is a repository that use Docker to develop PHP applications. If you want to develop a PHP application, this is the right repository that you can use.
This docker environment comes with:
- ✅ PHP (8.1, 8.2, 8.3)
- ✅ Composer (latest)
- ✅ Apache (latest)
- ✅ MySQL (latest)
- ✅ SQLite (3)
- ✅ phpMyAdmin (latest)
Soon:
- 🕔 Git
- 🕔 MariaDB
- 🕔 PostgreSQL
- 🕔 SQL Server
- 🕔 Redis
- Clone this repository
- Delete the
.gitdirectory - Copy
.env.exampleto.env - Select your
PHP_VERSIONin.env. Available versions:8.1,8.2and8.3.
Or because this is a public template, you can just use this template to create a repository.
In this docker environment, we will use docker compose to run our services at once.
To run this docker environment, you simply type this:
sudo docker compose up -d
# or
sudo docker-compose up -d
# depends on your docker compose versionImportant
If you encounter permission problem as described in pull request number #7
you have to run sudo docker compose run --rm app bash -c "sudo chown -R \$(whoami): /home/\$(whoami)/application" first.
Then smash the enter button, and you are ready to go.
sudo docker compose run --rm app rm .gitkeep && sudo docker compose run --rm app composer create-project laravel/laravel .# run this if you are building a traditional web application
sudo docker compose run --rm app rm .gitkeep && sudo docker compose run --rm app composer create-project symfony/skeleton:"7.0.*" .
sudo docker compose run --rm app composer require webapp
# run this if you are building a microservice, console application or API
sudo docker compose run --rm app rm .gitkeep && sudo docker compose run --rm app composer create-project symfony/skeleton:"7.0.*" .sudo docker compose run --rm app rm .gitkeep && sudo docker compose run --rm app composer create-project slim/slim-skeleton .If you want to install another framework, just run:
sudo docker compose run --rm app rm .gitkeep && sudo docker compose run --rm app composer create-project another/framework .Or if you prefer not to use a framework, you can do that as well.
sudo docker exec -it app bashNote: If you run a development server with
php -S <host>:<port> -t public,php artisan serveor any other console command that serve the application, make sure you set the host to0.0.0.0so it can be accessible from outside the container.
If you want to use apache web server to serve your application, you can do that simply by creating a symlink from your application entrypoint to the web server entrypoint. By default, the web server entrypoint is in the /var/www/html directory.
Example (Laravel)
- Enter the application container
sudo docker exec -it app bash- Remove the default web server entrypoint
sudo rm -rf /var/www/htmlif it ask you for your password, just type password and hit enter.
- Create a symlink from your application entrypoint to the web server entrypoint
sudo ln -s /home/me/application/public /var/www/html- Done ✅. Now, your application is served by the web server and you can access it on your local machine at
http://localhost:8080.