Getting Started

Installation

Run a PHP 8.5 app with NGINX in a container, then change its PHP settings without touching a config file. It takes a few minutes and needs only Docker.

New to containers? Read Container basics first for the terms used here.

Install Docker

Install Docker by following Docker's installation guide, then confirm Docker and Docker Compose both print a version:

Terminal
docker --version
docker compose version

Create a sample project

Create a project directory with a public folder and move into it:

Terminal
mkdir -p my-php-project/public
cd my-php-project

Create these two files. public/index.php is the page NGINX serves, because the web root in our NGINX image is /var/www/html/public. compose.yml tells Docker which image to run and how.

compose.yml
services:
  php:
    image: serversideup/php:8.5-fpm-nginx
    # Your machine's port 80 goes to NGINX on port 8080
    ports:
      - 80:8080
    # Mount this project at /var/www/html
    volumes:
      - ./:/var/www/html
    environment:
      PHP_UPLOAD_MAX_FILE_SIZE: "250M"

Start the container

Before you start, check that:

  • Your terminal is in my-php-project, next to compose.yml.
  • Nothing else on your machine is using port 80. If something is, change the mapping to 8000:8080 and use http://localhost:8000 below.

Start the container

Terminal
docker compose up

Docker pulls the image and starts the container. Keep this terminal open to see the logs.

Open the app

Go to http://localhost. The PHP info page shows:

  • PHP Version 8.5.x at the top
  • Server API FPM/FastCGI
  • upload_max_filesize 250M, the value you set in compose.yml
  • opcache.enable Off, the image default

Change PHP settings

Our images read environment variables when the container starts. A settings change needs a restart, not a rebuild. Raise the upload limit:

Stop the container

Press + C in the terminal running the container. From another terminal, you can run this in the project directory instead:

Terminal
docker compose down

Update compose.yml

compose.yml
services:
  php:
    image: serversideup/php:8.5-fpm-nginx
    ports:
      - 80:8080
    volumes:
      - ./:/var/www/html
    environment:
      PHP_UPLOAD_MAX_FILE_SIZE: "500M"
      PHP_POST_MAX_SIZE: "500M"
      NGINX_CLIENT_MAX_BODY_SIZE: "500M"

An upload has to fit three limits: PHP's file size limit, PHP's request size limit, and NGINX's request size limit. All three default to 100M.

Start it again

Terminal
docker compose up

Refresh the page

http://localhost now shows upload_max_filesize and post_max_size as 500M.

Change the PHP version and web server

The PHP version and web server are part of the image tag, so switching either one is a one-line change. Stop the container and change the image line to FrankenPHP on PHP 8.4:

compose.yml
services:
  php:
    image: serversideup/php:8.4-frankenphp

Run docker compose up again. The page now shows PHP Version 8.4.x and Server API FrankenPHP, and your upload settings still apply.

Change it back to 8.5-fpm-nginx before you continue, or keep whichever fits your app.

Next steps