Command not found: composer - composer-php

I am following this tutorial. When I get to around the 11:48 minute mark, I am supposed to run the command:
composer create-project laravel/laravel .
To which the terminal response is:
zsh: command not found: composer
I am not sure if this is necessary, but here is my docker-composer.yml file:
version: '3'
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8088:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:5.7.22
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "4306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: homestead
MYSQL_USER: homestead
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
networks:
- laravel
I had to install homebrew before I could install composer using the commands from the composer website.
The terminal confirmed that Composer version 1.10.10 was successfully installed.
Regardless, I'm still getting "command not found: composer" in the terminal.
How do I fix this?

This problem arises when you have composer installed locally.To make it globally executable,run the below command in terminal
sudo mv composer.phar /usr/local/bin/composer

In addition, if it doesn't solved the problem with:
sudo mv composer.phar /usr/local/bin/composer
After, try:
sudo -u <user> /usr/local/bin/composer <command> <option>
It works for me with nginx's user.

Related

Laravel 9 with Docker - CSS and JS not loading using Vite

I'm having trouble in determining the cause of not loading of my CSS stylesheet and Javascript on my Laravel 9 project using Docker in my Windows OS.
I have done all the steps after creating containers and no error message thrown in my page.
Should I run npm run dev in the container? I have no issue before using mix but I really need to deploy this project.
I also attached screenshot below from chrome dev tools that everything in my app.js & app.css is not loading
Dockerfile:
# Set master image
FROM php:8.0-fpm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN chown -R www-data:www-data /var/www
# Set working directory
WORKDIR /var/www
USER $user
docker-compose.yml
version: '3'
services:
#Laravel App
app:
build:
context: .
dockerfile: Dockerfile
image: dr3
container_name: app
volumes:
- .:/var/www/
ports:
- "9000:9000"
networks:
- laraveldockerize
#Nginx Service
nginx:
image: nginx:stable-alpine
container_name: nginx
restart: unless-stopped
ports:
- "8000:80"
volumes:
- .:/var/www
- ./dockerize/nginx/default.conf:/etc/nginx/conf.d/default.conf
networks:
- laraveldockerize
#MySQL Service
db:
image: mysql:5.7
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: ${DB_DATABASE}
# MYSQL_USER: ${DB_USERNAME}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
volumes:
- ./dockerize/mysql/data:/var/lib/mysql
- ./dockerize/mysql/my.cnf:/etc/mysql/conf.d/mysql-custom.cnf
networks:
- laraveldockerize
node:
image: node:alpine
container_name: node
working_dir: /var/www/
tty: true
ports:
- 5173:5173
volumes:
- ./:/var/www
networks:
- laraveldockerize
#Docker Networks
networks:
laraveldockerize:
driver: bridge
Vite:

Docker-compose run script after container starts

My goal is to have a one-liner (kinda) for building and starting my app. I want to be able to execute this command and run several additional commands related to my app (like migrations, init and starting a websocket server).
But when I try to use ENTRYPOINT directive my php service runs commands but the service itself is not working properly.
docker log nginx shows me this error:
[error] 31#31: *2 connect() failed (111: Connection refused) while connecting to upstream,
If I comment out ENTRYPOINT in back.dockerfile my app runs fine, but I have to manually run those artisan commands
docker-compose build && docker-compose up -d
Is there a way to achieve such result?
My docker-compose.yml
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
volumes:
- ./app:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
ports:
- "8000:80"
depends_on:
- php
- mysql
networks:
- laravel
tty: true
php:
build:
context: .
dockerfile: ./docker/back.dockerfile
container_name: php
ports:
- "9000:9000"
depends_on:
- node
networks:
- laravel
node:
build:
context: .
dockerfile: ./docker/front.dockerfile
container_name: node
ports:
- "3000:3000"
networks:
- laravel
mysql:
image: mysql:8.0
container_name: mysql
restart: unless-stopped
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: laravel
MYSQL_USER: laravel
MYSQL_PASSWORD: laravel
MYSQL_ROOT_PASSWORD: root
SERVICE_NAME: mysql
networks:
- laravel
back.dockerfile
FROM php:7.4-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
RUN apk update
RUN apk upgrade
RUN apk add bash
RUN alias composer='php /usr/bin/composer'
ENV COMPOSER_ALLOW_SUPERUSER 1
COPY ./app/composer.json ./app/composer.lock ./
COPY ./app .
RUN composer install --no-scripts --prefer-dist --optimize-autoloader
RUN chown -R www-data:www-data /var/www/html
RUN chmod -R 755 /var/www/html/storage
COPY ./entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 6001
entrypoint.sh
#!/bin/sh
set -e
php artisan migrate --path 'database/migrations'
php artisan app:init
php artisan websockets:serve
exec "$#"

Laravel with docker on RPI - Failed to open stream: Permission denied

I am testing deployment with docker on RPI but getting "Failed to open stream: Permission denied"
I tried few solutions but none of them worked for me
Permission Denied Error using Laravel & Docker
Laravel & Docker: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
my Dockerfile:
FROM php:8.0-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql
RUN chown -R www-data:www-data /var/www
RUN chmod -R 755 .
and docker-compose.yml
version: "3.7"
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
restart: unless-stopped
container_name: nginx
ports:
- "80:80"
volumes:
- ./:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mariadb
networks:
- laravel
mariadb:
image: yobasystems/alpine-mariadb:latest
restart: unless-stopped
container_name: mariadb
tty: true
ports:
- "4306:3306"
volumes:
- ./mariadb:/var/lib/mariadb
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: laravel_dev
MYSQL_USER: laravel_dev
MYSQL_PASSWORD: laravel_dev
SERVICE_TAGS: dev
SERVICE_NAME: mariadb
networks:
- laravel
phpmyadmin:
image: phpmyadmin
container_name: phpmyadmin
restart: unless-stopped
ports:
- 4380:80
environment:
PMA_ARBITRARY: 1
PMA_PORT: 3306
PMA_HOST: mariadb
PMA_USER: laravel_dev
PMA_PASSWORD: laravel_dev
depends_on:
- mariadb
networks:
- laravel
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./:/var/www/html
ports:
- "9000:9000"
networks:
- laravel
composer:
image: composer:latest
container_name: composer
volumes:
- ./:/var/www/html
working_dir: /var/www/html
networks:
- laravel
npm:
image: node:current-alpine3.14
container_name: npm
volumes:
- ./:/var/www/html
working_dir: /var/www/html
entrypoint: ['npm']
networks:
- laravel
artisan:
build:
context: .
dockerfile: Dockerfile
container_name: artisan
volumes:
- ./:/var/www/html
depends_on:
- mariadb
working_dir: /var/www/html
entrypoint: ['php', '/var/www/html/artisan']
networks:
- laravel
Only thing that worked was chmod 777 on project root folder but that is not the solution i would be comfortable with using.
So i found a solution on reddit
https://www.reddit.com/r/docker/comments/hjsipd/permission_denied_with_volumes/fwoixqe/
I had to sign project folder to container user, which i found with
less /etc/passwd. In this case name of user was www-data with UID 82. And command chown -R 82:82 .

Laravel's the composer.lock file is not updated on docker/ docker-compose

I am working on a Laravel project. I am using docker-compose/ docker as my development environment.
This is my docker-compose.yml file.
version: '3'
services:
apache:
container_name: myaneat_apache
image: webdevops/apache:ubuntu-16.04
environment:
WEB_DOCUMENT_ROOT: /var/www/public
WEB_ALIAS_DOMAIN: myan.localhost
WEB_PHP_SOCKET: php-fpm:9000
volumes: # Only shared dirs to apache (to be served)
- ./public:/var/www/public:cached
- ./storage:/var/www/storage:cached
networks:
- myaneat-network
ports:
- "80:80"
- "443:443"
php-fpm:
container_name: myaneat_php
image: jguyomard/laravel-php:7.3
volumes:
- ./:/var/www/
- ./ci:/var/www/ci:cached
- ./vendor:/var/www/vendor:delegated
- ./storage:/var/www/storage:delegated
- ./node_modules:/var/www/node_modules:cached
- ~/.ssh:/root/.ssh:cached
- ./composer.json:/var/www/composer.json
- ./composer.json:/var/www/composer.lock
- ~/.composer/cache:/root/.composer/cache:delegated
networks:
- myaneat-network
db:
container_name: myaneat_db
image: mariadb:10.2
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: myan
MYSQL_USER: myan
MYSQL_PASSWORD: secret
volumes:
- myaneat-data:/var/lib/mysql
networks:
- myaneat-network
ports:
- "33060:3306"
elasticsearch:
container_name: myaneat_es
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.1
restart: always
volumes:
- es-data:/usr/share/elasticsearch/data
networks:
- myaneat-network
ports:
- "9200:9200"
kibana:
image: docker.elastic.co/kibana/kibana:6.5.1
container_name: myaneat_kibana
environment:
- ./kibana.yml:/usr/share/kibana/config/kibana.yml
ports:
- "5601:5601"
networks:
- myaneat-network
networks:
myaneat-network:
driver: "bridge"
volumes:
myaneat-data:
driver: "local"
es-data:
driver: "local"
I am installing a new package running the following command.
docker-compose exec php-fpm composer require calebporzio/sushi
But only the composer.json is updated but not composer.lock. Also, the package is not downloaded into the vendor folder either. I was working before. Just out of the blue, this happens.
I tried the following:
docker-compose exec php-fpm composer clearcache
docker-compose exec php-fpm composer clear-cache
docker-compose exec php-fpm composer dump-autoload
docker-compose exec php-fpm composer update --lock
What is the possible root cause? How can I fix it?
You may try run update specific to the lock:
docker-compose exec php-fpm composer update --lock
This flag is documented here
As for the updating of .lock file, you may find info about it here, You're interesting in the last clause.
Running composer update will:
Check composer.json
Determine the latest versions to install based on your version specs
Install the latest versions
Update composer.lock to reflect the latest versions installed

Docker Laravel not loading assets

I have configure a docker compose file to run laravel with apache and mysql. The app builds fine but when i access to it i have this error loading the assets
This is my docker-compose file conf:
version: '3'
services:
#PHP Service
vma_web:
build:
context: .
dockerfile: Dockerfile
container_name: vma_web
restart: unless-stopped
env_file: '.env.prod'
tty: true
ports:
- "8250:80"
environment:
SERVICE_NAME: vma_web
SERVICE_TAGS: 1.0.0
networks:
- app-network
#MySQL Service
vma_mysql:
image: mysql:5.7
container_name: vma_mysql
restart: unless-stopped
tty: true
ports:
- "33061:3306"
environment:
MYSQL_DATABASE: school_back
MYSQL_ROOT_PASSWORD: epTfkgH9XakwN5mm
SERVICE_TAGS: 1.0.0
SERVICE_NAME: vma_mysql
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
And the dockerfile
FROM php:7.2-apache-stretch
RUN apt-get update
RUN apt-get install -y libpng-dev libxml2-dev nano zip unzip
RUN docker-php-ext-install mbstring gd zip pdo pdo_mysql
COPY vma.conf /etc/apache2/sites-available/000-default.conf
WORKDIR /var/www/html/vma
COPY . .
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
RUN chmod -R 777 bootstrap storage public routes/pages.php
RUN composer install
EXPOSE 80
What am i doing wrong ?
is something about permissions ?
is something about the ports ?

Resources