0

enter image description here

There are a lot of articles about this, I read them but none of the solutions worked.

I have laravel mounted via docker-compose in the folder /var/www/html/app

I am using this docker image https://github.com/khromov/alpine-nginx-php8/blob/master/Dockerfile

Logged into the container as root user with docker-compose exec -u root web sh, I can gave 777 permission to all under bootstrap folder, then I ls and result as below

/var/www/html/app # ls -ln bootstrap/
total 20
-rwxrwxrwx    1 1000     1000          1396 Oct  4  2019 app.php
-rwxrwxrwx    1 1000     1000          1079 Sep 11  2019 autoload.php
drwxrwxrwx    1 1000     1000            96 Jul  8  2021 cache
-rwxrwxrwx    1 1000     1000          2918 May 26 16:01 container.php
-rwxrwxrwx    1 1000     1000           120 Sep 11  2019 testing-container.php
-rwxrwxrwx    1 1000     1000           713 Feb  3 16:08 testing.php

I did the same in host user (where docker runs), gave 777 and chown to nobody:nobody

ls -l bootstrap 
total 40
-rwxrwxrwx   1 nobody  nobody  1396 Oct  4  2019 app.php
-rwxrwxrwx   1 nobody  nobody  1079 Sep 11  2019 autoload.php
drwxrwxrwx  42 nobody  nobody  1344 Jul  8 10:51 cache
-rwxrwxrwx   1 nobody  nobody  2918 May 26 18:01 container.php
-rwxrwxrwx   1 nobody  nobody   120 Sep 11  2019 testing-container.php
-rwxrwxrwx   1 nobody  nobody   713 Feb  3 17:08 testing.php

Still laravel gives me the error permission denied.. I also gave chmod -R 777 bootstrap from guest host the one running docker not inside docker itself then docker-compose restart web, still nothing changed.

The service in docker-compose looks like

  web:
    user: nobody:nobody
    build:
      context: .
      dockerfile: ./web/Dockerfile
      args:
        - DOMAIN=${DOMAIN}
    restart: on-failure
    environment:
      DOMAIN: ${DOMAIN}
    volumes:
      - ${WEB_PATH}:/var/www/html/app
      - ./web/default.conf:/etc/nginx/sites-available/${DOMAIN}
    expose:
      - 8080
    container_name: web

Above I even tried to use user nobody as that one is used by nginx but no success

Laravel is running as nobody user from the error logs:

Server/Request Data
PATH    
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
HOSTNAME    
"956b41d4651a"
HOME    
"/"
SUPERVISOR_ENABLED  
"1"
SUPERVISOR_PROCESS_NAME 
"php-fpm"
SUPERVISOR_GROUP_NAME   
"php-fpm"
USER    
"nobody"

In addition to give 777, i also tried chown -R nobody:nobody bootstrap inside container itself but still did not work

So is there some way to mount in docker-compose and give ownership to nobody:nobody ? or some other solution

Kristi Jorgji
  • 1,154
  • 1
  • 14
  • 39
  • Can you try `php artisan optimize` – Kevin Jul 08 '21 at 08:38
  • The "--force" option does not exist. PHP Fatal error: Uncaught RuntimeException: Curl error (code 60): SSL certificate problem: certificate is not yet valid in /var/www/html/app/vendor/monolog/monolog/src/Monolog/Handler/Curl/Util.php:56 Stack trace: #0 /var/www/html/app/vendor/newrelic/monolog-enricher/src/AbstractHandler.php(137): Monolog\Handler\Curl\Util::execute() – Kristi Jorgji Jul 08 '21 at 08:39
  • Using `"laravel/framework": "^8.40",` in composer.lock `"name": "laravel/framework", "version": "v8.49.2",` – Kristi Jorgji Jul 08 '21 at 08:39
  • Running just optimize worked ```php artisan optimize Configuration cache cleared! Configuration cached successfully! Route cache cleared! Routes cached successfully! Files cached successfully! ``` but then i cannot open the site at all, got some error `web | #5 /var/www/html/app/ve...PHP message: PHP Fatal error: Uncaught Error: Class "PDO" not found in /var/www/html/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:1409 ` Recreating container fixed this.. but permission issue is shown again – Kristi Jorgji Jul 08 '21 at 08:41
  • So it changed the error ? https://stackoverflow.com/questions/11813381/php-fatal-error-class-pdo-not-found – Kevin Jul 08 '21 at 08:42
  • Yes it changed error but i fixed that pdo error by running `php artisan optimize:clear ` and rebuilding container, so we are still at my question that is the issue. Need to fix permission error now – Kristi Jorgji Jul 08 '21 at 08:44
  • Check this solution :https://stackoverflow.com/questions/4917811/file-put-contents-failed-to-open-stream-permission-denied – Kevin Jul 08 '21 at 08:45
  • i got stuck with error posted here , am again at ```ErrorException thrown with message "file_put_contents(/var/www/html/app/bootstrap/cache/packages.phpohihOp): Failed to open stream: Permission denied" ``` – Kristi Jorgji Jul 08 '21 at 08:45
  • Thanks finished reading all of them but have tried already (as mentinoned also in my question what i tried already) – Kristi Jorgji Jul 08 '21 at 08:48
  • In documentation there is a lines such a "If you copied files into `./src-compose` you need to run: `sudo chown -R nobody:nogroup ./src-compose sudo chmod -R 777 ./src-compose` This makes sure that the files have the correct owner inside the container but remain writable outside of it." – fatm Jul 08 '21 at 09:42
  • @FatimaMazhit thanks yes i did that , inside my dockerfile ` RUN mkdir -p /var/www/html/app RUN chown -R nobody.nobody /var/www/html/app` – Kristi Jorgji Jul 08 '21 at 10:03

0 Answers0