Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| php_server [2025/10/28 16:52] – created. Might have some errors MediocreMetastasis | php_server [2025/10/29 02:17] (current) – MediocreMetastasis | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Setting up a server to run php code ====== | ====== Setting up a server to run php code ====== | ||
| - | === Download Docker === | + | ===== Download Docker ===== |
| + | Follow instructions on this page | ||
| + | [[https:// | ||
| + | You also want to install the httpd package by running this command in a terminal | ||
| + | <code -> | ||
| + | docker pull httpd | ||
| + | </ | ||
| + | |||
| + | ===== Set up Directory ===== | ||
| + | Create the files and folders shown below | ||
| + | <code -> | ||
| + | |-public-html/ | ||
| + | | |-index.php | ||
| + | | |- ... | ||
| + | |-docker-compose.yml | ||
| + | |-DockerFile | ||
| + | |-php.ini | ||
| + | </ | ||
| + | |||
| + | public-html/ | ||
| + | |||
| + | docker-compose.yml and DockerFile will hold the code to initialize the server. They' | ||
| + | |||
| + | php.ini is the config file for your php server. this let's you change parameters and enable extensions like sql. | ||
| + | |||
| + | ===== Edit files ===== | ||
| + | |||
| + | Edit the DockerFile and run this command: | ||
| + | <code -> | ||
| + | FROM php: | ||
| + | |||
| + | # Enable mod_rewrite (needed for .htaccess) | ||
| + | RUN a2enmod rewrite | ||
| + | |||
| + | # Allow .htaccess files by updating Apache config | ||
| + | RUN sed -i '/< | ||
| + | |||
| + | # Copy your website files | ||
| + | COPY ./ | ||
| + | # Copy custom php.ini | ||
| + | COPY php.ini / | ||
| + | |||
| + | # Optional: ensure permissions are correct | ||
| + | RUN chown -R www-data: | ||
| + | </ | ||
| + | Some of this code sets up the .htaccess file that is included in the public-html/ | ||
| + | |||
| + | You also want to edit the docker-compose.yml file and paste in this code: | ||
| + | <code -> | ||
| + | version: " | ||
| + | |||
| + | services: | ||
| + | web: | ||
| + | build: . | ||
| + | ports: | ||
| + | - " | ||
| + | volumes: | ||
| + | - ./ | ||
| + | - ./ | ||
| + | </ | ||
| + | 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: | ||
| + | <code -> | ||
| + | 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, | ||
