This article is provided by the tutorial column of composer to introduce how to use docker-composer to build a simple nginx php environment. I hope it will be helpful to friends in need!
Directory structure
➜ Study tree ├── conf ├── docker-compose.yaml ├── nginx │ ├── conf │ │ └── laravel.conf │ └── html │ └── index.php
index.php
<?php /** * Created by OrangBus * User email: orangbus40400@gmail.com * website: orangbus.cn * blog: doc.orangbus.cn * github: github.com/orangbus */echo phpinfo();
nginx.conf
server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm index.php; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_pass php8:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /html$fastcgi_script_name; include fastcgi_params; }}
Important note
fastcgi_pass php8:9000;
php8: The name of the php container. If you want to configure multiple php versions, you only need to copy the php configuration and fill in the corresponding php Container name
php8: # php的容器名称 image: php:8.0-fpm restart: always volumes: - ./nginx/html:/html-------------------------------- php74: # 对应的nginx配置文件为:fastcgi_pass php74:9000; image: php:8.0-fpm restart: always volumes: - ./nginx/html:/html
fastcgi_param SCRIPT_FILENAME /html$fastcgi_script_name;
/html: PHP project is mapped to [php container directory] (red)
docker-compose
version: '3.5'services: nginx: image: nginx:latest restart: always ports: - 8010:80 volumes: - ./nginx/html/:/usr/share/nginx/html # 注意点一 - ./nginx/conf/:/etc/nginx/conf.d/ links: - php8 php8: image: php:8.0-fpm restart: always volumes: - ./nginx/html:/html #注意点二
Note 1:
./nginx/html: Your php project address on this machine
/usr/share/nginx/html: nginx default access address
Note two:
./nginx/html: Your php project address on this machine
/html: The address here is to map your local php code to the php container. It is usually the same as the address configured by your nginx (red)
Tip: Please pay attention to two things The association of the red area, such a simple nginx php association environment has been configured successfully.
Pitfall guide:
When using -link
, the custom port connecting to the container will be invalid, for example
version: '3.5'services: php8: image: php:8.0-fpm restart: always volumes: - ./nginx/html:/html links: # 如果使用 links ,当我们php程序中填写mysql端口的时候应该是 3306 而不是 3307,但是我们外部是需要用3307端口去连接mysql的 - mysql mysql: image: mysql:latest ports: - 3307:3306
The above is the detailed content of docker-composer quickly builds nginx+php environment. For more information, please follow other related articles on the PHP Chinese website!

The combination of AI and Composer can improve PHP development efficiency and security. Specifically reflected in: 1. Dependency analysis and optimization: AI can predict dependencies and reduce conflicts. 2. Automated security checks: AI can identify security vulnerabilities, and it is recommended to update them. 3. Code generation and optimization: AI can automatically generate and optimize related code.

VprocesserazrabotkiveB-enclosed, Мнепришлостольностьсясзадачейтерациигооглапидляпапакробоглесхетсigootrive. LEAVALLYSUMBALLANCEFRIABLANCEFAUMDOPTOMATIFICATION, ČtookazaLovnetakProsto, Kakaožidal.Posenesko

I'm having a tricky problem when developing a Symfony-based application: how to effectively validate JSON data format. Initially, I tried using manual verification code, but this was not only complicated, but also error-prone. After some exploration, I discovered a Composer package called ptyhard/json-schema-bundle, which brought great convenience and efficiency to my project.

When developing an e-commerce website, I encountered a difficult problem: how to provide users with personalized product recommendations. Initially, I tried some simple recommendation algorithms, but the results were not ideal, and user satisfaction was also affected. In order to improve the accuracy and efficiency of the recommendation system, I decided to adopt a more professional solution. Finally, I installed andres-montanez/recommendations-bundle through Composer, which not only solved my problem, but also greatly improved the performance of the recommendation system. You can learn composer through the following address:

When developing an e-commerce platform, it is crucial to choose the right framework and tools. Recently, when I was trying to build a feature-rich e-commerce website, I encountered a difficult problem: how to quickly build a scalable and fully functional e-commerce platform. I tried multiple solutions and ended up choosing Fecmall's advanced project template (fecmall/fbbcbase-app-advanced). By using Composer, this process becomes very simple and efficient. Composer can be learned through the following address: Learning address

I had a tough problem when working on a project with a large number of Doctrine entities: Every time the entity is serialized and deserialized, the performance becomes very inefficient, resulting in a significant increase in system response time. I've tried multiple optimization methods, but it doesn't work well. Fortunately, by using sidus/doctrine-serializer-bundle, I successfully solved this problem, significantly improving the performance of the project.

When developing Laravel projects, the management of error logs is a very critical link. Recently, I encountered a problem in my project: how to efficiently capture and record all types of errors and ensure that these error messages can be processed in a timely manner. After some research, I found the lukeboy25/errorlogger package. It is installed through Composer and can greatly simplify the management process of error logs. You can learn composer through the following address:

When developing a Laravel application, I encountered a common but difficult problem: how to improve the security of user accounts. With the increasing complexity of cyber attacks, a single password protection is no longer enough to ensure the security of users' data. I tried several methods, but the results were not satisfactory. Finally, I installed the wiebenieuwenhuis/laravel-2fa library through Composer and successfully added two-factor authentication (2FA) to my application, greatly improving security.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.