Would you like to learn how to install Apache with PHP support enabled using Docker on Ubuntu Linux? In this tutorial, we are going to show you all the steps required to perform the PHP installation using Docker on a computer running Ubuntu Linux in 5 minutes or less.

• Ubuntu 20.04
• Ubuntu 18.04
• Ubuntu 19.04
• Apache 2.4.38
• PHP 7.4

Equipment list

The following section presents the list of equipment used to create this tutorial.

As an Amazon Associate, I earn from qualifying purchases.

Tutorial PHP – Docker Installation on Ubuntu Linux

Install the Docker service.

Copy to Clipboard

Download the PHP Docker image with Apache embedded.

Copy to Clipboard

List the Docker images installed on your system.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

Create a docker volume for persistent data.

Copy to Clipboard

Verify the persistent data directory.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

Optionally, create a symbolic link to an easier access location.

Copy to Clipboard

Start an Apache container with PHP support and persistent data storage.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

In our example, the Docker image was used to start a new container.

The new container is using the local port 80.

The container ID is 952fc4dd7a424846aeffcf05f3307fbd46c41ad78b2349e77565d43b34d8f120.

Congratulations! You have finished the PHP Docker installation on Ubuntu Linux.

Tutorial Apache – Testing the Docker installation

Create a PHP test page inside the Docker volume.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Open your browser and enter the IP address of your web server.

In our example, the following URL was entered in the Browser:

• http://192.168.100.10/test.php

The Apache server will display the PHP test page.

PHP Docker installation

Congratulations! Your PHP Docker installation was tested successfully.

Tutorial PHP – Docker container management

Verify the status of all Docker containers using the following command:

Copy to Clipboard

Verify the status of the Apache container using the ID or its name.

Copy to Clipboard

To stop the Apache container service, use the following command:

Copy to Clipboard

To start the Apache container service, use the following command:

Copy to Clipboard

To restart the Apache container service, use the following command:

Copy to Clipboard

In case of error, use the following command to verify the Apache container logs.

Copy to Clipboard

In our examples, we demonstrated how to manage the PHP container using its ID or the name previously defined.