I am trying to setup the Dockerfile for PHP services. PHP scripts are served using Nginx server in docker container but its giving me vendor/autoload.php not found error.
I have tried changing Dockerfile several times but the vendor/autoload.php error still persists.
Here is the Dockerfile
FROM composer as builder
RUN mkdir -p /usr/app/php-services
WORKDIR /usr/app/php-services
#copy composer file
COPY composer.json .
RUN composer install
#copy php-scripts to /usr/app/php-services
COPY . .
FROM nginx:alpine
COPY --from=builder /usr/app/php-services /usr/app/php-services
COPY ./phpdocker/nginx/nginx.conf /etc/nginx/conf.d/default.conf
#check if vendor has autoload file and it exists!!!
RUN ls /usr/app/php-services/vendor
EXPOSE 8000
The scripts should work fine but whenever I run docker logs it says.
Here is the nginx.conf file
server {
listen 8000;
access_log /var/log/nginx/application.access.log;
root /usr/app/php-services;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_pass php-fpm:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include fastcgi_params;
}
}
I have tried almost everything and have literally no idea why this is happening. What am I doing wrong here? Is there any issue in my nginx.conf file?
Sorry about the last response, I misunderstood the problem.
However I was able to build a similar container but wasn't able to reproduce the error. It might be something with the php-scripts you are adding that aren't in this post. I was able to get a similar container build though using modified copies of your Dockerfile + nginx.conf. I also added some debugging for troubleshooting in the Docker file and created a launch/build script.
I edited the Dockerfile to have the following. This will add setting 755 permissions if you need, listing out a few directories in question and your log. If needed post that output to comments.
FROM composer as builder
RUN mkdir -p /usr/app/php-services
WORKDIR /usr/app/php-services
COPY composer.json .
RUN composer install
#copy php-scripts to /usr/app/php-services
COPY . .
COPY php.ini /usr/app/php-services
FROM nginx:alpine
COPY --from=builder /usr/app/php-services /usr/app/php-services
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY php.ini .
#check if vendor has autoload file and it exists!!!
RUN chmod 755 -R /usr/app/php-services;ls -lrt /etc/nginx/ /var/log /usr/app/php-services/ /usr/app/php-services/vendor /usr/app/php-services/vendor/twitter.php;/var/log/nginx/application_php_errors.log | tee -a shellcheck.log
#CMD ["ls -la /usr/app/php-services/vendor"]
EXPOSE 8000
Then edited nginx.conf to have the following. Added resolver information (unsure if this will apply to you or not) including upstream property, try_files, including snippets for fastcgi.
server {
listen 8000;
resolver 127.0.0.11;
set $upstream php-fpm:9000;
access_log /var/log/nginx/application.access.log;
root /usr/app/php-services;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
include snippets/fastcgi-php.conf;
fastcgi_pass $upstream;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include fastcgi_params;
}
}
Then created a shell script to launch build and report back some debug info. Add this next to the Dockerfile on docker host, make it executable with chmod +x run-container.sh then run it with ./run-container.sh $PORTNUM. ie ./run-container.sh 8000
#!/bin/bash
docker build . -t php-services:v3
docker run -d -p $1:8000 php-services:v3
CONTAINER=`docker ps -a | head -2 | tail -1| awk '{print $1}'`
echo "Your container is: $CONTAINER"
docker ps -a | head -2 | tail -1| awk '{print $1}'
docker cp $CONTAINER:/var/log/nginx/ .
docker cp $CONTAINER:/shellcheck.log .
docker cp $CONTAINER:/etc/nginx/fastcgi.conf .
docker ps -a | grep $CONTAINER
docker logs $CONTAINER
Let me know if any of this works for you, for some reason yours is expecting a twitter.php which I do not have and wasn't an issue. Is that something you are copying into container from that folder?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.