Composer install error when run in shell script - php

I have shell script for that is executed before start of the application.
This is the shell script
#!/bin/sh
/usr/local/bin/composer install
/usr/local/bin/php artisan optimize
/usr/local/bin/php artisan key:generate
when i try to execute this script i get this error
Running composer as root/super user is highly discouraged as packages, plugins and scripts cannot always be trusted
[Symfony\Component\Console\Exception\CommandNotFoundException]
" is not defined.
Did you mean this?
install
The composer executable is installed and works when called from the command line

The trick is putting it like this
#!/bin/sh
`/usr/local/bin/composer install`
`/usr/local/bin/php artisan optimize`
`/usr/local/bin/php artisan key:generate`

Related

/usr/bin/env: php: No such file or directory with AWS Elastic Beanstalk

When I deploy a Symfony application to AWS Elastic Beanstalk, in a PHP environment (PHP 8.1 running on 64bit Amazon Linux 2/3.4.1), the following error appears with Composer:
----------------------------------------
/var/log/eb-engine.log
----------------------------------------
[...]
Executing script cache:clear [OK]
Executing script assets:install public [OK]
Executing script requirements-checker [KO]
[KO]
Script requirements-checker returned with error code 127
!! /usr/bin/env: php: No such file or directory
!!
Script #auto-scripts was called via post-install-cmd
But when I connect to SSH, the command composer install works correctly:
cd /var/app/staging/
sudo su -- webapp -c "/usr/local/composer.phar install"
Executing script cache:clear [OK]
Executing script assets:install public [OK]
Executing script requirements-checker [OK]
vendor/symfony/requirements-checker/bin/requirements-checker:
#!/usr/bin/env php
<?php
include('requirements-checker.php');
I don't understand why AWS Elastic Beanstalk don't know "#!/usr/bin/env php" while deploying?
Can you help me?
Thanks.
I managed to solve the problem by skipping Composer scripts execution with:
.ebextensions/01_php.config
option_settings:
aws:elasticbeanstalk:container:php:phpini:
composer_options: --no-scripts
Then, I run composer install again but with scripts execution:
.ebextensions/02_app.config
[...]
05_composer_install:
command: |
runuser -u webapp -- \
composer.phar install --no-dev --optimize-autoloader

php artisan migrate nothing to migrate error

I am trying to install this package on my server after installing everything when I try to migrate with php artisan migrate it tells me there is nothing to migrate. Also the migration table is not there. here is what I did:
php composer.phar require igaster/laravel_cities
change in providers app.php
Igaster\LaravelCities\GeoServiceProvider::class,
Ran this script
mkdir storage/geo
cd storage/geo
wget http://download.geonames.org/export/dump/allCountries.zip && unzip allCountries.zip && rm allCountries.zip
wget http://download.geonames.org/export/dump/hierarchy.zip && unzip hierarchy.zip && rm hierarchy.zip
Now when I run php artisan migrate it tells me there is nothing to migrate
I am not sure if this is because I have php composer.phar instead of composer?
Try php artisan config:cache then retype php artisan migrate - Hope this helpfull...
Try running:
php artisan vendor:publish --provider="Igaster\LaravelCities\GeoServiceProvider"
And then run the migration
php artisan migrate
php composer.phar is identical to composer so thats not the issue.
If migration file not showing you likely need to run
php artisan vendor:publish
Copy vendor/igaster/laravel_cities/src/migrations folder contents to database\migrations folder, then run php artisan migrate. Sometimes publishing vendor resources doesn't work for me too and I dive into the source of the package then to make them work.

Run `php composer.phar dump-autoload` from code - Laravel 5.4

I'm trying to run these command from code, but having some trouble finding out how.
php composer.phar dump-autoload -o
php composer.phar require 'vendor/some-package'
php composer.phar update 'vendor/some-package'
EDIT
Forgot to mention, that I don't want to use the exec function because of potential risk and the fact that's blocked on most servers by default.
I did manage to download the .phar file from code, but not how to run these commands. I'm trying to build a friendly as possible solution and don't want use to dumpautoload manually after installing something etc.
Code to download
$composerPath = base_path('composer.phar');
copy('https://getcomposer.org/composer.phar', $composerPath);
I have found a working solution. You can call these command with Symphony's process component.
$process = new \Symfony\Component\Process\Process('php composer.phar autoload-dump');
$process->setWorkingDirectory(base_path());
$process->run();
Worked it out into a class:
https://codeneverlied.com/using-composer-from-code/
you can runcomposer global require "laravel/envoy=~1.0" to bring Laravel's envoy package into your project. With envoy you can write something like
#servers(['localhost' => '127.0.0.1'])
#task('foo', ['on' => 'localhost'])
php composer.phar dump-autoload -o
php composer.phar require 'vendor/some-package'
php composer.phar update 'vendor/some-package'
#endtask
but at some point the server will have to run envoy run task, this is also guessing on your question. You may more elaborate more on what you are trying to actually do.
cd /tmp
wget https://getcomposer.org/composer.phar
chmod 755 composer.phar
php composer.phar --version

How do I remove old artisan command from Kernel in Laravel 5

I have created some Command files into my Laravel Application. Laravel version is 5.2. I set command like: get:email in the Command file. Also call the Command file into Kernel.php. After that I can see the artisan command list by typing the command php artisan list. as like as below:
//output
get:email
And I changed the command title get:email to get-bq:email. When I run the command php artisan get-bq:email -- its working nicely. Also I can see the list by typing the command php artisan list::
//output
get-bq:email
Issue / Problem: Both commands are working. But I won't to work with both of them. I have done the following things:
modified command file as well as command
run composer dump-autoload -o
run composer update
remove vendor and storage folder then run composer update again.
Still the old command is working into my system.
What I want: How May I remove my old commands from my Laravel(5.2) application?
Run these commands:
php artisan cache:clear
php artisan config:clear
These commands will clear app cache and config cache and recreate it.
I've had the same problem recently.
Repoeatedly tried
php artisan cache:clear
php artisan config:clear
and the cached Kernal command wouldn't clear.
In desperation i killed the queue worker terminal and restarted the queue with the command
php artisan queue:work
The issue stopped.

Installation issue in laravel bundle with commands

I am new to Laravel. I have never used artisan commands. Now I'm trying to install a bundle, but it says to run this commands: php artisan bundle:install charisma and `php artisan bundle:publish. I don't know how to run these commands and WHERE to run these commands for installation. Can anyone please tell me step by step how and where these commands work.
You should run those commands at the terminal.
Let's suppose you have Laravel installed on documents/projects/test.
cd documents/projects/test
php artisan bundle:install charisma

Categories