Erro ao subir container laravel para vps
[Finalizado Pelo Aluno]
estou subindo as aplicação do docker para uma vps, ao iniciar os containers recebo o erro:
Warning: require(/var/www/public/../vendor/autoload.php): Failed to open stream: No such file or directory in /var/www/public/index.php on line 35
Fatal error: Uncaught Error: Failed opening required '/var/www/public/../vendor/autoload.php' (include_path='.:/usr/local/lib/php') in /var/www/public/index.php:35 Stack trace: #0 {main} thrown in /var/www/public/index.php on line 35
Resolvi como composer install fora do container. ai surgiu outro erro:
UnexpectedValueException
Olá, Johnny! Tudo bem?
Quando subiu os containers, teve algum algum erro? Qual?
Como rodou o composer fora dos containers, está com problemas de permissão (usuário e grupo dos arquivos diferentes -> ls -la)
Vc pode mudar a permissão diretório storage/ ou alterar o usuário e grupo do arquivos: chown -R nomeuser:nomeuser .
Não tive nenhum problema ao subir os containers;
Rodei o composer dentro da pasta do projeto e não tive problema de permissão;
Comandos executados fora do container:
root@g8765l:~/projetos/bvbus-api# ls
app bootstrap composer.lock database docker-compose.yml package.json phpunit.xml README.md routes storage vendor
artisan composer.json config docker Dockerfile package-lock.json public resources server.php tests webpack.mix.js
root@g8765l:~/projetos/bvbus-api# php artisan optimize
Configuration cache cleared!
Configuration cached successfully!
Route cache cleared!
Routes cached successfully!
Files cached successfully!
root@g8765l:~/projetos/bvbus-api# ls -la
total 748
drwxr-xr-x 4 root root 4096 Nov 24 10:31 public
drwxr-xr-x 5 www-data www-data 4096 Nov 24 01:26 storage
root@g8765l:~/projetos/bvbus-api# chown -R root:root storage/
root@g8765l:~/projetos/bvbus-api# ls -la
total 748
drwxr-xr-x 4 root root 4096 Nov 24 10:31 public
drwxr-xr-x 5 root root 4096 Nov 24 01:26 storage
root@g8765l:~/projetos/bvbus-api# php artisan optimize
Configuration cache cleared!
Configuration cached successfully!
Route cache cleared!
Routes cached successfully!
Files cached successfully!
root@g8765l:~/projetos/bvbus-api# chmod -R 755 storage
root@g8765l:~/projetos/bvbus-api# chmod -R 777 storage
root@g8765l:~/projetos/bvbus-api# php artisan optimize
Configuration cache cleared!
Configuration cached successfully!
Route cache cleared!
Routes cached successfully!
Files cached successfully!
root@g8765l:~/projetos/bvbus-api# docker-compose restart
Restarting bvbus-api_queue_1 ... done
Restarting bvbus-api_app_1 ... done
Restarting nginx ... done
Restarting bvbus-api_redis_1 ... done
Restarting bvbus-api_db_1 ... done
Restarting bvbus-api_postgres_1 ... done
como não funcionou fiz:
root@g8765l:~/projetos/bvbus-api# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c212ea347b51 especializati/laravel9-app "docker-php-entrypoi…" 7 hours ago Up 6 minutes 9000/tcp bvbus-api_queue_1
d3608e824cb2 bvbus-api_app "docker-php-entrypoi…" 7 hours ago Up 6 minutes 9000/tcp bvbus-api_app_1
b9f47eb581ec bvbus-api_nginx "/docker-entrypoint.…" 7 hours ago Up 6 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp nginx
be9f90550d30 redis:latest "docker-entrypoint.s…" 7 hours ago Up 6 minutes 6379/tcp bvbus-api_redis_1
32595a421495 mysql:5.7.22 "docker-entrypoint.s…" 7 hours ago Up 6 minutes 0.0.0.0:3388->3306/tcp, :::3388->3306/tcp bvbus-api_db_1
e85a11e8456a postgres:latest "docker-entrypoint.s…" 7 hours ago Up 6 minutes 0.0.0.0:5435->5432/tcp, :::5435->5432/tcp bvbus-api_postgres_1
root@g8765l:~/projetos/bvbus-api# docker exec -it bvbus-api_app_1 bash
johnny@d3608e824cb2:/var/www$ ls -la
total 752
drwxr-xr-x 4 root root 4096 Nov 24 13:31 public
drwxrwxrwx 5 root root 4096 Nov 24 04:26 storage
johnny@d3608e824cb2:/var/www$ chown -R johnny:root storage/
chown: changing ownership of 'storage/logs/laravel.log': Operation not permitted
chown: changing ownership of 'storage/logs/.gitignore': Operation not permitted
chown: changing ownership of 'storage/logs': Operation not permitted
chown: changing ownership of 'storage/framework/views/.gitignore': Operation not permitted
chown: changing ownership of 'storage/framework/views': Operation not permitted
chown: changing ownership of 'storage/framework/testing/.gitignore': Operation not permitted
chown: changing ownership of 'storage/framework/testing': Operation not permitted
chown: changing ownership of 'storage/framework/sessions/.gitignore': Operation not permitted
chown: changing ownership of 'storage/framework/sessions': Operation not permitted
chown: changing ownership of 'storage/framework/cache/data/.gitignore': Operation not permitted
chown: changing ownership of 'storage/framework/cache/data': Operation not permitted
chown: changing ownership of 'storage/framework/cache/.gitignore': Operation not permitted
outra tentativa:
johnny@d3608e824cb2:/var/www$ exit
exit
root@g8765l:~/projetos/bvbus-api# chown -R johnny:root storage/
chown: invalid user: ‘johnny:root’
meu .env:
APP_NAME="BvBus"
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_LEVEL=debug
BROADCAST_DRIVER=log
CACHE_DRIVER=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
e o erro continua:
UnexpectedValueException
Vi aqui que está usando um usuário sudo, por isso os problemas de permissão: root@g8765l:~/projetos/bvbus-api#
O problema não está no seu container, mas sim neste usuário sudo root.
Recomendo criar um usuário, igual faço aqui neste curso: https://academy.especializati.com.br/curso/ambiente-docker-na-digital-ocean
Obrigado professor funcionou!
crie um user conforme o curso e executei tudo com esse user ai não tive problema de permissão, a única coisa que tive que fazer adcional foi gerar uma nova chave ssl com esse usuario ai fucionou. Obrigado.
Precisa estar logado para conseguir responder a este ticket!
Clique Aqui Para Entrar!