Last few days I am playing around with API Platform, a REST and GraphQL framework to build modern API-driven projects using Symfony framwork. It’s framework for quick and easy setup of an API project. And it’s really easy and fast, except if you face with few issues as I did. In this article I want to share few hints for beginners in Docker and API Platform.
So in short this is process of configuring the API Platform project:
1. Install docker and docker compose
2. Download API Platform (TAR.GZ file) or generate it using this link: https://github.com/api-platform/api-platform/generate
3. Enter the project folder
4. run `docker-compose pull`
5. run `docker-compose up -d`
That should be it, but unfortunatelly I had some issues on newly created VirtualBox machine.
Issue 1: Docker-compose fails to run due to “Permission denied...” error
Solution is to add current logged user to “docker” group:
`usermod -a -G docker [YOUR-USER]`
Also don’t forget to log out and login again.
Issue 2: API Platform – File not found
This is the best error I have ever seen. :)
For me, there was problem with permissions b/c I run Virtual Box machine as docker platform and I copied api-platform files from a shared folder which has files with root as owner.
Solution: make sure your current user has "rwe" permissions:
`chown -R [YOUR-USER] /your-api-dir && chmod -R 775 /your-api-dir`
According to some Github issues, solution is just to use TAR.GZ file, but it did not work for me.
Hint 3: API Platform 503 Bad Gateway Nginx error
This is caused by problem with running PHP-FPM. Basically I solved it with one of the two commands:
1. `docker-compose exec php php-fpm -D`
2. `docker-compose stop && docker-compose up -d`
Issue 4: Untrusted host “somehost”
Add your host to your .env (or .env.local or other file) in TRUSTED_HOSTS variable.
Run `docker-compose exec php php bin/console cache:clear`