UX

Run Laravel with Podman on Fedora Silverblue

On this page

Introduction

This tutorial describes how you can run Laravel (a PHP framework) in a Podman container on Fedora Silverblue. While this tutorial is about Fedora Silverblue, you can also use this tutorial on Fedora or any other distribution. You only have to change the way you install Podman and podman-compose. Another option is that you don't use Podman, but Docker. In that case, just use the commands docker and docker-compose (after installing Docker and docker-compose first of course).

Installation

rpm-ostree install podman-compose
reboot

File structure

Server
├── Dockerfile
├── docker-compose.yml
└── www
    ├── laravel-mvc

You only have to create the directories Server and www.  Put the files Dockerfile and docker-compose in the Server directory. The directory laravel-mvc will be created when you install Laravel with Composer (a PHP package manger).

Dockerfile

FROM php:8.1-apache
RUN apt-get update
RUN apt-get install -y git libzip-dev zip unzip npm
RUN docker-php-ext-install pdo pdo_mysql zip
RUN a2enmod rewrite
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

The file Dockerfile does not have an extension.

docker-compose.yml

version: 3.4
services:
  webserver:
    container_name: webserver
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      - database
    volumes:
      - ./www:/var/www/html:Z
    ports:
      - 8000:80
  database:
    container_name: database
    image: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: [root password]
      MYSQL_DATABASE: [database name]
      MYSQL_USER: [database user]
      MYSQL_PASSWORD: [password user]
    ports:
      - 9906:3306
    volumes:
      - dbdata:/var/lib/mysql
  phpmyadmin:
     container_name: phpmyadmin
     image: phpmyadmin/phpmyadmin
     ports:
       - 8080:80
     restart: always
     environment:
       PMA_HOST: database
     depends_on:
       - database

The :Z is necessary if SELinux is enabled on your system.

The data of the database is stored in the volume dbdata (~.local/share/containers/storage/volumes).

Start containers

podman-compose up -d

Run the command inside the directory Server

Enter container

podman exec -it webserver /bin/bash

Install Laravel

composer create-project laravel/laravel laravel-mvc

Run the command inside the directory www

Web address

The website can be found at the address below.

localhost:8000/laravel-mvc/public/

Laravel .env file

DB_CONNECTION=mysql
DB_HOST=database
DB_PORT=3306
DB_DATABASE=[database name]
DB_USERNAME=[database user]
DB_PASSWORD=[password database user]

The value database of the property DB_HOST corresponds to the service database in the docker-compose file.

Stop containers

podman-compose down

Run the command inside the directory Server