项目作者: chung1905

项目描述 :
LAMP Docker (with some small tools that help development)
高级语言: Dockerfile
项目地址: git://github.com/chung1905/docker_lamp.git
创建时间: 2018-11-02T06:17:51Z
项目社区:https://github.com/chung1905/docker_lamp

开源协议:MIT License

下载


LAMP Stack in Docker

multiple PHP (5.6/7.x/8.x) + Apache2 + MariaDB/Mysql + … in Docker

This docker setup has been tested with Magento 2, WordPress and Symfony 2 -> Symfony 4

How to set up:

  1. Install docker and docker compose properly
  2. Clone project and cd into the that
  3. Create configurations files (for the first time):
  • .env: define docker env variable
  • dclamp.env: define PHP versions and services
  • docker-compose.yml: Docker compose file
    1. ./dclamp
  • Next time, you have to run ./dclamp config and ./dclamp generate separately.
  1. Generate wildcard self-signed certificates for *.*.localhost (optional)
    1. openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
    2. -keyout ./httpd/certs/x.x.localhost.key \
    3. -out ./httpd/certs/x.x.localhost.crt \
    4. -subj "/C=XX/ST=State/L=City/O=Company/OU=CompanySectionName/CN=*.*.localhost"
  2. Create and run container:
    1. docker compose up -d

PHP web application:

  • Write your code at public_html directory
  • Browse to URL: localhost/info.php to check if it’s running properly
  • Your MariaDB database credentials: root:1@localhost:3306 or root:1@mariadb:3306

Default VirtualHost

  • Default PHP version(s): latest PHP 8.x
  • Assume your index.php is located at ./public_html/project-dir/public-dir/index.php,
    please browse to:
    • http://public-dir.project-dir73.localhost to run your application with PHP 7.3,
    • http://public-dir.project-dir74.localhost (PHP 7.4)
  • You don’t have to add entry to /etc/hosts/ because by default, all .localhost sites will be redirected to 127.0.0.1:
    • If it’s not the case, you can use dnsmasq instead of /etc/hosts, example:
      1. # Redirect all localhost sites to 127.0.0.1
      2. address=/localhost/127.0.0.1

Custom VirtualHost

  • Add your VirtualHost config files to ./httpd/conf/vhosts/
  • Restart Apache container: docker restart httpd

Use PHP CLI:

  • Run command
    1. docker compose exec php73 /bin/bash
    or
    1. docker compose exec php{xx} /bin/bash
  • Run you PHP application with command php ...
  • To debug PHP CLI application: replace php by xdebug
    • Example: php bin/console to xdebug bin/console

Enable/Disable PHP xdebug:

  • After docker compose exec... into container, run
    1. toggle-php-mod xdebug
    or shortcut
    1. toggle-php-mod xd

Enable/Disable PHP Opcache:

  • After docker compose exec... into container, run
    1. toggle-php-mod opcache
    or shortcut
    1. toggle-php-mod op