commit ddda631033fcce49955ceef654e63ae45846f4e4 Author: Antoni Nuñez Romeu Date: Mon Apr 13 17:13:52 2026 +0200 first commit diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml new file mode 100644 index 0000000..3d0d346 --- /dev/null +++ b/.gitea/workflows/deploy.yaml @@ -0,0 +1,22 @@ +name: Deploy LAMP +run-name: ${{ gitea.actor }} is deploying to PROD servers. +on: [ push, fork, pull ] + +jobs: + Deploy LAMP: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: SSH to remote server + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + port: ${{ secrets.PORT }} + script: | + cd /docker/lamp/ + git pull + docker compose up -d --build + - run: echo "🍏 This job's status is ${{ job.status }}." diff --git a/README.md b/README.md new file mode 100644 index 0000000..172984f --- /dev/null +++ b/README.md @@ -0,0 +1,91 @@ +# Lightweight LAMP Stack with Docker + +This repository contains a lightweight LAMP (Linux, Apache, MySQL, PHP) stack using Docker containers. + +## Features + +- **Apache 2.4** (Alpine-based) - Web server with support for virtual hosts +- **PHP 8.4** (FPM Alpine-based) - Latest PHP version +- **MySQL 8.0** - Relational database +- **Adminer** - Lightweight database management tool (alternative to phpMyAdmin) +- **Virtual Host Support** - Easy to add new virtual hosts +- **Optimized Images** - Using Alpine Linux for minimal footprint + +## Directory Structure + +``` +Docker-Lamp/ +├── apache/ # Apache configuration and Dockerfile +├── php/ # PHP configuration and Dockerfile +├── mysql/ # MySQL configuration and Dockerfile +├── adminer/ # Adminer configuration and Dockerfile +├── html/ # Web root directory (mounted to containers) +├── docker-compose.yml # Docker Compose configuration +└── README.md # This file +``` + +## Quick Start + +1. Clone this repository +2. Navigate to the project directory +3. Start the stack: + +```bash +docker-compose up -d +``` + +4. Access the services: + - Web server: http://localhost:32000 + - Adminer (MySQL GUI): http://localhost:32001 + - PHP Info page: http://localhost:32000/index.php + +## Configuration + +### Apache Virtual Hosts + +To add a new virtual host: +1. Create a new `.conf` file in `apache/vhosts/` +2. Configure your virtual host settings +3. Restart Apache: `docker-compose restart apache` + +Example virtual host configuration is provided in `apache/vhosts/example.conf` + +### Environment Variables + +MySQL credentials are configured in `docker-compose.yml`: +- Database: `lamp_db` +- Username: `lamp_user` +- Password: `lamp_password` +- Root Password: `root_password` + +Adminer uses these same credentials by default. + +## Customization + +### Changing PHP Version +Modify the PHP Dockerfile to use a different PHP version tag. + +### Adding PHP Extensions +Edit the PHP Dockerfile to install additional extensions using `docker-php-ext-install`. + +### Persistent Data +MySQL data is persisted in a Docker volume named `mysql-data`. + +## Stopping the Stack + +```bash +docker-compose down +``` + +To remove volumes as well: + +```bash +docker-compose down -v +``` + +## Notes + +- All images are based on Alpine Linux for minimal size +- Apache is configured to allow `.htaccess` overrides +- PHP-FPM communicates with Apache via the shared volume +- Adminer provides a clean, lightweight interface for database management \ No newline at end of file diff --git a/adminer/Dockerfile b/adminer/Dockerfile new file mode 100644 index 0000000..5bc6bee --- /dev/null +++ b/adminer/Dockerfile @@ -0,0 +1,10 @@ +FROM adminer:latest + +# Set environment variables for Adminer +ENV ADMINER_DEFAULT_SERVER=mysql \ + ADMINER_DEFAULT_USERNAME=lamp_user \ + ADMINER_DEFAULT_PASSWORD=lamp_password \ + ADMINER_DEFAULT_DB=lamp_db + +# Expose port 8080 for Adminer +EXPOSE 8080 \ No newline at end of file diff --git a/apache/Dockerfile b/apache/Dockerfile new file mode 100644 index 0000000..ee41778 --- /dev/null +++ b/apache/Dockerfile @@ -0,0 +1,21 @@ +FROM httpd:2.4-alpine + +# Copy custom httpd.conf if needed (optional) +# COPY httpd.conf /usr/local/apache2/conf/httpd.conf + +# Enable Apache modules (rewrite, etc.) if needed +RUN sed -i 's/^#\(LoadModule rewrite_module\)/\1/' /usr/local/apache2/conf/httpd.conf && \ + sed -i 's/^#\(LoadModule deflate_module\)/\1/' /usr/local/apache2/conf/httpd.conf + +# Set document root +ENV APACHE_DOCUMENT_ROOT=/var/www/html +RUN sed -ri -e 's!/usr/local/apache2/htdocs!${APACHE_DOCUMENT_ROOT}!g' /usr/local/apache2/conf/httpd.conf + +# Expose port 80 +EXPOSE 80 + +# Copy virtual host configuration (will be mounted via docker-compose) +# COPY vhosts/ /etc/apache2/sites-enabled/ + +# Start Apache in foreground +CMD ["httpd-foreground"] \ No newline at end of file diff --git a/apache/vhosts/example.conf b/apache/vhosts/example.conf new file mode 100644 index 0000000..37ba38e --- /dev/null +++ b/apache/vhosts/example.conf @@ -0,0 +1,12 @@ + + ServerName example.local + DocumentRoot /var/www/html/example + + + AllowOverride All + Require all granted + + + ErrorLog ${APACHE_LOG_DIR}/example_error.log + CustomLog ${APACHE_LOG_DIR}/example_access.log combined + \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..227abc1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,49 @@ +version: '3.8' + +services: + apache: + build: ./apache + ports: + - "32000:80" + volumes: + - ./html:/var/www/html + - ./apache/vhosts:/etc/apache2/sites-enabled + depends_on: + - php + networks: + - lamp-network + + php: + build: ./php + volumes: + - ./html:/var/www/html + networks: + - lamp-network + + mysql: + build: ./mysql + environment: + MYSQL_DATABASE: lamp_db + MYSQL_USER: lamp_user + MYSQL_PASSWORD: lamp_password + MYSQL_ROOT_PASSWORD: root_password + volumes: + - mysql-data:/var/lib/mysql + networks: + - lamp-network + + adminer: + build: ./adminer + ports: + - "32001:8080" + depends_on: + - mysql + networks: + - lamp-network + +volumes: + mysql-data: + +networks: + lamp-network: + driver: bridge \ No newline at end of file diff --git a/html/index.php b/html/index.php new file mode 100644 index 0000000..968c8df --- /dev/null +++ b/html/index.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/mysql/Dockerfile b/mysql/Dockerfile new file mode 100644 index 0000000..bcbddb7 --- /dev/null +++ b/mysql/Dockerfile @@ -0,0 +1,13 @@ +FROM mysql:8.0 + +# Set environment variables for MySQL +ENV MYSQL_DATABASE=lamp_db \ + MYSQL_USER=lamp_user \ + MYSQL_PASSWORD=lamp_password \ + MYSQL_ROOT_PASSWORD=root_password + +# Copy initialization scripts (if any) +# COPY init.sql /docker-entrypoint-initdb.d/ + +# Expose MySQL port +EXPOSE 3306 \ No newline at end of file diff --git a/php/Dockerfile b/php/Dockerfile new file mode 100644 index 0000000..1aa1467 --- /dev/null +++ b/php/Dockerfile @@ -0,0 +1,28 @@ +FROM php:8.4-fpm-alpine + +# Install system dependencies +RUN apk add --no-cache \ + libzip-dev \ + zip \ + unzip \ + git \ + curl \ + libpng-dev \ + libjpeg-turbo-dev \ + freetype-dev \ + oniguruma-dev \ + xml-dev \ + && docker-php-ext-configure gd --with-freetype --with-jpeg \ + && docker-php-ext-install -j$(nicon) gd zip pdo_mysql mysqli exif pcntl bcmath opcache + +# Install Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +# Set working directory +WORKDIR /var/www/html + +# Expose port 9000 for PHP-FPM +EXPOSE 9000 + +# Start PHP-FPM +CMD ["php-fpm"] \ No newline at end of file