Jobeet Day 1: Starting up the Project

Today we will setup the development environment, install Symfony 4.2 and display a page of the application in the web browser. First of all, we need to have a friendly working environment for web development. We will use Docker with nginx and PHP images from Docker Hub. To check the minimum requirements for running Symfony 4.2 you can access this link.

Docker configuration

After you install Docker and Docker Compose, create a new folder named jobeet, copy the archive into the folder and decompress it. It is initial configuration for generic PHP project, which was generated by service phpdocker.io. It includes PHP 7.2, MySQL 5.7 and nginx. To start containers just run next command:

docker-compose up -d

Note: In case of error check troubleshooting section

What we did here:

  • we called docker-compose that wraps the functionality of Docker and does working with Docker easier
  • this command reads configuration from docker-compose.yml from folder where command is run
  • up means start and run our entire application
  • -d means detached mode. Command will run containers in the background and console will be free to use for next commands.

After several minutes containers will be running and you can check it with next command:

docker-compose ps

The result should be the same:

      Name                   Command             State           Ports          
-------------------------------------------------------------------------------
jobeet-mysql       docker-entrypoint.sh mysqld   Up      0.0.0.0:3306->3306/tcp 
jobeet-php-fpm     /bin/sh -c /usr/bin/php-fpm   Up      9000/tcp               
jobeet-webserver   nginx -g daemon off;          Up      0.0.0.0:80->80/tcp

Congratulations! Now you have prepared environment for Jobeet project.

Download and install Symfony 4.2

To create our Symfony project we will use method described in official documentation. First of all, enter PHP container:

docker-compose exec php-fpm bash
  • exec command is used to run commands in container
  • php-fpm is the name of the container (line 27 in docker-compose.yml file)
  • bash executes bash in the container

Now you are in php container. Run php -v to check that php exists and the version is 7.2.x.

After that create Symfony project in tmp (temporary) folder, copy it to your project folder, exit from container and change permission of files to be able to edit them from your IDE:

composer create-project symfony/website-skeleton:4.2.* /tmp/jobeet/
cp -aR /tmp/jobeet/. .
exit;
sudo chown -R $USER:$USER .  # if you're on a Mac, use $USER:staff instead

We install into tmp directory and copy then to proper one, because create-project command requires target folder to be empty, but in project’s folder we already have docker files.

Test the Symfony installation

Now open your web browser and enter the http://127.0.0.1 URL. You should see error No route found for "GET /" but it’s OK. You don’t have any routes created yet.

Symfony console

Symfony 4 comes with the console component tool that you will use for different tasks. To see a list of things it can do for you type at the command prompt:

bin/console list

Note: don’t forget first to enter in PHP container if you are not in: docker-compose exec php-fpm bash and to execute this command from PHP container

The Environments

Symfony 4 has different environments. If you look in the project’s directory, you will see file .env with variable APP_ENV=dev inside. Value prod stands for production environment and dev is used by web developers when they work on the application in the development environment.

The development environment will prove very handy because it will show you all the errors and warnings and the Web Debug Toolbar  —  the developer’s best friend. Check the development environment by accessing http://127.0.0.1 in your browser (note the bottom debug toolbar).

Debug toolbar

That’s all for today. You can find the code from this day here: https://github.com/gregurco/jobeet/tree/day1. See you on the next day of this tutorial where we will talk about what exactly the Jobeet site will be about!

Additional information

Troubleshooting

Couldn’t connect to Docker daemon

If you have just installed the docker on linux, there’s a chance you will get the error bellow. It’s expected as the current user doesn’t have enough permissions.

ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

You can fix this either by running the command as root using sudo (since root has all the permissions) or adding current user to the docker group and restarting the terminal.

sudo usermod -a -G docker `whoami`

Address already in use

If you have already installed on the machine a web server server then you will get the error that port 80 is already in use. The error looks like this:

ERROR: for webserver  Cannot start service webserver: driver failed programming external connectivity on endpoint jobeet-webserver (a2fb001830712b327605a3e77744b16fff85b5e7dfc3aa73407dea323dc49163): Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use

In case you have met this issue please update docker-compose.yml, service webserver the ports parameter, change - 80:80 with - 8000:80 and rerun the command. Just keep in mind that in order to access the site instead of http://127.0.0.1 you will have to access http://127.0.0.1:8000.

Next Steps

Continue this tutorial here: Jobeet Day 2: The Project

Main page is available here: Symfony 4.2 Jobeet Tutorial