This is an old revision of the document!
Table of Contents
Setting up a server to run php code
Download Docker
Follow instructions on this page Docker Installation
You also want to install the httpd package by running this command in a terminal
docker pull httpd
Set up Directory
|-public-html/ | |- |-docker-compose.yml |-DockerFile |-php.ini
Edit files
Edit the DockerFile and run this command:
FROM php:8.2-apache # Enable mod_rewrite (needed for .htaccess) RUN a2enmod rewrite # Allow .htaccess files by updating Apache config RUN sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf # Copy your website files COPY ./public-html/ /var/www/html/ # Copy custom php.ini COPY php.ini /usr/local/etc/php/conf.d/custom.ini # Optional: ensure permissions are correct RUN chown -R www-data:www-data /var/www/html
You also want to edit the docker-compose.yml file and paste in this code:
version: "3.9"
services:
web:
build: .
ports:
- "8080:80"
volumes:
- ./public-html:/var/www/html
- ./php.ini:/usr/local/etc/php/conf.d/custom.ini
You do not need to edit the php.ini. It is included for if and when you need to use it. You can also edit the 2 docker files to let you run a sql server alongside your web server.
Build and Activate Server
open up a terminal located in your directory and run these commands:
docker compose build docker compose up -d
Save these commands for later. You'll need to run them everytime you edit the DockerFile, docker-compose.yml, or php.ini file. You can also use these commands to activate the server.
