This time I will bring you a detailed explanation of the containerization and deployment of PHP applications. What are theprecautions for containerization and deployment of PHP applications? The following is a practical case, let's take a look.
PHP is the best language in the world.
The classic LNMP (linux nginx php mysql) environment has many ready-made deployment scripts, but today when Docker is popular, many students still have some problems on how to deploy, so this article is simple Introduce how to use Docker and docker-compose to deploy php applications on the server. First of all, let’s review the past php configuration in nginx:location ~ \.php$ { try_files $uri =404; include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
server { listen 80; charset utf-8; # access_log /var/log/nginx/nginx.access.log main; # error_log /var/log/nginx/error.log; root /var/www/html; index index.php index.html; add_header X-Cache $upstream_cache_status; location ~ \.php$ { try_files $uri =404; include fastcgi_params; fastcgi_pass php-fpm:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
version: '2' services: nginx: image: nginx:stable-alpine ports: - 80:80 volumes: - ./conf/nginx/conf.d:/etc/nginx/conf.d volumes_from: - php-fpm restart: always php-fpm: image: php:7.1-fpm-alpine volumes: - ./code:/var/www/html restart: always
nginx conf uses service_name to access php-fpm
nginx shares php-fpm's /var/www/html through the volumes_from directive
Write this in index.php in the code directory:
Copy after login
# bash docker-compose up
FROM php:7.1-fpm-alpine RUN docker-php-install pdo pdo-mysql COPY src /var/www/html
version: '2' services: nginx: image: nginx:stable-alpine ports: - 8000:80 volumes: - ./conf/nginx/conf.d:/etc/nginx/conf.d volumes_from: - php-fpm restart: always php-fpm: image: {YOUR_PHP_IMAGE_NAME}:{TAG} restart: always
Detailed explanation of the use of php namespace
The above is the detailed content of Detailed explanation of containerization and deployment of PHP applications. For more information, please follow other related articles on the PHP Chinese website!