Based on docker, build Nginx+Php+https local development environment quickly, avoid manual installation of PHP extension

Time:2019-8-13

What is NginxPhp Docker and what are the main problems to be solved

Based on docker, the Nginx+Php local development environment (including common PHP extensions), nginx, PHP configuration files, log files and PHP engineering codes are all on the host for easy modification.

It can solve the following problems:

  • New people join the team, configure LNMP troublesome and duplicate work
  • Prod, staging, local development environment is inconsistent, local no problem, on staging, prod has a variety of problems
  • There are problems with the installation of PHP extensions, such as: MAC computers, multiple local PHP versions, inconsistent extensions (eg: memcache, memcached)
  • New features of the project need to be installed with new extensions, and all developers need to install them once.

NginxPhpDocker github url

1. How to use it?

1.1 download code

git clone [email protected]:weiwenwang/NginxPhpDocker.git
cd NginxPhpDocker

1.2 Start the PHP container

docker run -it -d \
--name myphp \
-v $PWD/www/php:/www/php \
-v $PWD/www/example:/www/example \
--privileged=true \
wangnan188/nginx-php-docker:v7.2-v1

1.3 Start the nginx container

docker run -it -d \
-p 80:80 \
-p 443:443 \
-v $PWD/nginx-conf/conf.d:/etc/nginx/conf.d \
-v $PWD/nginx-conf/nginx.conf:/etc/nginx/nginx.conf \
-v $PWD/www/html:/www/html \
-v $PWD/www/example:/www/example \
-v $PWD/ssl/server.crt:/etc/nginx/ssl/server.crt \
-v $PWD/ssl/server.key:/etc/nginx/ssl/server.key \
-v $PWD/log/nginx:/var/log/nginx/ \
--link=myphp:myphp_alias \
--privileged=true \
--name=mynginx nginx

1.4 Notes, very important

  • The two instructions of 1.2 and 1.3 must be executed in the NginxPhpDocker directory
  • The folder of PHP code must be hung in the PHP container. When a small partner is using it, it must be hung in the nginx container. The nginx and PHP containers are isolated. PHP will only find files in their own container by address, and communicate with nginx only through fastcgi. nginx tells the PHP user the requested file address. PHP is in its own capacity Apparatus to find the corresponding file

What is the effect of 1.5 after 1.2 and 1.3?

Based on docker, build Nginx+Php+https local development environment quickly, avoid manual installation of PHP extension
Based on docker, build Nginx+Php+https local development environment quickly, avoid manual installation of PHP extension
Based on docker, build Nginx+Php+https local development environment quickly, avoid manual installation of PHP extension

3. How to run the existing projects?

Let me give you an example. If our current project (thinkphp_3.2.3_full) is written by the ThinkPHP framework, how can I run it?
Step 1: Put the code in www/example/directory
Step 2: Add the configuration file nginx-conf/conf.d/example-thinkphp.conf, and all that remains is a simple nginx configuration problem.
Make a host binding locally: “127.0.0.1 thinkphp-full.com”
Browser access: http://thinkphp-full.com/inde…

Based on docker, build Nginx+Php+https local development environment quickly, avoid manual installation of PHP extension

4. What extensions does Wangnan 188/nginx-php-docker now contain?

extension status remark extension status remark
Core YES redis YES
ctype YES gd YES
curl YES xdebug YES
date YES mongodb YES
dom YES swoole YES
fileinfo YES memcached YES
filter YES memcache NO
ftp YES
hash YES
iconv YES
json YES
libxml YES
mbstring YES
mysqlnd YES
openssl YES
pcre YES
PDO YES
pdo_sqlite YES
Phar YES
posix YES
readline YES
Reflection YES
session YES
SimpleXML YES
sodium YES
SPL YES
sqlite3 YES
standard YES
tokenizer YES
xml YES
xmlreader YES
xmlwriter YES
zlib YES

5. Other

Subsequent PHP extensions are supplementary and may not update this article in time. Please move to the latest version: GitHub

Recommended Today

Implementation of PHP Facades

Example <?php class RealRoute{ public function get(){ Echo’Get me’; } } class Facade{ public static $resolvedInstance; public static $app; public static function __callStatic($method,$args){ $instance = static::getFacadeRoot(); if(!$instance){ throw new RuntimeException(‘A facade root has not been set.’); } return $instance->$method(…$args); } // Get the Facade root object public static function getFacadeRoot() { return static::resolveFacadeInstance(static::getFacadeAccessor()); } protected […]