I would like to install api-platform on a shared hosting with apache & php. For development purpose, I simulate this hosting via docker (so I don't want to relie on "docker" installation of apiplatform because this is not the target environment).
I simply created my project with symfony:
composer create-project symfony/skeleton:"6.1.*" my_project_directory
I then installed apache-pack:
composer require symfony/apache-pack
And finally api-platform:
composer require api
When I run docker-compose up
, Symfony is ready and avalaible at http://localhost/public but api-platform is not. (I tried http://localhost/api and http://localhost/public/api)
I created a repo to let you see: https://github.com/Niolak/api-platform-apache/tree/main/php
Could you help me to make it work please?
CodePudding user response:
After a small research I found this solution:
Enable the a2enmod
on your Dockerfile
,
// Dockerfile
FROM php:8.1-apache
RUN apt update
RUN apt install -y git
RUN a2enmod rewrite && service apache2 restart
Move the .htaccess
from public/
to the src/
. Afterwards rewrite it with:
// ./src/.htaccess
RewriteEngine on
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public/index.php?path=$1 [NC,L,QSA]
P.S: As I mentioned, this was found after a small research. I dont know if it is a good practise or not.