Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How docker installs the php project

2025-03-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to install docker php project, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Docker install php project method: 1, download the required image file; 2, in the nginx/conf directory to prepare the nginx configuration file php.conf;3, create docker-compose.yml orchestration file; 4, install the extension.

This article operating environment: macOS10.15 system, PHP5.6 version, macbook pro 2020 computer.

Using Docker to quickly build PHP Development Environment

Recently, a colleague came over and asked me to add some features to a PHP website I wrote a long time ago, when I developed a local development environment built using xampp, but now my laptop has been updated and there is no development environment at that time. In line with the principle of not installing useless software on computers as far as possible, I think whether we can use Docker to build a local development environment, so this paper introduces how to quickly build a local PHP development environment based on Docker for students in need for reference.

Catalogue

Preparation in advance

Orchestration file

Running effect

Install extension

references

This paper builds the PHP development environment under Mac based on 5.6-fpm-alpine3.8 and ngingx.

Preparation in advance

First download the required image file

$docker pull php:5.6-fpm-alpine3.8$ docker pull nginx$ docker pull mysql

Users need to go to hub.docker.com, search PHP and find the version they want to install through tags. My project is version 5.6 because it has been developed for a long time and can not support the latest PHP.

We need to prepare a working directory, such as lnmp, and prepare the website root directory, Nginx configuration file directory, and Nginx log directory under the working directory.

$mkdir lnmp$ cd lnmp$ mkdir-p nginx/www nginx/logs nginx/conf

Create a new index.php file in the newly created www directory to check whether the php environment has been built successfully.

Prepare the configuration file php.conf for nginx in the nginx/conf directory.

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.htl; location = / 50x.html {root / usr/share/nginx/html } location ~\ .php$ {fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME / www/$fastcgi_script_name; include fastcgi_params;}} orchestration file

Create a docker-compose.yml orchestration file in the working directory.

For a detailed introduction to docker-compose, please refer to my previous article, introduction to docker-compose.

Version: "2.1" services: nginx: image: nginx ports: -" 80:80 "volumes:-~ / Projects/sh-valley/docker-conf/lnmp/nginx/www:/usr/share/nginx/html-~ / Projects/sh-valley/docker-conf/lnmp/nginx/conf:/etc/nginx/conf.d-~ / Projects/sh-valley/docker-conf/lnmp/nginx/logs:/var/log/nginx networks:-lnmp-network php: image: php:5.6-fpm-alpine3.8 volumes:-~ / Projects/sh-valley/docker-conf/lnmp/nginx/www:/www networks:-lnmp-network mysql: image: mysql ports: -"3306 environment:-MYSQL_ROOT_PASSWORD=123456 networks:-lnmp-networknetworks: lnmp-network:"

At this point, we have completed all the preparatory work, and we can start to view the results immediately.

Run effect $docker-compose up-dCreating network "lnmp_php-network" with the default driverCreating lnmp_nginx_1. DoneCreating lnmp_php_1... Done

You will soon see the familiar phpinfo interface.

Install extension

The default php image provides fewer extensions and lacks common extensions such as mysql, gd2, and so on, so we need to install and enable the extensions ourselves.

First go to the php container and use the php-m command to see what extensions are available locally.

You can use the docker-php-ext-install command to install the extension.

$docker-php-ext-install mysql

Once the extension is installed, it can be enabled in php.ini. We can see from phpinfo that the default php.ini in the container environment is not enabled, so you can copy php.ini-development to php.ini from / usr/local/etc/php. Enable the extensions you need by modifying the configuration in php.ini. The following are several extension installation commands for your reference.

Docker-php-ext-source creates a / usr/src/php directory in the container

Docker-php-ext-enable enables the PHP extension to save us the process of manually editing php.ini

Docker-php-ext-install installs and enables PHP extensions

Docker-php-ext-configure is often paired with docker-php-ext-install and is used when a custom extended configuration is required

The above is all the contents of the article "how to install the php Project in docker". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report