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 Workstation 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, you will have to use the commands docker and docker-compose instead.
When you install Laravel as described in the tutorial, you are basically installing a complete (L-)AMP-stack (Apache, MySQL/MariaDB and PHP) on your computer, so this tutorial can also be used for that purpose. Just skip the part where you install Laravel.
Install podman-compose
rpm-ostree install podman-compose
reboot
Create file structure
Server
├── Dockerfile
├── docker-compose.yml
└── www
├── laravel-mvc
You only have to create the directories Server and www. The Dockerfile and the docker-compose file have to be in the directory Server.
The directory laravel-mvc will be created when you install Laravel with Composer.
Add the Dockerfile
Add the code below to the 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=composerThe Dockerfile does not have an extension.
Add docker-compose.yml
Add the code below to the docker-compose file.
version: 3.4
volumes:
dbdata:
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
Add random values to the databases settings.
Start containers
podman-compose up -dRun the command in the directory Server
Enter container
In order to install Laravel, you need to enter the container webserver first.
podman exec -it webserver /bin/bashInstall Laravel
composer create-project laravel/laravel laravel-mvcWeb 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 downRun the command inside the directory Server