Home >Backend Development >PHP Tutorial >Continuous delivery of PHP applications with Docker Compose, Nginx and MariaDB
Continuous delivery of PHP applications through Docker Compose, Nginx and MariaDB
Overview:
With the rapid development of cloud computing and containerization technology, more and more More and more applications are adopting containerization to achieve rapid delivery and deployment. This article will introduce how to use Docker Compose, Nginx and MariaDB to build a simple PHP application and implement the continuous delivery process. At the same time, we will give specific code examples to help readers better understand this process.
1. Preparation
2. Create a Docker Compose configuration file
Create a file named docker-compose.yml and fill it in according to the following example content.
version: '3' services: web: build: context: . dockerfile: Dockerfile ports: - "80:80" depends_on: - db db: image: mariadb:latest environment: MYSQL_ROOT_PASSWORD: example
3. Create Nginx configuration file
Create a file named nginx.conf and fill it in according to the following example content.
server { listen 80; server_name localhost; root /var/www/html; index index.php index.html; location / { try_files $uri $uri/ /index.php?$args; } location ~ .php$ { fastcgi_pass web:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
4. Create a PHP application file
Create a file named index.php in the project root directory and fill it in according to the following example content.
<?php echo "Hello, World!"; ?>
5. Create Dockerfile
Create a file named Dockerfile in the project root directory and fill in the following example content.
FROM php:7.4-fpm WORKDIR /var/www/html COPY . /var/www/html RUN docker-php-ext-install mysqli pdo pdo_mysql CMD ["php-fpm"] EXPOSE 9000
6. Build and start the container
Execute the following commands in the project root directory to build and start the container.
docker-compose up -d
7. Verify the running results
Access http://localhost in the browser. If you see the words "Hello, World!", it means that the container has run successfully.
8. Continuous delivery process
When we update the application, we need to follow the following steps to achieve continuous delivery.
docker-compose down
Then, we can modify the index.php file, for example, change "Hello, World!" to "Hello, Docker!".
docker-compose up -d --build
Conclusion:
By using Docker Compose, Nginx and MariaDB, we can quickly build a PHP application and implement the continuous delivery process. The advantage of containerization technology is that it can provide consistent development, testing and production environments, greatly simplifying deployment and maintenance. At the same time, using Nginx as a reverse proxy and load balancer can better manage request traffic. Through the above code examples, readers can further understand how to use these tools to implement the continuous delivery process.
The above is the detailed content of Continuous delivery of PHP applications with Docker Compose, Nginx and MariaDB. For more information, please follow other related articles on the PHP Chinese website!