Composer install fails over command line - composer-php

I seem to be able to connect to SSH on my CPanel and run the installer, however access to the "installer" fails, thus denying the installation of composer. Any ideas?
[mememigf#server188 home]$ wget https://getcomposer.org/installer
--2016-07-01 01:49:27-- https://getcomposer.org/installer
Resolving getcomposer.org... 87.98.253.108, 2001:41d0:a:7b19::2
Connecting to getcomposer.org|87.98.253.108|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 293630 (287K) [application/octet-stream]
installer: Permission denied
Cannot write to “installer” (Success).
[mememigf#server188 home]$

Sounds like there is already a file in your home directory with the name "installer" that you don't have permission to write to.
Test if that's the case using this command
ls -l | grep installer
The suggested installation method for composer is as follows
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Taken from the composer installation page
https://getcomposer.org/download/

Related

Laravel Sail "build path ./vendor/laravel/sail/runtimes/8.0 either does not exist, is not accessible, or is not a valid URL."

I'm using Laravel 8.x with Sail using PHP 8.0, recently, I actually messed up my compose.json file resulting in issues with the vendor, trying to recreate the project from scratch, I deleted the vendor folder.
Normally, docker-compose would build and create the /path/to/project/vendor/laravel/sail/runtimes/ directory with its appropriate content, but for some reason, I keep getting the following error:
ERROR: build path /path/to/project/vendor/laravel/sail/runtimes/8.0 either does not exist, is not accessible, or is not a valid URL.
I tried using docker system prune and deleting the existing containers manually through the Docker Desktop interface, and I even tried running it with docker-compose build --no-cache, I still get the same error.
Is there a way to fix this or should I just clone my project again and try to build it?
Note: I'm using an old Mac without the possibility of just manually running composer install so any of my interactions with the instance relies on the docker container working.
docker run --rm --interactive --tty --volume C:/path/to/project:/app composer install --ignore-platform-reqs --no-scripts
The standard procedure for setting up any Laravel project should be running composer install, so an inability to do so really ties one's hands here.
However, in this case, where the only way for me to run composer was through docker, I elected to use the laravel.build website to create a new project and copy the vendor folder over. Here's the script:
docker info > /dev/null 2>&1
# Ensure that Docker is running...
if [ $? -ne 0 ]; then
echo "Docker is not running."
exit 1
fi
docker run --rm \
-v $(pwd):/opt \
-w /opt \
laravelsail/php80-composer:latest \
bash -c "laravel new example-app && cd example-app && php ./artisan sail:install --with=mysql,redis,meilisearch,mailhog,selenium"
cd example-app
CYAN='\033[0;36m'
LIGHT_CYAN='\033[1;36m'
WHITE='\033[1;37m'
NC='\033[0m'
echo ""
if sudo -n true 2>/dev/null; then
sudo chown -R $USER: .
echo -e "${WHITE}Get started with:${NC} cd example-app && ./vendor/bin/sail up"
else
echo -e "${WHITE}Please provide your password so we can make some final adjustments to your application's permissions.${NC}"
echo ""
sudo chown -R $USER: .
echo ""
echo -e "${WHITE}Thank you! We hope you build something incredible. Dive in with:${NC} cd example-app && ./vendor/bin/sail up"
fi
After that, running ./vendor/bin/sail up -d && ./vendor/bin/sail composer install fixed the problem.

Envoy Laravel run forever

i'm using bitbucket pipeline to deploy and run some artisan command,
but there is a problem that make me headache, when artisan command failed, envoy show the error/Exception, but not continue to run next envoy task.it's keep show me the exception till i kill the php process in vps server (using kill/pkill command)
here is my envoy
#task('start_check_log', ['on' => 'web'])
cd /home/deployer/mywork/laravel/
nohup bash -c "php artisan serve --env=dusk.local 2>&1 &" && sleep 2
curl -vk http://localhost:8000 &
php artisan check_log
sudo kill $(sudo lsof -t -i:8000)
php artisan cache:clear
php artisan config:clear
#endtask
php artisan check_log just to check the log file, i want to check if error occurred, but when error comes up, envoy stuck on that error.
I've resolved this problem, this is just my stupid, I 've to add command pipe in other to envoy continue the task php artisan check_log && sleep 2 and the envoy continue the process

Cipher exception when deploying Laravel to Elastic Beanstalk

Ok I'm starting to lose my mind here. When I deploy my app to elastic beanstalk I get this error:
[2017-12-15 17:50:18] Tylercd100\LERN.CRITICAL: RuntimeException was thrown! The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.
To be clear I deploy my app source without dependencies installed and with APP_KEY not set, I'm leaving the dependency installation to elastic beanstalk which installs them during deployment.
In my aws .config file I have defined deployment commands as follows:
---
commands:
00init:
command: "sudo yum install gcc-c++"
01init:
command: "rm -f amazon-elasticache-cluster-client.so"
02init:
command: "wget https://s3.amazonaws.com/php-amazon-elasticache-cluster-client-7-1/amazon-elasticache-cluster-client.so"
03init:
command: "sudo mv amazon-elasticache-cluster-client.so /usr/lib64/php/7.1/modules/"
04init:
command: "echo \"extension=amazon-elasticache-cluster-client.so\" | sudo tee /etc/php-7.1.d/50-memcached.ini"
05init:
command: "sudo /etc/init.d/httpd restart"
container_commands:
00permissions:
command: "find * -type d -print0 | xargs -0 chmod 0755"
01permissions:
command: "find . -type f -print0 | xargs -0 chmod 0644"
02permissions:
command: "chmod -R 775 storage bootstrap/cache"
03cache:
command: "php artisan cache:clear"
04key:
command: "php artisan key:generate"
05cache:
command: "php artisan config:cache"
06cache:
command: "php artisan route:cache"
07optimize:
command: "php artisan optimize"
These commands are running during deployment to aws without any error.
When I go and check .env directly on the virtual machine the APP_KEY is set as it should be considering the commands above.
Yet I get the cipher error.
Assuming you set APP_KEY in elasticbeanstalk configuration page in dashboard, there are two things that I would like to point out.
1- When php artisan config:cache is run in container_commands, it caches file paths as /var/app/ondeck/... This causes runtime errors while laravel trying to access the cached files.
2- Cipher error occurs when laravel cannot access the APP_KEY value from your .env file. If a line like APP_KEY=${APP_KEY} exists in your .env file, that is the main cause of the error. You assume that APP_KEY value is going to be read from the environment configuration made in the dashboard. However, environment variables have not been set by the beanstalk yet somehow when your commands or container_commands are running. You can solve this issue my sourcing environment variables by yourself by including below command in your commands or files.
source /opt/elasticbeanstalk/support/envvars
e.g.
"/opt/elasticbeanstalk/hooks/appdeploy/post/91_config_cache.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
source /opt/elasticbeanstalk/support/envvars
echo "Running php artisan config:cache"
cd /var/app/current
php artisan config:cache
echo "Finished php artisan config:cache"

Laravel: file_put_contents() failed to open stream: Permission denied for Session folder

I am getting this issue for sessions even when I have given 777 and required user and group to the folders in storage.
ErrorException in Filesystem.php line 81: file_put_contents(/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec): failed to open stream: Permission denied
How can I get rid of this issue?
at HandleExceptions->handleError('2',
'file_put_contents(/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec):
failed to open stream: Permission denied',
'/var/www/html/business/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php',
'81', array('path' =>
'/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec',
'contents' =>
'a:5:{s:6:"_token";s:40:"Dyi8ML8zxaQJOEiVvqBpqk3noLDJTkIdqiC67qs9";s:9:"_previous";a:1:{s:3:"url";s:29:"http://XXXXX:8333";}s:22:"PHPDEBUGBAR_STACK_DATA";a:0:{}s:9:"_sf2_meta";a:3:{s:1:"u";i:1470895812;s:1:"c";i:1470895812;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}',
'lock' => true))
I had a problem like that and doing the following solved it for me
chmod -R gu+w storage
chmod -R guo+w storage
php artisan cache:clear
Got it from the answer here
if you try
chmod -R gu+w storage
chmod -R guo+w storage
php artisan cache:clear
and it still doesn't work.
you have two ways:
Disable your SELinux (i really don't recommend this way, unless you are on training or learning)
Configuring SELinux Policies for Apache Web Servers
i want to break down every steps for confirguring selinux policies
assumption: you've already installed all database like mysql, postgresql, or others. you've installed web server
install semanage with command "yum provides /usr/sbin/semanage"
install policycoreutils-python with command "yum install -y policycoreutils-python"
create policies:
a. sudo semanage fcontext -a -t httpd_sys_content_t "/var/www/html/webapp(/.*)?"
b. sudo semanage fcontext -a -t httpd_log_t "/var/www/html/webapp/logs(/.*)?"
c. sudo semanage fcontext -a -t httpd_cache_t "/var/www/html/webapp/cache(/.*)?"
Allowing ReadWrite Access:
a. sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/webapp/storage(/.*)?"
ACCESS YOUR WEBAPP
b. restorecon -Rv /var/www/html/webapp
Giving 777 to the folder session works for me.
chown -R www-data:www-data project_folder
sudo service apache2 reload
chmod -R gu+w storage
chmod -R guo+w storage
php artisan cache:clear
This worked for me for my laravel 8 application.
First run this command in your Laravel app folder
sudo composer update
After that run the following in order
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
sudo chmod -R 775 storage
sudo chmod -R 775 bootstrap/cache
run the following command
docker-compose exec <your webserver container name> sh OR bash(if it uses bash)
then
ls -l /var/www/storage/framework/views/ | grep 7369b96b4 (this number is part of the file name you are trying to see it permission) you will see something like this -rw-r--r--
the run
chmod 777 var/www/storage/framework/views/7369b96b436adb2109e56fbb8ed7ba805568c985.php(the full file name)
reload the page
Goto project root folder and run the following command
sudo chmod -R 777 storage/* bootstrap/cache/*
Go to the session folder and make the permission like 755. It's worked for me.

How install composer-asset-plugin while 'vagrant up'?

I generate config by puphpet.com. I want to install composer-asset-plugin when I first run vagrant up.
I wrote simple script puphpet\files\exec-once\composer-asset-plugin.sh, which tries to do that:
#!/usr/bin/bash
echo "Installing Composer Asset Plugin"
composer global require "fxp/composer-asset-plugin:~1.0.0"
It install plugin in /root/.composer, so when I connect via vagrant ssh (under user vagrant) and try to use Composer I get a error, which means that plugin is absent because Composer really absent in /home/vagrant/.composer. After I install plugin malualy Composer works fine.
I tried to change user from root to vagrant before plugin instaling:
#!/usr/bin/bash
echo "Installing Composer Asset Plugin"
expect -c 'set timeout 3600; spawn su - vagrant; expect "Password:" {send -- "vagrant\r";}; exit 0'
composer global require fxp/composer-asset-plugin:~1.0.0;
It hangs after command expect. What I do wrong?
The following might help:
# Install Composer
if [ ! -f /usr/local/bin/composer ]; then
cd /tmp
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
fi
# Install necessary plugin
sudo -H -u vagrant bash -c "composer global require fxp/composer-asset-plugin:~1.0.0"
In this case the command will be executed in vagrant user context and his home will be used.

Resources