Install Imagick in Laravel Sail (Docker) - laravel

I am trying to install Imagick PHP Extension in Laravel Sail but I am failing to do so.
Details:
Laravel 9
PHP 8.2
In the Dockerfile (in directory docker/8.2) I added this snippet to the script:
RUN apt-get update; \ # Imagick extension apt-get install -y libmagickwand-dev; \ pecl install imagick; \ docker-php-ext-enable imagick; \ # Success true
Did run sail build and it runs the script without errors but it does not detect Imagick

Solved. I forgot to point to the published Dockerfile in docker-composer.yml. :/

Related

Using Laravel Sail on an existing Laravel application

Sail Version: 1.16.2
Laravel Version: 9.37
PHP Version: 8.1
Host operating system: macOS 12.3
Description:
I want to use Sail on my existing Laravel application.
As following to the documentation, i need to execute this command to install sail & other composer dependencies:
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php81-composer:latest \
composer install --ignore-platform-reqs
When i run it, everything is going well until composer install crashes with this error:
Install of google/apiclient-services failed
In Filesystem.php line 314: Could not delete /var/www/html/vendor/composer/cc83f9bf/googleapis-google-api-php-client-services-52b4942/src/OrgPolicyAPI:
Steps To Reproduce:
Install new laravel application
Delete vendor folder if you have one
Add "google/apiclient": "^2.12.6" to your composer.json
Execute the docker run command above
Error occurs
Can someone help me solving this?

Unable to run laravel command on docker with composer

I'm having some issues with running the laravel command on my docker container.
I use the php docker image and use the copy command for getting composer from the composer image. After that I've added composer to my $PATH variable and run the composer global require laravel/installer command.
After building the docker compose file and running it I open up the command line for my php image. In here I try to run the "laravel" command but get the following error: /bin/sh: laravel:not found.
Looking in the $HOME/.config/composer/vendor folder I see laravel here, so I think the installation is correct.
I might be completely wrong here or have made a dumb rookie mistake, so any help is greatly appreciated
Below here is my dockerfile:
FROM php:8.0.14-apache
RUN docker-php-ext-install pdo pdo_mysql
#apache
RUN a2enmod rewrite
#composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
#add composer to path
ENV PATH="$PATH:$HOME/usr/local/bin/composer"
RUN export PATH="$PATH:$HOME/.composer/vendor/bin"
#update
RUN apt-get update
RUN apt-get -y install nano
#add nodejs
RUN apt-get -y install nodejs npm
COPY . /var/www/html/
RUN npm install
#install laravel
RUN composer global require laravel/installer
You copy composer to /usr/local/bin/composer, but you add $HOME/usr/local/bin/composer to the path.
Also, RUN export ... doesn't do anything, because each RUN statement is run in a separate shell. So when the RUN command is done, the shell exits and the exported variable is lost.
Try this
FROM php:8.0.14-apache
RUN docker-php-ext-install pdo pdo_mysql
#apache
RUN a2enmod rewrite
#composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
#add composer to path
ENV PATH="$PATH:/usr/local/bin/composer"
#update
RUN apt-get update
RUN apt-get -y install nano
#add nodejs
RUN apt-get -y install nodejs npm
COPY . /var/www/html/
RUN npm install
#install laravel
RUN composer global require laravel/installer
I've added the "changed path" from the command composer global about to my ENV path and added /vendor/bin. I'm not sure if its bad practise to add something from the root folder to the $PATH variable.
So the complete line looks like this:
ENV PATH="$PATH:/root/.config/composer/vendor/bin"
By adding this line i'm able to run the laravel command

How do I get this to work in a docker environment - missing ext-zip extension

I am stuck with these errors for days and I have tried quite a couple of Dockerfile configurations.
Versions
PHP version: 7.3
Laravel version: ^6.2
Package version: ^3.1
Description
Exact errors
Problem 1
- Installation request for phpoffice/phpspreadsheet 1.11.0 -> satisfiable by phpoffice/phpspreadsheet[1.11.0].
- phpoffice/phpspreadsheet 1.11.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
Problem 2
- phpoffice/phpspreadsheet 1.11.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
- maatwebsite/excel 3.1.19 requires phpoffice/phpspreadsheet ^1.10 -> satisfiable by phpoffice/phpspreadsheet[1.11.0].
- Installation request for maatwebsite/excel 3.1.19 -> satisfiable by maatwebsite/excel[3.1.19].
To enable extensions, verify that they are enabled in your .ini files:
-
- /usr/local/etc/php/conf.d/docker-php-ext-bcmath.ini
- /usr/local/etc/php/conf.d/docker-php-ext-exif.ini
- /usr/local/etc/php/conf.d/docker-php-ext-gd.ini
- /usr/local/etc/php/conf.d/docker-php-ext-pcntl.ini
- /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini
- /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
My Dockerfile
FROM php:7.3-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
RUN apt-get update && \
apt-get install -y \
libzip-dev \
&& docker-php-ext-install zip
# 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 useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
WORKDIR /var/www
USER $user
# Run migration?
As I experienced, sometimes it is so confusing to install a php extension.
Fortunately there is an awesome repository(docker-php-extension-installer) for doing it painlessly:
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
RUN install-php-extensions zip
Also you can add any extensions without concerning about the dependencies.
I tried a number of solutions I found and none worked for me -- including this one. I had to resort to editing the php.ini inside of the docker container and specifying which extensions I wanted to use. I don't think it was a problem of extensions not being installed, but the php.ini was not being updated properly for some reason.
Here Is the article that helped me find php.ini
This was for the PHP:8.0.3-fpm-buster docker image.

E: Package 'mysql-client' has no installation candidate in php-fpm image build using docker compose

Im fairly new to docker and so im trying to learn more about it using a laravel project, im following this tutorial:
https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose
Ive adjusted the Dockerfile a bit from what the tutorial has but even the tutorial file causes the same result.
FROM php:7.3-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Install dependencies
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
apt-get update && apt-get install -y mysql-client \
RUN npm install -g npm
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo pdo_mysql
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Set working directory
WORKDIR /var/www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
But i keep getting the following error when i run docker-compose up -d:
E: Package 'mysql-client' has no installation candidate
ERROR: Service 'app' failed to build: The command '/bin/sh -c curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get update && apt-get install -y mysql-client nodejs build-essential vim git curl' returned a non-zero code: 100
Am i missing something?
I expected this to work since i am running apt-get update before installing mysql-client.
Thanks.
php:7.3-fpm now use Debian 10 (Buster) as its base image and Buster ships with MariaDB, so just replace mysql-client with mariadb-client should fix it.
If you still want to use the mysql client, it's called default-mysql-client now.
php:7.2-apache triggers the error as well, but I resolve it using php:7.2.18-apache
it worked for me: sudo apt-get update && apt-get install -y git curl libmcrypt-dev default-mysql-client
or alternatively apt-cache search mysql-server
find out your servers then sudo apt-get install default-mysql-server default-mysql-server-core mariadb-server-10.6 mariadb-server-core-10.6
in my case it was the above codes

How do I install composer in container of docker?

I am new at docker and docker-compose and I am developing a Laravel-project on docker and docker-compose with Laradock as following a tutorial(not sure whether It is a correct way or not to refer this situation though).
I want to install the composer in this environment to be able to use the composer command.
As a matter of fact, I wanted to do seeding to put data into DB that I made by php artisan make:migrate but this error appeared.
include(/var/www/laravel_practice/vendor/composer/../../database/seeds/AdminsTableSeeder.php): failed to open stream: No such file or directory
So I googled this script to find a solution that will solve the error then I found it.
It says, "Do composer dump-autoload and try seeding again", so I followed it then this error appeared.
bash: composer: command not found
Because I have not installed composer into docker-container.
My docker's condition is like this now.
・workspace
・mysql
・apache
・php-fpm
Since I have not installed the composer, I have to install it into docker-container to solve the problem, BUT I have no idea how to install it into docker-container.
So could anyone tell me how to install composer into docker-container?
Thank you.
here is the laradock/mysql/Dockerfile and laravelProject/docker-compose.yml.
ARG MYSQL_VERSION=5.7
FROM mysql:${MYSQL_VERSION}
LABEL maintainer="Mahmoud Zalt <mahmoud#zalt.me>"
#####################################
# Set Timezone
#####################################
ARG TZ=UTC
ENV TZ ${TZ}
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && chown -R mysql:root /var/lib/mysql/
COPY my.cnf /etc/mysql/conf.d/my.cnf
CMD ["mysqld"]
EXPOSE 3306
version: '2'
services:
db:
image: mysql:5.7
ports:
- "6603:3306"
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=true
- MYSQL_DATABASE=laravelProject
- LANG=C.UTF-8
volumes:
- db:/var/lib/mysql
command: mysqld --sql-mode=NO_ENGINE_SUBSTITUTION --character-set-server=utf8 --collation-server=utf8_unicode_ci
web:
image: arbiedev/php-nginx:7.1.8
ports:
- "8080:80"
volumes:
- ./www:/var/www
- ./nginx.conf:/etc/nginx/sites-enabled/default
volumes:
db:
You can build your own image and use it in your Docker compose file.
FROM php:7.2-alpine3.8
RUN apk update
RUN apk add bash
RUN apk add curl
# INSTALL COMPOSER
RUN curl -s https://getcomposer.org/installer | php
RUN alias composer='php composer.phar'
# INSTALL NGINX
RUN apk add nginx
I used the PHP alpine image as my base image because it's lightweight, so you might have to install other dependencies yourself. In your docker-compose file
web:
build: path/to/your/Dockerfile/directory
image: your-image-tag
ports:
- "8080:80"
volumes:
- ./www:/var/www
- ./nginx.conf:/etc/nginx/sites-enabled/default
You could do something like this:
FROM php:8.0.2-apache
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y mariadb-client libxml2-dev
RUN apt-get autoremove -y && apt-get autoclean
RUN docker-php-ext-install mysqli pdo pdo_mysql xml
COPY --from=composer /usr/bin/composer /usr/bin/composer
the argument COPY --from= should solve your problem.
FROM php:7.3-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
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'

Resources