diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..434a391 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,18 @@ +.git +.gitignore +.env +vendor +node_modules +storage/logs/* +storage/framework/cache/* +storage/framework/sessions/* +storage/framework/views/* +bootstrap/cache/* +tests +.editorconfig +.phpunit.result.cache +phpunit.xml +readme.md +docker-compose.yml +Dockerfile +.dockerignore diff --git a/.env.docker b/.env.docker new file mode 100644 index 0000000..e56d3f7 --- /dev/null +++ b/.env.docker @@ -0,0 +1,13 @@ +# Docker Environment Variables +# Copy this file and configure for your external MySQL database + +# Database Configuration - Update these to connect to your external MySQL +DB_HOST=your-mysql-host +DB_PORT=3306 +DB_DATABASE=merchbay_admin +DB_USERNAME=your-mysql-user +DB_PASSWORD=your-mysql-password + +# Application Configuration +APP_ENV=production +APP_DEBUG=false diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2414610 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,61 @@ +# Use PHP 7.4 with Apache (compatible with Laravel 5.2 and ARM64) +FROM php:7.4-apache + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + git \ + curl \ + libpng-dev \ + libonig-dev \ + libxml2-dev \ + libzip-dev \ + zip \ + unzip \ + libfreetype6-dev \ + libjpeg62-turbo-dev \ + openssh-client \ + && docker-php-ext-configure gd --with-freetype --with-jpeg \ + && docker-php-ext-install -j$(nproc) gd + +# Install PHP extensions +RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath zip + +# Enable Apache mod_rewrite +RUN a2enmod rewrite + +# Install Composer +COPY --from=composer:1.10 /usr/bin/composer /usr/bin/composer + +# Set working directory +WORKDIR /var/www/html + +# Copy existing application directory contents +COPY . /var/www/html + +# Copy existing application directory permissions +RUN chown -R www-data:www-data /var/www/html \ + && chmod -R 755 /var/www/html/storage \ + && chmod -R 755 /var/www/html/bootstrap/cache + +# Create .env file if it doesn't exist +RUN if [ ! -f .env ]; then cp .env.example .env; fi + +# Install PHP dependencies without running post-install scripts +RUN composer install --no-dev --no-scripts --no-interaction + +# Generate application key +RUN php artisan key:generate + +# Optimize autoloader +RUN composer dump-autoload --optimize --no-dev + +# Configure Apache DocumentRoot to point to Laravel's public directory +ENV APACHE_DOCUMENT_ROOT=/var/www/html/public +RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf +RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf + +# Expose port 80 +EXPOSE 80 + +# Start Apache +CMD ["apache2-foreground"] diff --git a/README-DOCKER.md b/README-DOCKER.md new file mode 100644 index 0000000..7aeba46 --- /dev/null +++ b/README-DOCKER.md @@ -0,0 +1,165 @@ +# Docker Deployment Guide for MerchBay Admin + +## Prerequisites + +- Docker installed on your system +- Docker Compose installed on your system + +## Quick Start + +### 1. Build and Start Containers + +```bash +docker-compose up -d --build +``` + +This will: +- Build the application container +- Start MySQL database +- Start PHPMyAdmin +- Set up networking between containers + +### 2. Access the Application + +- **Application**: http://localhost:8080 +- **PHPMyAdmin**: http://localhost:8081 + +### 3. Run Database Migrations + +```bash +docker-compose exec app php artisan migrate +``` + +### 4. Seed Database (if needed) + +```bash +docker-compose exec app php artisan db:seed +``` + +## Useful Commands + +### View Container Logs + +```bash +docker-compose logs -f app +``` + +### Access Container Shell + +```bash +docker-compose exec app bash +``` + +### Stop Containers + +```bash +docker-compose down +``` + +### Stop and Remove Volumes (Clean Slate) + +```bash +docker-compose down -v +``` + +### Rebuild Containers + +```bash +docker-compose up -d --build --force-recreate +``` + +### Run Artisan Commands + +```bash +docker-compose exec app php artisan [command] +``` + +### Clear Laravel Cache + +```bash +docker-compose exec app php artisan cache:clear +docker-compose exec app php artisan config:clear +docker-compose exec app php artisan route:clear +docker-compose exec app php artisan view:clear +``` + +### Install/Update Composer Dependencies + +```bash +docker-compose exec app composer install +# or +docker-compose exec app composer update +``` + +## Environment Configuration + +Edit the `docker-compose.yml` file to customize: +- Database credentials +- Port mappings +- Environment variables + +For production deployment, update the `APP_ENV` and `APP_DEBUG` values: + +```yaml +environment: + - APP_ENV=production + - APP_DEBUG=false +``` + +## Database Connection + +The application connects to the MySQL container using these credentials (defined in docker-compose.yml): + +- **Host**: db +- **Database**: merchbay_admin +- **Username**: merchbay_user +- **Password**: merchbay_password + +## Troubleshooting + +### Permission Issues + +If you encounter permission errors: + +```bash +docker-compose exec app chown -R www-data:www-data /var/www/html/storage +docker-compose exec app chmod -R 755 /var/www/html/storage +``` + +### Database Connection Issues + +Ensure the database container is fully started: + +```bash +docker-compose logs db +``` + +Wait a few seconds after starting containers for MySQL to initialize. + +### Port Already in Use + +If ports 8080 or 3306 are already in use, modify the ports in `docker-compose.yml`: + +```yaml +ports: + - "8090:80" # Change 8080 to 8090 or any available port +``` + +## Production Deployment + +For production environments: + +1. Update `.env` file with production settings +2. Set `APP_DEBUG=false` in docker-compose.yml +3. Use a secure database password +4. Consider using a reverse proxy (Nginx/Traefik) with SSL +5. Set up proper backup strategies for database volumes +6. Configure log rotation + +## Volumes + +- `db_data`: Persistent MySQL data +- `./storage`: Laravel storage (logs, cache, sessions) +- `./public/uploads`: User uploaded files + +These volumes ensure data persists across container restarts. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..83c916a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +version: '3.8' + +services: + app: + build: + context: . + dockerfile: Dockerfile + container_name: merchbay_admin_app + restart: unless-stopped + ports: + - "8080:80" + environment: + - APP_ENV=production + - APP_DEBUG=false + - DB_CONNECTION=mysql + - DB_HOST=${DB_HOST:-localhost} + - DB_PORT=${DB_PORT:-3306} + - DB_DATABASE=${DB_DATABASE:-merchbay_admin} + - DB_USERNAME=${DB_USERNAME:-root} + - DB_PASSWORD=${DB_PASSWORD:-} + volumes: + - ./storage:/var/www/html/storage + - ./public/uploads:/var/www/html/public/uploads + network_mode: bridge