Skip to content

Commit 3436025

Browse files
author
marco
committed
Initial commit
0 parents  commit 3436025

File tree

13 files changed

+424
-0
lines changed

13 files changed

+424
-0
lines changed

Dockerfile

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Base image: Ubuntu 24.04
2+
FROM ubuntu:24.04
3+
LABEL maintainer="Marco Costa <marcocosta@gmx.com>"
4+
ENV REFRESHED_AT 2025-03-28
5+
6+
# Arguments to define PHP and phpMyAdmin versions (defaults: PHP 7.4, phpMyAdmin 5.1.1)
7+
ARG PHP_VERSION=7.4
8+
ARG PHPMYADMIN_VERSION=5.1.1
9+
10+
# Environment variables
11+
ENV DEBIAN_FRONTEND=noninteractive \
12+
PHP_VERSION=${PHP_VERSION} \
13+
PHPMYADMIN_VERSION=${PHPMYADMIN_VERSION} \
14+
APACHE_RUN_USER=www-data \
15+
APACHE_RUN_GROUP=www-data \
16+
APACHE_LOG_DIR=/var/log/apache2 \
17+
APACHE_PID_FILE=/var/run/apache2.pid \
18+
APACHE_RUN_DIR=/var/run/apache2 \
19+
APACHE_LOCK_DIR=/var/lock/apache2 \
20+
MYSQL_USER=root \
21+
MYSQL_PASSWORD=root \
22+
PYTHONUNBUFFERED=1
23+
24+
# Update repositories and install basic tools + Supervisor
25+
RUN apt-get update && \
26+
apt-get install -y software-properties-common curl wget git nano pwgen unzip supervisor
27+
28+
# Add Ondrej's PHP repository for Ubuntu 24.04
29+
RUN LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php && \
30+
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C && \
31+
apt-get update
32+
33+
# Install core packages (Apache, PHP core, MariaDB, Redis, Python)
34+
RUN apt-get install -y \
35+
apache2 \
36+
php${PHP_VERSION} \
37+
libapache2-mod-php${PHP_VERSION} \
38+
mariadb-server mariadb-client \
39+
redis-server \
40+
python3 python3-pip python3-venv
41+
42+
# Install essential PHP extensions (required for Laravel/WordPress)
43+
RUN apt-get install -y \
44+
php${PHP_VERSION}-mysql \
45+
php${PHP_VERSION}-mbstring \
46+
php${PHP_VERSION}-gd \
47+
php${PHP_VERSION}-xml \
48+
php${PHP_VERSION}-curl \
49+
php${PHP_VERSION}-zip
50+
51+
# Install optional PHP extensions (ignore failures)
52+
RUN for ext in apcu bcmath intl soap sqlite3 cli opcache xdebug redis imagick; do \
53+
apt-get install -y php${PHP_VERSION}-${ext} || echo "Extension php${PHP_VERSION}-${ext} not available, skipping."; \
54+
done
55+
56+
# Install Composer
57+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
58+
59+
# Install Node.js 18.x
60+
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
61+
apt-get install -y nodejs
62+
63+
# Configure Apache with DocumentRoot at /var/www/html
64+
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf && \
65+
a2enmod rewrite && \
66+
mkdir -p /app && \
67+
echo "<?php echo 'Server running! PHP ' . phpversion(); ?>" > /app/index.php && \
68+
rm -fr /var/www/html && \
69+
ln -s /app /var/www/html && \
70+
chown -R www-data:www-data /app
71+
72+
# Create runtime directory for MariaDB socket
73+
RUN mkdir -p /run/mysqld && \
74+
chown mysql:mysql /run/mysqld && \
75+
chmod 755 /run/mysqld
76+
77+
# Copy configuration files
78+
COPY config/apache/000-default.conf /etc/apache2/sites-available/000-default.conf
79+
COPY config/php/apache2-php.ini /etc/php/${PHP_VERSION}/apache2/php.ini
80+
COPY config/php/cli-php.ini /etc/php/${PHP_VERSION}/cli/php.ini
81+
COPY config/mariadb/my.cnf /etc/mysql/my.cnf
82+
COPY config/redis/redis.conf /etc/redis/redis.conf
83+
COPY config/supervisor/supervisord.conf /etc/supervisor/supervisord.conf
84+
COPY config/supervisor/apache2.conf /etc/supervisor/conf.d/apache2.conf
85+
COPY config/supervisor/mariadb.conf /etc/supervisor/conf.d/mariadb.conf
86+
COPY config/supervisor/redis.conf /etc/supervisor/conf.d/redis.conf
87+
COPY config/start.sh /start.sh
88+
89+
# Install phpMyAdmin with fallback to version 5.2.1 if the specified version fails
90+
RUN echo "Attempting to download phpMyAdmin ${PHPMYADMIN_VERSION}..." && \
91+
wget -O /tmp/phpmyadmin.tar.gz https://files.phpmyadmin.net/phpMyAdmin/${PHPMYADMIN_VERSION}/phpMyAdmin-${PHPMYADMIN_VERSION}-all-languages.tar.gz || \
92+
(echo "Failed to download phpMyAdmin ${PHPMYADMIN_VERSION}, falling back to 5.2.1..." && \
93+
wget -O /tmp/phpmyadmin.tar.gz https://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-all-languages.tar.gz) && \
94+
tar xfvz /tmp/phpmyadmin.tar.gz -C /var/www && \
95+
ln -s /var/www/phpMyAdmin-*-all-languages /var/www/phpmyadmin && \
96+
mv /var/www/phpmyadmin/config.sample.inc.php /var/www/phpmyadmin/config.inc.php && \
97+
sed -i "s/\$cfg\['Servers'\]\[\$i\]\['password'\] = '';/\$cfg['Servers'][\$i]['password'] = 'root';/" /var/www/phpmyadmin/config.inc.php && \
98+
chown -R www-data:www-data /var/www/phpmyadmin
99+
100+
# Set permissions for startup script
101+
RUN chmod +x /start.sh
102+
103+
# Clean up unnecessary packages
104+
RUN apt-get -y autoremove && \
105+
apt-get -y clean
106+
107+
# Volumes for persistence
108+
VOLUME ["/var/lib/mysql", "/app", "/var/log"]
109+
110+
# Exposed ports (80: Apache, 3306: MariaDB, 6379: Redis)
111+
EXPOSE 80 3306 6379
112+
113+
# Use start.sh as the entrypoint
114+
CMD ["/start.sh"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Marco Costa <marcocosta@gmx.com>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Docker LAMP Stack
2+
3+
A flexible and robust LAMP (Linux, Apache, MySQL/MariaDB, PHP) stack Docker image with additional tools like Redis, Python, Node.js, and Composer. This project supports configurable PHP and phpMyAdmin versions, managed by Supervisor for process reliability.
4+
5+
## Features
6+
- **Base:** Ubuntu 24.04
7+
- **Web Server:** Apache 2
8+
- **Database:** MariaDB
9+
- **PHP:** Configurable version (default: 7.4) with essential and optional extensions
10+
- **phpMyAdmin:** Configurable version (default: 5.1.1) with fallback to 5.2.1
11+
- **Extras:** Redis, Python 3, Node.js 18.x, Composer
12+
- **Process Management:** Supervisor
13+
- **Persistence:** Volumes for MySQL, application data, and logs
14+
- **Ports:** 80 (Apache), 3306 (MariaDB), 6379 (Redis), with optional additional ports
15+
16+
## Requirements
17+
- Docker installed on your system
18+
19+
## Usage
20+
21+
# Docker LAMP Stack
22+
23+
A flexible and robust LAMP (Linux, Apache, MySQL/MariaDB, PHP) stack Docker image with additional tools like Redis, Python, Node.js, and Composer. This project supports configurable PHP and phpMyAdmin versions, managed by Supervisor for process reliability.
24+
25+
## Features
26+
- **Base:** Ubuntu 24.04
27+
- **Web Server:** Apache 2
28+
- **Database:** MariaDB
29+
- **PHP:** Configurable version (default: 7.4) with essential and optional extensions
30+
- **phpMyAdmin:** Configurable version (default: 5.1.1) with fallback to 5.2.1
31+
- **Extras:** Redis, Python 3, Node.js 18.x, Composer
32+
- **Process Management:** Supervisor
33+
- **Persistence:** Volumes for MySQL, application data, and logs
34+
- **Ports:** 80 (Apache), 3306 (MariaDB), 6379 (Redis), with optional additional ports
35+
36+
## Requirements
37+
- Docker installed on your system
38+
39+
## Usage
40+
41+
### Build the Image
42+
1. Clone or download this repository:
43+
```bash
44+
git clone https://github.com/syspanel/docker-lamp-stack.git
45+
cd docker-lamp-stack
46+
47+
Build the Docker image with specific PHP and phpMyAdmin versions:
48+
PHP 7.4 with phpMyAdmin 5.1.1 (default):
49+
bash
50+
51+
docker build -t docker-lamp-stack .
52+
53+
PHP 7.4 with phpMyAdmin 5.1.1:
54+
bash
55+
docker build -t docker-lamp-stack-74 --build-arg PHP_VERSION=7.4 --build-arg PHPMYADMIN_VERSION=5.1.1 .
56+
PHP 8.0 with phpMyAdmin 5.2.1:
57+
bash
58+
docker build -t docker-lamp-stack-80 --build-arg PHP_VERSION=8.0 --build-arg PHPMYADMIN_VERSION=5.2.1 .
59+
PHP 8.1 with phpMyAdmin 5.2.1:
60+
bash
61+
docker build -t docker-lamp-stack-81 --build-arg PHP_VERSION=8.1 --build-arg PHPMYADMIN_VERSION=5.2.1 .
62+
PHP 8.2 with phpMyAdmin 5.2.1:
63+
bash
64+
docker build -t docker-lamp-stack-82 --build-arg PHP_VERSION=8.2 --build-arg PHPMYADMIN_VERSION=5.2.1 .
65+
PHP 8.3 with phpMyAdmin 5.2.1:
66+
bash
67+
docker build -t docker-lamp-stack-83 --build-arg PHP_VERSION=8.3 --build-arg PHPMYADMIN_VERSION=5.2.1 .
68+
Note: If the specified PHPMYADMIN_VERSION is unavailable, it falls back to 5.2.1.
69+
70+
Run the Container
71+
72+
Run the container with persistent volumes for the application, MySQL data, and logs. Below is an example with additional ports and log mapping:
73+
bash
74+
75+
docker run --name "docker-lamp-stack" \
76+
-p "8080:80" -p "8082:3306" -p "8083:6379" \
77+
-v ${PWD}/app:/app -v ${PWD}/mysql:/var/lib/mysql \
78+
-v ${PWD}/logs:/var/log \
79+
docker-lamp-stack-74
80+
81+
Basic Example (without additional ports or logs):
82+
bash
83+
84+
docker run --name "docker-lamp-stack" \
85+
-p "8080:80" -p "8082:3306" -p "8083:6379" \
86+
-v ${PWD}/app:/app -v ${PWD}/mysql:/var/lib/mysql \
87+
docker-lamp-stack
88+
89+
Access
90+
91+
Web Server: http://localhost:16080 (or 8080 for basic example; displays "Server running! PHP x.x.x")
92+
phpMyAdmin: http://localhost:16080/phpmyadmin (or 8080; user: root, password: root)
93+
MariaDB: Port 16082 (or 8082), user: root, password: root
94+
Redis: Port 16083 (or 8083)
95+
Additional Ports: 16081 (443), 16084 (8000), 16085 (9000), 16086 (10000) are mappable but require additional configuration for use (e.g., SSL for 443).
96+
97+
Logs
98+
99+
Logs are available in the /var/log directory inside the container. With the -v ${PWD}/logs:/var/log volume, they are persisted to the logs directory on the host:
100+
101+
Apache: ${PWD}/logs/apache2/supervisor.log
102+
MariaDB: ${PWD}/logs/mariadb/supervisor.log, ${PWD}/logs/mariadb/error.log
103+
Redis: ${PWD}/logs/redis/supervisor.log
104+
Supervisor: ${PWD}/logs/supervisor/supervisord.log
105+
106+
Configuration
107+
108+
Configuration files are located in the config/ directory:
109+
110+
Apache: config/apache/000-default.conf
111+
PHP: config/php/apache2-php.ini and config/php/cli-php.ini
112+
MariaDB: config/mariadb/custom.cnf
113+
Redis: config/redis/redis.conf
114+
Supervisor: config/supervisor/ (main config and service-specific files)
115+
Startup Script: config/start.sh (initializes MariaDB and creates log directories)
116+
117+
Supported PHP Versions
118+
119+
Any version available in the ppa:ondrej/php repository (e.g., 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3). Optional extensions are installed if available; missing ones are skipped without failing the build.
120+
phpMyAdmin Fallback
121+
122+
If the specified PHPMYADMIN_VERSION is not found, the build automatically falls back to version 5.2.1, ensuring compatibility with modern PHP versions.
123+
Repository
124+
125+
This project is hosted on GitHub: syspanel/docker-lamp-stack
126+
License
127+
128+
This project is licensed under the MIT License. See the file for details.
129+
Author
130+
131+
Marco Costa marcocosta@gmx.com
132+
Support the Project
133+
134+
### Support the Project
135+
If you find this project useful, consider supporting its development with a donation via PayPal:
136+
137+
[![Donate via PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/donate/?business=marcocosta@gmx.com&currency_code=USD)
138+
139+

config/apache/000-default.conf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Default Apache VirtualHost configuration
2+
<VirtualHost *:80>
3+
ServerAdmin webmaster@localhost
4+
DocumentRoot /var/www/html
5+
<Directory /var/www/html>
6+
Options Indexes FollowSymLinks
7+
AllowOverride All
8+
Require all granted
9+
</Directory>
10+
Alias /phpmyadmin /var/www/phpmyadmin
11+
<Directory /var/www/phpmyadmin>
12+
Options Indexes FollowSymLinks
13+
AllowOverride All
14+
Require all granted
15+
</Directory>
16+
# ErrorLog ${APACHE_LOG_DIR}/error.log
17+
# CustomLog ${APACHE_LOG_DIR}/access.log combined
18+
</VirtualHost>

config/mariadb/my.cnf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
# Run program with --help to get a list of available options and with
3+
# --print-defaults to see which it would actually understand and use.
4+
#
5+
# If you are new to MariaDB, check out https://mariadb.com/kb/en/basic-mariadb-articles/
6+
7+
#
8+
# This group is read both by the client and the server
9+
# use it for options that affect everything
10+
#
11+
[client-server]
12+
# Port or socket location where to connect
13+
# port = 3306
14+
socket = /run/mysqld/mysqld.sock
15+
16+
# Import all .cnf files from configuration directory
17+
!includedir /etc/mysql/conf.d/
18+
!includedir /etc/mysql/mariadb.conf.d/
19+
20+
21+
[mysqld]
22+
sql_mode=NO_ENGINE_SUBSTITUTION
23+
24+
sql_mode = ""
25+
sql-mode = ""

config/php/apache2-php.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
; PHP configuration for Apache
2+
upload_max_filesize = 1024M
3+
post_max_size = 1024M
4+
short_open_tag = On
5+
memory_limit = 1024M
6+
max_execution_time = 600
7+
max_input_time = 600
8+
max_input_vars = 1000

config/php/cli-php.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
; PHP configuration for CLI
2+
upload_max_filesize = 1024M
3+
post_max_size = 1024M
4+
short_open_tag = On
5+
memory_limit = 1024M
6+
max_execution_time = 600
7+
max_input_time = 600
8+
max_input_vars = 1000

config/redis/redis.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Redis configuration
2+
bind 0.0.0.0

0 commit comments

Comments
 (0)