---
title: 'How to Deploy Any Version of PHP in Docker-Compose | Zomro'
description: 'In this article, we will look at how to deploy any version of PHP using Docker-Compose, which is especially useful for developers and system administrators.'
image: 'https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/07/02/image-20230702235047-1.jpg'
---

![opened image]()

  * [Zomro](https://zomro.com/)
  * [FAQ](https://zomro.com/blog/faq/)
  * How to Deploy Any Version of PHP in Docker-Compose 



# How to Deploy Any Version of PHP in Docker-Compose

30-06-2023

Docker and Docker Compose are powerful tools for deploying and managing containers. In this article, we'll look at how to deploy any version of PHP using Docker-Compose, which is especially useful for developers and system administrators. We'll show you a step-by-step process for deploying PHP using Docker and Docker Compose.

  1. ## **Installing Docker and Docker Compose**




.

First of all, you need to install Docker and Docker Compose on your system. You can install Docker by following the instructions in the [How to install PostgreSQL and pgAdmin in Docker](https://zomro.com/rus/blog/faq/283-kak-ustanovit-postgresql-i-pgadmin-v-docker) and similar articles on our website.

  2. ## **Create project**




.

Create a new folder for your project and navigate to it:
    
    
     mkdir my-php-project cd my-php-project

  3. ## **Create Dockerfile**




In the project folder, create a file named **`Dockerfile`**. This file contains instructions for building the Docker image with the correct version of PHP.
    
    
     vim Dockerfile

.

Inside the file, replace `7.4` with the correct version of PHP:
    
    
     FROM php:7.4-apache
    
    RUN docker-php-ext-install pdo_mysql

![How to Deploy Any Version of PHP in Docker-Compose - 1](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/07/02/image-20230702235047-1.jpg)

This code tells Docker to use the official PHP image version **7.4 with Apache**. It then installs the **`pdo_mysql`** extension to work with MySQL.

  4. ### **Create file docker-compose.yml**




Create a file named **`docker-compose.yml`** in the project folder. This file contains the configuration for running PHP and MySQL containers. Inside the file, insert the following code:
    
    
     version: '3.8'
    
    services:
      php:
        build:
          context: .
          dockerfile: Dockerfile
        volumes:
          - .:/var/www/html
        ports:
          - 9900:80
    
      mysql:
        image: mysql:5.7
        environment:
          MYSQL_ROOT_PASSWORD: rootpassword
          MYSQL_DATABASE: mydatabase
          MYSQL_USER: myuser
          MYSQL_PASSWORD: mypassword
        volumes:
          - mysql-data:/var/lib/mysql
    
    volumes:
      mysql-data:
    

Two services are defined in this configuration: **`php` and `mysql`**. The `php` service uses the image built from the file **`Dockerfile`** , and the **`mysql` ** service uses the official MySQL image version 5.7. This also specifies the environment and volume settings for saving MySQL data.

![How to Deploy Any Version of PHP in Docker-Compose - 2](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/07/02/image-20230702235148-2.jpg)

  5. ### **Assembling and launching containers**




.

In order to build and start containers, execute the following command in the terminal:
    
    
     docker-compose up --build -d 

.

![How to Deploy Any Version of PHP in Docker-Compose - 3](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/07/02/image-20230702235207-3.jpg)

This command will build a PHP image from your **`Dockerfile`** , download a MySQL image, and run both containers in the background. Once executed, the containers are up and running and available for use.

  6. ### **Check containers**




To verify that the containers are up and running successfully, run the following command:
    
    
     docker-compose ps

.

![How to Deploy Any Version of PHP in Docker-Compose - 4](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/07/02/image-20230702235216-4.jpg)

You should see a list of running containers and their statuses. If everything is OK, you should see that both containers are running.

  7. ### **Creating a PHP test file**




Now that our containers are up and running, let's create a simple PHP file to test that our configuration works. In the project folder, create a file named `index.php` and insert the following code:
    
    
     <?php phpinfo();

![How to Deploy Any Version of PHP in Docker-Compose - 5](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/07/02/image-20230702235234-5.jpg)

  8. ### **Access the PHP file via browser**




In order to access your PHP file through a browser you need to find out the IP address of your server. Use the following command:
    
    
     ip a

You will be presented with the IP address of your server. Enter this IP address into the browser address bar and port **9900** and you should see the version of PHP you have installed.
    
    
     http://your_ip:9900/index.php

.

![How to Deploy Any Version of PHP in Docker-Compose - 6](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/07/02/image-20230702235259-6.jpg)

**Closure**

In this article we have seen how to deploy any version of PHP using Docker-Compose. You can now easily set up and use different versions of PHP for your projects which can greatly simplify the process of developing and managing environments. Follow these simple steps and you can successfully deploy PHP in Docker-Compose.

We also suggest you other useful articles:

  * [How to Deploy Any Version of PHP in Docker-Compose](https://zomro.com/blog/faq/348-how-to-deploy-any-version-of-php-in-docker-compose-for-beginners)
  * [List of important commands for working with Docker-compose](https://zomro.com/blog/faq/304-spisok-vazhnyh-komand-dlja-raboty-s-docker-compose)
  * [How to install Nginx in Docker-Compose](https://zomro.com/blog/faq/317-kak-ustanovit-nginx-v-docker-compose)






.

Similar articles:

[How to order DNS hosting service in new billing](https://zomro.com/blog/faq/233-kak-zakazat-uslugu-dns-hostinga-v-novom-billinge) [MacOS: How to perform MTR check](https://zomro.com/blog/faq/101-macos-kak-vypolnit-proverku-mtr) [Adding resource records to a domain in DNS hosting](https://zomro.com/blog/faq/296-dobavlenie-zapisej-v-dns-hosting) [How to install and configure phpMyAdmin on Windows Server](https://zomro.com/blog/faq/367-how-to-install-and-configure-phpmyadmin-on-windows-server) [How to connect to a server via FTP, SFTP, and SCP](https://zomro.com/blog/faq/144-kak-podkljuchitsja-k-serveru-po-ftp-sftp-i-scp)

[ Forex Server from €7.95/mon ](/server-for-forex)
