docker-compose-lamp

docker-compose-lamp

Docker Compose构建的LAMP开发环境

项目采用Docker Compose搭建LAMP开发环境,包含PHP、Apache、MySQL、phpMyAdmin和Redis。支持多个PHP版本,便于本地开发。提供简便的安装过程和可定制的配置选项,允许开发者自定义PHP设置、Apache虚拟主机和数据库版本。集成Xdebug调试和SSL配置,满足开发者需求。

LAMP stackDocker ComposePHPApacheMySQLGithub开源项目

LAMP stack built with Docker Compose

Landing Page

A basic LAMP stack environment built using Docker Compose. It consists of the following:

  • PHP
  • Apache
  • MySQL
  • phpMyAdmin
  • Redis

As of now, we have several different PHP versions. Use appropriate php version as needed:

  • 5.4.x
  • 5.6.x
  • 7.1.x
  • 7.2.x
  • 7.3.x
  • 7.4.x
  • 8.0.x
  • 8.1.x
  • 8.2.x
  • 8.3.x

Installation

  • Clone this repository on your local computer
  • configure .env as needed
  • Run the docker compose up -d.
git clone https://github.com/sprintcube/docker-compose-lamp.git cd docker-compose-lamp/ cp sample.env .env // modify sample.env as needed docker compose up -d // visit localhost

Your LAMP stack is now ready!! You can access it via http://localhost.

Configuration and Usage

General Information

This Docker Stack is build for local development and not for production usage.

Configuration

This package comes with default configuration options. You can modify them by creating .env file in your root directory. To make it easy, just copy the content from sample.env file and update the environment variable values as per your need.

Configuration Variables

There are following configuration variables available and you can customize them by overwritting in your own .env file.


PHP


PHPVERSION Is used to specify which PHP Version you want to use. Defaults always to latest PHP Version.

PHP_INI Define your custom php.ini modification to meet your requirments.


Apache


DOCUMENT_ROOT

It is a document root for Apache server. The default value for this is ./www. All your sites will go here and will be synced automatically.

APACHE_DOCUMENT_ROOT

Apache config file value. The default value for this is /var/www/html.

VHOSTS_DIR

This is for virtual hosts. The default value for this is ./config/vhosts. You can place your virtual hosts conf files here.

Make sure you add an entry to your system's hosts file for each virtual host.

APACHE_LOG_DIR

This will be used to store Apache logs. The default value for this is ./logs/apache2.


Database


For Apple Silicon Users: Please select Mariadb as Database. Oracle doesn't build their SQL Containers for the arm Architecture

DATABASE

Define which MySQL or MariaDB Version you would like to use.

MYSQL_INITDB_DIR

When a container is started for the first time files in this directory with the extensions .sh, .sql, .sql.gz and .sql.xz will be executed in alphabetical order. .sh files without file execute permission are sourced rather than executed. The default value for this is ./config/initdb.

MYSQL_DATA_DIR

This is MySQL data directory. The default value for this is ./data/mysql. All your MySQL data files will be stored here.

MYSQL_LOG_DIR

This will be used to store Apache logs. The default value for this is ./logs/mysql.

Web Server

Apache is configured to run on port 80. So, you can access it via http://localhost.

Apache Modules

By default following modules are enabled.

  • rewrite
  • headers

If you want to enable more modules, just update ./bin/phpX/Dockerfile. You can also generate a PR and we will merge if seems good for general purpose. You have to rebuild the docker image by running docker compose build and restart the docker containers.

Connect via SSH

You can connect to web server using docker compose exec command to perform various operation on it. Use below command to login to container via ssh.

docker compose exec webserver bash

PHP

The installed version of php depends on your .envfile.

Extensions

By default following extensions are installed. May differ for PHP Versions <7.x.x

  • mysqli
  • pdo_sqlite
  • pdo_mysql
  • mbstring
  • zip
  • intl
  • mcrypt
  • curl
  • json
  • iconv
  • xml
  • xmlrpc
  • gd

If you want to install more extension, just update ./bin/webserver/Dockerfile. You can also generate a PR and we will merge if it seems good for general purpose. You have to rebuild the docker image by running docker compose build and restart the docker containers.

phpMyAdmin

phpMyAdmin is configured to run on port 8080. Use following default credentials.

http://localhost:8080/
username: root
password: tiger

Xdebug

Xdebug comes installed by default and it's version depends on the PHP version chosen in the ".env" file.

Xdebug versions:

PHP <= 7.3: Xdebug 2.X.X

PHP >= 7.4: Xdebug 3.X.X

To use Xdebug you need to enable the settings in the ./config/php/php.ini file according to the chosen version PHP.

Example:

# Xdebug 2
#xdebug.remote_enable=1
#xdebug.remote_autostart=1
#xdebug.remote_connect_back=1
#xdebug.remote_host = host.docker.internal
#xdebug.remote_port=9000

# Xdebug 3
#xdebug.mode=debug
#xdebug.start_with_request=yes
#xdebug.client_host=host.docker.internal
#xdebug.client_port=9003
#xdebug.idekey=VSCODE

Xdebug VS Code: you have to install the Xdebug extension "PHP Debug". After installed, go to Debug and create the launch file so that your IDE can listen and work properly.

Example:

VERY IMPORTANT: the pathMappings depends on how you have opened the folder in VS Code. Each folder has your own configurations launch, that you can view in .vscode/launch.json

{ "version": "0.2.0", "configurations": [ { "name": "Listen for Xdebug", "type": "php", "request": "launch", // "port": 9000, // Xdebug 2 "port": 9003, // Xdebug 3 "pathMappings": { // "/var/www/html": "${workspaceFolder}/www" // if you have opened VSCODE in root folder "/var/www/html": "${workspaceFolder}" // if you have opened VSCODE in ./www folder } } ] }

Now, make a breakpoint and run debug.

Tip! After theses configurations, you may need to restart container.

Redis

It comes with Redis. It runs on default port 6379.

SSL (HTTPS)

Support for https domains is built-in but disabled by default. There are 3 ways you can enable and configure SSL; https on localhost being the easiest. If you are trying to recreating a testing environment as close as possible to a production environment, any domain name can be supported with more configuration.

Notice: For every non-localhost domain name you wish to use https on, you will need to modify your computers hosts file and point the domain name to 127.0.0.1. If you fail to do this SSL will not work and you will be routed to the internet every time you try to visit that domain name locally.

1) HTTPS on Localhost

To enable https on localhost (https://localhost) you will need to:

  1. Use a tool like mkcert to create an SSL certificate for localhost:
    • With mkcert, in the terminal run mkcert localhost 127.0.0.1 ::1.
    • Rename the files that were generated cert.pem and cert-key.pem respectively.
    • Move these files into your docker setup by placing them in config/ssl directory.
  2. Uncomment the 443 vhost in config/vhosts/default.conf.

Done. Now any time you turn on your LAMP container https will work on localhost.

2) HTTPS on many Domains with a Single Certificate

If you would like to use normal domain names for local testing, and need https support, the simplest solution is an SSL certificate that covers all the domain names:

  1. Use a tool like mkcert to create an SSL certificate that covers all the domain names you want:
    • With mkcert, in the terminal run mkcert example.com "*.example.org" myapp.dev localhost 127.0.0.1 ::1 where you replace all the domain names and IP addresses to the ones you wish to support.
    • Rename the files that were generated cert.pem and cert-key.pem respectively.
    • Move these files into your docker setup by placing them in config/ssl directory.
  2. Uncomment the 443 vhost in config/vhosts/default.conf.

Done. Since you combined all the domain names into a single certificate, the vhost file will support your setup without needing to modify it further. You could add domain specific rules if you wish however. Now any time you turn on your LAMP container https will work on all the domains you specified.

3) HTTPS on many Domain with Multiple Certificates

If you would like your local testing environment to exactly match your production, and need https support, you could create an SSL certificate for every domain you wish to support:

  1. Use a tool like mkcert to create an SSL certificate that covers the domain name you want:
    • With mkcert, in the terminal run mkcert [your-domain-name(s)-here] replacing the bracket part with your domain name.
    • Rename the files that were generated to something unique like [name]-cert.pem and [name]-cert-key.pem replacing the bracket part with a unique name.
    • Move these files into your docker setup by placing them in config/ssl directory.
  2. Using the 443 example from the vhost file (config/vhosts/default.conf), make new rules that match your domain name and certificate file names.

Done. The LAMP container will auto pull in any SSL certificates in config/ssl when it starts. As long as you configure the vhosts file correctly and place the SSL certificates in config/ssl, any time you turn on your LAMP container https will work on your specified domains.

Contributing

We are happy if you want to create a pull request or help people with their issues. If you want to create a PR, please remember that this stack is not built for production usage, and changes should be good for general purpose and not overspecialized.

Please note that we simplified the project structure from several branches for each php version, to one centralized master branch. Please create your PR against master branch.

Thank you!

Why you shouldn't use this stack unmodified in production

We want to empower developers to quickly create creative Applications. Therefore we are providing an easy to set up a local development environment for several different Frameworks and PHP Versions. In Production you should modify at a minimum the following subjects:

  • php handler: mod_php=> php-fpm
  • secure mysql users with proper source IP limitations

编辑推荐精选

问小白

问小白

全能AI智能助手,随时解答生活与工作的多样问题

问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。

热门AI助手AI对话AI工具聊天机器人
Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

Trae

Trae

字节跳动发布的AI编程神器IDE

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

openai-agents-python

openai-agents-python

OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。

openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。

下拉加载更多