Reputation: 1
I'm running my application in Docker Windows wsl/Ubuntu, using PHP 8.1. Docker looks into my working directory, not in the root directory to get the autoloader. However, the vendor folder is in the root directory of my project.
FROM php:latest
RUN groupadd -r appgroup && useradd -r -g appgroup appuser
RUN apt-get update && apt-get install -y libcurl4-gnutls-dev
RUN docker-php-ext-install mysqli pdo pdo_mysql curl
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www/html
COPY . /var/www/html
RUN chown -R appuser:appgroup /var/www/html
USER appuser
RUN composer install
VOLUME /var/www/html/
EXPOSE 80
CMD ["php", "-S", "0.0.0.0:80"]
my index.php (located in the working directory):
require_once __DIR__ . '/../vendor/autoload.php';
echo 'test';
the result I get in my browser: Warning: require_once(/var/www/html/../vendor/autoload.php): Failed to open stream: No such file or directory in /var/www/html/index.php on line 3
Fatal error: Uncaught Error: Failed opening required '/var/www/html/../vendor/autoload.php' (include_path='.:/usr/local/lib/php') in /var/www/html/index.php:3 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 3
Upvotes: 0
Views: 293
Reputation: 62
You might find the answer on PHP - Failed to open stream : No such file or directory
You need to set SITE_ROOT
which is missing in your index.php
With this method; it doesn't depend on ini settings
of php and simplifies the deployment in docker if you need to scale it further down the line.
Upvotes: 0