当前位置: 首页 > 软件库 > 数据库相关 > >

docker-nginx-php-mysql

Docker running Nginx, PHP-FPM, MySQL & PHPMyAdmin
授权协议 Readme
开发语言 C/C++
所属分类 数据库相关
软件类型 开源软件
地区 不详
投 递 者 茅慈
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Nginx PHP MySQL

Docker running Nginx, PHP-FPM, Composer, MySQL and PHPMyAdmin.

Overview

  1. Install prerequisites

    Before installing project make sure the following prerequisites have been met.

  2. Clone the project

    We’ll download the code from its repository on GitHub.

  3. Configure Nginx With SSL Certificates [Optional]

    We'll generate and configure SSL certificate for nginx before running server.

  4. Configure Xdebug [Optional]

    We'll configure Xdebug for IDE (PHPStorm or Netbeans).

  5. Run the application

    By this point we’ll have all the project pieces in place.

  6. Use Makefile [Optional]

    When developing, you can use Makefile for doing recurrent operations.

  7. Use Docker Commands

    When running, you can use docker commands for doing recurrent operations.


Install prerequisites

To run the docker commands without using sudo you must add the docker group to your-user:

sudo usermod -aG docker your-user

For now, this project has been mainly created for Unix (Linux/MacOS). Perhaps it could work on Windows.

All requisites should be available for your distribution. The most important are :

Check if docker-compose is already installed by entering the following command :

which docker-compose

Check Docker Compose compatibility :

The following is optional but makes life more enjoyable :

which make

On Ubuntu and Debian these are available in the meta-package build-essential. On other distributions, you may need to install the GNU C++ compiler separately.

sudo apt install build-essential

Images to use

You should be careful when installing third party web servers such as MySQL or Nginx.

This project use the following ports :

Server Port
MySQL 8989
PHPMyAdmin 8080
Nginx 8000
Nginx SSL 3000

Clone the project

To install Git, download it and install following the instructions :

git clone https://github.com/nanoninja/docker-nginx-php-mysql.git

Go to the project directory :

cd docker-nginx-php-mysql

Project tree

.
├── Makefile
├── README.md
├── data
│   └── db
│       ├── dumps
│       └── mysql
├── doc
├── docker-compose.yml
├── etc
│   ├── nginx
│   │   ├── default.conf
│   │   └── default.template.conf
│   ├── php
│   │   └── php.ini
│   └── ssl
└── web
    ├── app
    │   ├── composer.json.dist
    │   ├── phpunit.xml.dist
    │   ├── src
    │   │   └── Foo.php
    │   └── test
    │       ├── FooTest.php
    │       └── bootstrap.php
    └── public
        └── index.php

Configure Nginx With SSL Certificates

You can change the host name by editing the .env file.

If you modify the host name, do not forget to add it to the /etc/hosts file.

  1. Generate SSL certificates

    source .env && docker run --rm -v $(pwd)/etc/ssl:/certificates -e "SERVER=$NGINX_HOST" jacoelho/generate-certificate
  2. Configure Nginx

    Do not modify the etc/nginx/default.conf file, it is overwritten by etc/nginx/default.template.conf

    Edit nginx file etc/nginx/default.template.conf and uncomment the SSL server section :

    # server {
    #     server_name ${NGINX_HOST};
    #
    #     listen 443 ssl;
    #     fastcgi_param HTTPS on;
    #     ...
    # }

Configure Xdebug

If you use another IDE than PHPStorm or Netbeans, go to the remote debugging section of Xdebug documentation.

For a better integration of Docker to PHPStorm, use the documentation.

  1. Get your own local IP address :

    sudo ifconfig
  2. Edit php file etc/php/php.ini and comment or uncomment the configuration as needed.

  3. Set the remote_host parameter with your IP :

    xdebug.remote_host=192.168.0.1 # your IP

Run the application

  1. Copying the composer configuration file :

    cp web/app/composer.json.dist web/app/composer.json
  2. Start the application :

    docker-compose up -d

    Please wait this might take a several minutes...

    docker-compose logs -f # Follow log output
  3. Open your favorite browser :

  4. Stop and clear services

    docker-compose down -v

Use Makefile

When developing, you can use Makefile for doing the following operations :

Name Description
apidoc Generate documentation of API
clean Clean directories for reset
code-sniff Check the API with PHP Code Sniffer (PSR2)
composer-up Update PHP dependencies with composer
docker-start Create and start containers
docker-stop Stop and clear all services
gen-certs Generate SSL certificates for nginx
logs Follow log output
mysql-dump Create backup of all databases
mysql-restore Restore backup of all databases
phpmd Analyse the API with PHP Mess Detector
test Test application with phpunit

Examples

Start the application :

make docker-start

Show help :

make help

Use Docker commands

Installing package with composer

docker run --rm -v $(pwd)/web/app:/app composer require symfony/yaml

Updating PHP dependencies with composer

docker run --rm -v $(pwd)/web/app:/app composer update

Generating PHP API documentation

docker run --rm -v $(pwd):/data phpdoc/phpdoc -i=vendor/ -d /data/web/app/src -t /data/web/app/doc

Testing PHP application with PHPUnit

docker-compose exec -T php ./app/vendor/bin/phpunit --colors=always --configuration ./app

Fixing standard code with PSR2

docker-compose exec -T php ./app/vendor/bin/phpcbf -v --standard=PSR2 ./app/src

Checking the standard code with PSR2

docker-compose exec -T php ./app/vendor/bin/phpcs -v --standard=PSR2 ./app/src

Analyzing source code with PHP Mess Detector

docker-compose exec -T php ./app/vendor/bin/phpmd ./app/src text cleancode,codesize,controversial,design,naming,unusedcode

Checking installed PHP extensions

docker-compose exec php php -m

Handling database

MySQL shell access

docker exec -it mysql bash

and

mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD"

Creating a backup of all databases

mkdir -p data/db/dumps
source .env && docker exec $(docker-compose ps -q mysqldb) mysqldump --all-databases -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" > "data/db/dumps/db.sql"

Restoring a backup of all databases

source .env && docker exec -i $(docker-compose ps -q mysqldb) mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" < "data/db/dumps/db.sql"

Creating a backup of single database

Notice: Replace "YOUR_DB_NAME" by your custom name.

source .env && docker exec $(docker-compose ps -q mysqldb) mysqldump -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" --databases YOUR_DB_NAME > "data/db/dumps/YOUR_DB_NAME_dump.sql"

Restoring a backup of single database

source .env && docker exec -i $(docker-compose ps -q mysqldb) mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" < "data/db/dumps/YOUR_DB_NAME_dump.sql"

Connecting MySQL from PDO

<?php
    try {
        $dsn = 'mysql:host=mysql;dbname=test;charset=utf8;port=3306';
        $pdo = new PDO($dsn, 'dev', 'dev');
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
?>

Help us

Any thought, feedback or (hopefully not!)

  • 一、nginx 1、创建conf/conf.d log www目录分别用于放配置文件,日志文件,代码文件, 2、docker pull nginx 获取nginx镜像 二、php 1、docker pull php:5.6-fpm 获取php镜像 2、运行php容器   docker run --name php-fpm -v /nginx/www:/www -d php:5.6-fpm -v /

  • docker-nginx-php-mysql代码托管 准备工作 先安装好软件: git,      docker,     docker-compose 删除所有容器和镜像 $ docker stop $(docker ps -q) && docker rm $(docker ps -aq) $ docker rmi $(docker images -q) 01:代码克隆 在github上fork

  • docker安装 yum更新 yum -y update 安装依赖项 yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的 yum install -y yum-utils device-mapper-persistent-data lvm2 设置yum源 yum-config-manager --add-repo https://dow

  • 前言 “PHP是世界上最好的语言”,这个大家应该都没有争议把:) 但是当你用php写完一个项目后,你会发现,如果要将项目部署到线上,光是nginx+php-fpm的环境部署就要花费你许多时间。利用docker,可以大大节省我们的环境部署时间。 正文 docker简介 如果你还不了解docker,那么推荐你先通过其官网和docker-从入门到实践来学习和熟悉docker 这里简单介绍下docker

  • 1、创建 mkdir -p /docker/www mkdir -p /docker/nginx/conf.d/ 2、配置 vim nginx/conf.d/default.conf server { listen 80; server_name localhost; location / { root /usr/share/nginx/html;

  • 前置工作 下载后执行 chmod +x /usr/local/bin/docker-compose 1. 创建好目录及文件 1.1 docker-compose.yml文件 version: '3' services: nginx: build: ./nginx ports: - "80:80" links: - "php" volumes: - /var/www/docker-compose/n

  • 默认路径,方便查阅: nginx默认安装以后,容器中默认的工作目录/user/share/nginx/html nginx容器中文件夹/etc/nginx/conf.d下存放的是default.conf(default.conf是nginx.conf的初始值) nginx默认的配置文件位置:/etc/nginx/nginx.conf mysql:5.5 数据位置 show global varia

  • 示例 php lnmp+redis环境搭建使用了php7.3、php7.4 docker-compose.yaml version: '3' services: php74: build: context: ./ dockerfile: DockerPHP74 args: PHP_VERSION: 7.4 containe

 相关资料
  • 运行Nginx 1.17的Digital Ocean Ubuntu18.04 VPS。10 PHP-FPM7.3。我不知道如何正确运行PHP文件(其他一切都正常运行)php文件生成Nginx的404未找到页面。Nginx错误日志仅显示“信号处理已启动”每次更改后,我都会重新启动nginx fpm。我已经研究了几乎所有与此相关的StackOverflow问题,并尝试了各种不同的配置。如果您能提供任何

  • 项目的吉特回购:https://github.com/tombusby/docker-laravel-experiments(撰写本文时的标题为823fd22)。 这是我的码头工人。yml: 我创建了一个新的laravel项目。如果我把index.php换成一个基本的回声“你好世界”;,如果我使用回声“称为”;退出();,我可以识别laravel的index.php确实会被处决。 它死在第53行:

  • 我的错误日志从nginx一直说: [错误]82305#0:*542243 connect()到unix:/var/run/php5 fpm。连接到上游时sock失败(146:连接被拒绝) 大约每30秒。然而,我的php-fpm日志在这个错误中没有显示任何内容。只有nginx显示日志。php-fpm的nginx配置如下: 编辑:刚刚为nginx和php fpm添加了完整配置: php fpm:

  • 我将docker compose与以下: nginx conf是: 它工作得很好,如果我创建。但是,如果我想访问,我有一个403错误,并在docker-comple中使用以下日志: 我试过其他Q中的建议

  • 我正在努力理解我的错误在哪里。我看了各种答案并尝试了补救措施,结果发现他们的解决方案并没有纠正我的问题。我已经将所有内容剥离到最基本的部分,看看是否可以得到一个基本的PHP索引。php来展示自己。 以下是我试图在核心实现的目标: 我有docker compose站在1个网络上,2个服务连接到网络上。一个服务是PHP-FPM,另一个是为PHP-FPM服务的nginx。每次我站起来,不管我如何配置它,

  • 我有一个用Codeigniter制作的网站,在Ubuntu上运行Nginx和PHP-FPM。直到昨天晚上,它工作得还不错,开始加载页面时速度非常慢,有时是504,有时加载页面速度很快。 如果我重新启动nginx或php-fpm,站点会正常工作20-30秒,然后问题再次出现。 以下是nginx错误日志的内容: [错误]25226#25226:*65从上游读取响应头时上游超时(110:连接超时),客户