Docker Template Stack PHP

A DTS container for PHP projects

View project on GitHub


This file is part of: PHP Development Template Stack Copyright (c) 2025 Nico Jan Eelhart This source code is licensed under the MIT License found in the ‘LICENSE.md’ file in the root directory of this source tree.(last update: 02 jan. 2025)


Quick Setup

This is the quick setup for the PHP developer stack container consists of a Base Container and several Sub Containers. The Base Container is required for any Sub Container. The Sub Containers contain the development environments for the template application projects running on Linux.

Available container

Container name Description
compose_apache_php_cont The basic container, includes Symfony
compose_UnitTest_Addon.yml Adds composer abd PHP unit test
compose_apache_php_swarm Creates the container as a swarm, example of swarm

1 Setup steps

These are the quick setup steps for the PHP developer stack container. If you have previously installed this (or a similar) container, you can use these setup step, otherwise please first read the main documentation page howto_create_a_dev_container.

Consider Project setup and external network
If your application requires other independent Docker containers (such as a database), consider using an external network. This allows your Docker Compose setup to communicate with other standalone containers within the same network. For an example, see my document project-setup.md, which covers this in detail. Additionally, my GitHub repository includes a section with specialized Docker templates, which I have named Docker-Template-Plugin-Stacks. (todo soon)


1) Create docker base PHP container
Enter the sub directory ./ApachePHPWebService. Open a command prompt and use the following to create the basic docker base container, on which the sub-containers depends on

docker-compose -f compose_apache_php_cont.yml up -d --build --force-recreate --remove-orphans 

Expected results: This will create a basic PHP project structure which you can develop future local in the host or in the container it self
In docker a new service called: apachephpwebservice,
° Start it!
This page should display the PHP info page
This page should display the PHP Symfony application(Website I)
In case of an error you have to run composer install first from: /htdocs/symfony-apps/wiki-store
This page should display the PHP Raw app (website II)
The Apache2 Document root can be adjusted here: /usr/local/apache2/conf/extra/httpd-vhosts.conf
° Current document root/source at: /usr/local/apache2/htdocs/
° make sure it has the www-data owner and permissions chown -R www-data ./htdocs and chmod -R 755 ./htdocs
° To start a Symfony project use: symfony new projectname and update the Document root to the public directory created, and set the www-data owner and permissions.
° After that copy the /usr/local/apache2/htdocs/.htaccess file to the new public root directory (restart)
° a bind mount to that folder, local, can be found in the ./ApachePHPWebService/app/
♦ A general bind mount folder, local, can be found at: /usr/local/ApachePHPWebService/shared-host Which is known at the server as: /shared-host


Additional Docker commands for your convience

  • Container info:
    docker ps
  • Stop the container:
    docker stop [container id]
  • Start the container:
    docker compose -f compose.yaml up -d
  • Error and access log:
    docker logs -f <container id>
  • Filter Log:
    docker logs -f <container id 2>&1 | grep "error"



2) Create sub-container: PHP package manager & PHP UnitTest
Adds the composer package manager and the PHP Unit tests framework. Enter the sub directory ./ApachePHPWebService and open a command prompt and use the following command

docker  compose -f compose_UnitTest_Addon.yml up -d  --remove-orphans --build --force-recreate --remove-orphans  

Expected results:
Open a CLI in the container and execute:

phpunit --version		# Should return version of Phpunit
composer -V		        # Should return version of Composer

</small>

3) Create sub-container: Add Python front-end using pySide6 (Qt)
Adds Python with PySide 6 (Qt Based to the container) Enter the sub directory ./ApachePHPWebService and open a command prompt and use the following command

docker  compose -f compose_python_frontend_addon.yml up -d  --remove-orphans --build --force-recreate  

Expected results:
Open a CLI in the container and execute:

python3 --version && pip3 show PySide6  # Should display Python and pyside information

</small>

4) Configure and start the sub container in Visual Studio Code (VSC)
After this you should be able to open the container in VSC and start developing, you can do this local or by attaching to the container in VSC

VSC In the container

  • Open VSC
  • Select the Docker tab and select the container ‘apachephpwebservice-webserver-apache-php’ right click ‘attach Visual Studio Code’
  • In VSC choose: ‘open folder’ and select the directory ‘/usr/local/apache2/htdocs’*, This should open your PHP project in the container
  • You can create a new symphony project with symfony new my_api_project, make sure to set the Document root to the public folder of the new created project, probably you also need a .htaccess file.

VSC local

  • Open VSC
  • In VSC choose: ‘open folder’ and select your project directory this will open your PHP project locally.

More information!
See the main documentation page how to create a development container. Which explains the installation of the Base Container and any available Sub Containers in more details.

Home Sites
















Maintained by NicoJanE. Generated by GitHub Pages.