Skip to content

marcel-st/webserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apache + PHP Webserver on Ubuntu

An Apache HTTP Server with PHP support running on Ubuntu 24.04 LTS inside a Docker container. The container automatically updates all packages to their latest versions on each deployment.

Requirements

Repository Structure

.
├── Dockerfile              # Container image definition
├── docker-compose.yml      # Docker Compose configuration
├── entrypoint.sh           # Startup script (runs apt-get upgrade before Apache)
├── config/
│   └── 000-default.conf    # Apache virtual host configuration
├── html/                   # Web root (mount point for site content, including PHP files)
└── README.md

Quick Start

Using Docker Compose (recommended)

  1. Clone the repository and navigate to the project directory:

    git clone <repository-url>
    cd webserver
  2. Place your website files in the html/ directory (it will be created on first run).

  3. Build and start the container:

    docker compose up -d
  4. The webserver is now accessible at http://localhost.

Using Docker directly

Build the image:

docker build -t apache-webserver .

Run the container:

docker run -d \
  --name apache-webserver \
  -p 80:80 \
  -v $(pwd)/html:/var/www/html \
  apache-webserver

Automatic Updates

Each time the container starts, the entrypoint script runs apt-get upgrade before launching Apache. This ensures the container always runs the latest available package versions, including the most recent stable Apache release, without requiring an image rebuild.

⚠️ Important: Running package upgrades at container start introduces non-deterministic behaviour. Updates may include breaking changes or cause longer startup times. This approach is best suited for non-production environments. For production deployments, rebuild the image on a schedule, test it, and redeploy a known-good image instead.

To pick up the latest updates, simply restart the container:

docker compose restart

Or redeploy with a fresh container:

docker compose down && docker compose up -d

Configuration

Apache Virtual Host

The default virtual host configuration is located in config/000-default.conf. It:

  • Serves files from /var/www/html
  • Enables AllowOverride All so .htaccess files work
  • Enables mod_rewrite, mod_headers, and mod_ssl

To customise the configuration, edit config/000-default.conf and rebuild the image:

docker compose up -d --build

Serving Content

Place your HTML, CSS, JavaScript, PHP, and other site files in the html/ directory. They will be served at the root URL (http://localhost/).

For PHP websites, ensure your entry file is index.php (or explicitly request a .php file in the URL).

Quick PHP test file:

cat > html/info.php <<'EOF'
<?php phpinfo();
EOF

Then open http://localhost/info.php.

Changing the Port

Edit docker-compose.yml and update the ports mapping:

ports:
  - "8080:80"   # Expose on host port 8080 instead of 80

Logs

Apache access and error logs are written inside the container to /var/log/apache2/. To view them:

docker compose logs webserver

Or follow live:

docker compose logs -f webserver

Stopping and Removing the Container

# Stop
docker compose stop

# Stop and remove containers
docker compose down

# Stop, remove containers, and remove the built image
docker compose down --rmi local

Base Image & Software Versions

Component Version
Base OS Ubuntu 24.04 LTS (Noble Numbat)
Web Server Apache 2.4 (latest stable from Ubuntu repos)
PHP Runtime PHP (latest stable from Ubuntu repos)

Release Notes

2026-02-28

  • Added PHP support to the container image (libapache2-mod-php, php, php-cli).
  • Updated Apache vhost default index order to prefer index.php.
  • Added html/index.php sample page for quick PHP verification.
  • Updated documentation to include PHP usage and testing guidance.

About

Apache webserver with PHP support for Docker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors