39
Setting up a Symfony application using Docker.
In this blog we are going to be setting up a Symfony application inside of a Docker container. If you have not previously worked with a plain Docker file, you can follow my last post here.
At this point we should have our container running, and inside of our container we can run the following commands.
To create our own docker container we need to create two new files:
docker-compose.yml
nginx.conf
The
docker-compose.yml
should contain the following codeversion: '3'
services:
web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/nginx.conf
- ./app:/app
php:
image: php:fpm
volumes:
- ./app:/app
In order for this to work, you need to create an 'app' folder and inside of that, you need to create a 'public' folder, inside of that you can create your
index.html
file.As for the 2nd file mentioned, you need to add the following code:
server {
listen 80 default_server;
root /app/public;
}
This will start the container server and tell the container which directory to point to.
Once we have done this we need to create a
Once we have done this we need to create a
index.php
file inside of the /app/public
directory.Inside of our newly created
index.php
file, we need to copy/paste the following:<?php
phpinfo();
Now we need to re-run the server using
docker-compose up
.After restarting the docker container we should see PHP manual page.
If you see this, then congratulations, you have successfully created your PHP Docker container!! 🎊 🎊
If you see this, then congratulations, you have successfully created your PHP Docker container!! 🎊 🎊
Now that we have our basic PHP container, we can add Symfony to it.
To do this we need to stop the server by using the
control
+ c
command.Afterwards we want to run the following command:
curl -LO https://raw.githubusercontent.com/bitnami/bitnami-docker-symfony/master/docker-compose.yml
This will download Bitnami's official Symfony
docker-compose.yml
image. Once this command has finished, we can re-run docker-compose up
to run the build process. This is going to take some time, so feel free to grab a beverage.-Anthony
Follow me on twitter
Follow me on twitter
39