diff --git a/WordPress-Docker/Dockerfile b/WordPress-Docker/Dockerfile deleted file mode 100644 index 95d6a2d..0000000 --- a/WordPress-Docker/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -# Dockerfile (apache-static) -FROM httpd:2.4 - -LABEL maintainer="random@gmail.com" - -# Copy static site into the default Apache document root -COPY ./static-site/ /usr/local/apache2/htdocs/ - -EXPOSE 80 -# httpd base image already starts apache with the correct CMD - diff --git a/WordPress-Docker/README.md b/WordPress-Docker/README.md index 4986abc..5b3a2b8 100644 --- a/WordPress-Docker/README.md +++ b/WordPress-Docker/README.md @@ -2,6 +2,13 @@ This repository provides a Dockerized environment for running WordPress locally using Docker Compose. It's designed for quick development and testing without complex installations. +## Architecture + +- **Apache Server**: Single Apache container with `mod_userdir` enabled +- **User Data**: Shared volume containing student org home directories +- **WordPress**: Separate WordPress + MariaDB containers for testing +- **Structure**: Each org has `/home//public_html/` served at `http://localhost:8080/~` + ## 🚀 Quick Start 1. **Clone the repository:** @@ -9,28 +16,47 @@ This repository provides a Dockerized environment for running WordPress locally ```bash git clone https://git.1337.berkeley.edu/Committee/Secure-OCF-Web-Hosting.git cd Secure-OCF-Web-Hosting/WordPress-Docker - ```` + ``` -2. **Build and start the containers:** +2. **Install Docker Desktop:** + - [macOS](https://docs.docker.com/desktop/setup/install/mac-install/) + - [Windows](https://docs.docker.com/desktop/setup/install/windows-install/) + +3. **Build and start the containers:** ```bash docker-compose up -d ``` -3. **Access WordPress:** +4. **Access WordPress:** Open your browser and navigate to: ``` - http://localhost:8080 + http://localhost:8081 ``` Follow the on-screen instructions to complete the WordPress setup. -## 🛠️ Project Structure +### Access sites: +- **Student org sites**: + - http://localhost:8080/~studentorg1 + - http://localhost:8080/~studentorg2 + - http://localhost:8080/~studentorg3 +- **WordPress**: http://localhost:8081 -* `docker-compose.yml`: Defines the services, networks, and volumes for the WordPress and MySQL containers. -* `Dockerfile`: Customizes the WordPress image (if applicable). +### Add new student org: +```bash +docker exec -it ocf_apache_server bash +mkdir -p /home/neworg/public_html +echo "

New Org

" > /home/neworg/public_html/index.html +chown -R www-data:www-data /home/neworg +``` + +### View Apache logs: +```bash +docker logs ocf_apache_server +``` ## ⚙️ Managing Containers diff --git a/WordPress-Docker/apache/Dockerfile b/WordPress-Docker/apache/Dockerfile new file mode 100644 index 0000000..8d2a6bf --- /dev/null +++ b/WordPress-Docker/apache/Dockerfile @@ -0,0 +1,28 @@ +# Dockerfile (apache-static) +FROM httpd:2.4 + +LABEL maintainer="random@gmail.com" + +# Enable required Apache modules for user directories and PHP +RUN sed -i \ + -e 's/#LoadModule userdir_module/LoadModule userdir_module/' \ + -e 's/#LoadModule vhost_alias_module/LoadModule vhost_alias_module/' \ + -e 's/#LoadModule rewrite_module/LoadModule rewrite_module/' \ + -e 's/#Include conf\/extra\/httpd-userdir.conf/Include conf\/extra\/httpd-userdir.conf/' \ + /usr/local/apache2/conf/httpd.conf + +# Add custom configuration for user directories +COPY httpd-userdir.conf /usr/local/apache2/conf/extra/httpd-userdir.conf + +# Create example student org directories with basic content +RUN mkdir -p /home/studentorg1/public_html && \ + echo "

Welcome to Student Org 1's OCF Page

This is a test page.

" > /home/studentorg1/public_html/index.html && \ + mkdir -p /home/studentorg2/public_html && \ + echo "

Welcome to Student Org 2's OCF Page

This is a test page.

" > /home/studentorg2/public_html/index.html && \ + mkdir -p /home/studentorg3/public_html && \ + echo "

Welcome to Student Org 3's OCF Page

This is a test page.

" > /home/studentorg3/public_html/index.html + +# Set proper ownership +RUN chown -R www-data:www-data /home + +EXPOSE 80 diff --git a/WordPress-Docker/apache/httpd-userdir.conf b/WordPress-Docker/apache/httpd-userdir.conf new file mode 100644 index 0000000..3ca401c --- /dev/null +++ b/WordPress-Docker/apache/httpd-userdir.conf @@ -0,0 +1,20 @@ +# Settings for user home directories +# +# Required module: mod_userdir + +UserDir /home/*/public_html + +# +# Control access to UserDir directories. +# Mimics OCF structure where user directories are in /home +# + + AllowOverride All + Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec + Require all granted + + # Allow .htaccess usage for student customization + + RewriteEngine On + + diff --git a/WordPress-Docker/docker-compose.yml b/WordPress-Docker/docker-compose.yml index 91bdef3..f54b632 100644 --- a/WordPress-Docker/docker-compose.yml +++ b/WordPress-Docker/docker-compose.yml @@ -1,17 +1,28 @@ -version: "3.8" +version: '3.8' + services: - apache-static: + apache: build: - context: . - dockerfile: Dockerfile - container_name: apache-static + context: ./apache ports: - - "8080:80" # static landing page -> http://localhost:8080 + - "8080:80" + volumes: + - userdata:/home + depends_on: + - userdata + container_name: apache-static restart: unless-stopped + userdata: + image: busybox + volumes: + - userdata:/home + container_name: user_data + command: /bin/true + db: image: mariadb:11 - container_name: wp-db + container_name: wp_db environment: MYSQL_ROOT_PASSWORD: rootpass MYSQL_DATABASE: wp_db @@ -23,7 +34,7 @@ services: wordpress: image: wordpress:latest - container_name: wp-site + container_name: wp_site depends_on: - db environment: @@ -32,11 +43,12 @@ services: WORDPRESS_DB_PASSWORD: wp_pass WORDPRESS_DB_NAME: wp_db ports: - - "8081:80" # WordPress site -> http://localhost:8081 + - "8081:80" # WordPress site -> http://localhost:8081 volumes: - wp_data:/var/www/html restart: unless-stopped volumes: + userdata: db_data: wp_data: