0

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?

1 Answer 1

2

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.

Resources:
  1. .htaccess redirect from site root to public folder, hiding "public" in URL?
  2. Redirect all to index.php using htaccess
  3. How to enable mod_rewrite for Apache 2.2
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it seems all good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.