Composer PHP script running old PHP version causing syntax errors? - php

I am using composer's post-update-cmd with Laravel. My code is written in PHP 7, I think composer's script call is running an old version because I am getting syntax error on executing php artisan ide-helper:generate. Running the command manually in terminal does not trigger any errors.
How do I specify or configure composer's php to use a specific php path? Using #php, does not seem to work as "artisan" as the path becomes invalid:
You made a reference to a non-existent script #php artisan
ide-helper:generate
Here's my composer.json:
...
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan ide-helper:generate",
"php artisan ide-helper:meta",
"php artisan optimize"
]
...

I was receiving a similar error (my particular error was with the final script, #php artisan optimize)
Composer was already using PHP 7.1 correctly. Running composer selfupdate fixed this error.

So composer is somehow running the old php even though my ~/.bash_profile is pointing php to a new version.
To prove it, executing php -v was showing PHP 7. Whereas executing composer exec 'php -v' was showing php 5.6.
So after being bothered by this for a few days, I finally tried this. Apparently, the order of ~/.bash_profile matters.
I changed this:
alias composer="php /usr/local/bin/composer.phar"
export PATH=/Applications/MAMP/bin/php/php7.0.8/bin:$PATH
To:
export PATH=/Applications/MAMP/bin/php/php7.0.8/bin:$PATH
alias composer="php /usr/local/bin/composer.phar"
and reload the profile by executing source ~/.bash_profile
Now composer exec 'php -v' shows php 7!

First check the version of your php.
by entering this command to your command prompt(cmd): php -v
If it's showing the wrong version there's a conflict happening.
find the conflicting app by finding the source of your php (cmd): php --ini
the prompt will now tell you where the file is coming from.
You can then uninstall the app that's hosting the old php file. Then your system should automatically use the newer php.

Related

PHP artisan error: CLI stops working after every reboot

I installed Laravel through composer using PHP 7.3.25 through xampp v3.2.4. I first noticed the problem: cli stopped working, during
php artisan serve
I scoured SO and the internet for possible fixes. Going through these commands fixed this problem for me (or so I thought):
composer update --no-scripts
php artisan clear-compiled
composer dump-autoload
But every time I turn on the PC, I get the same error and have to follow these steps to make it work. Antivirus did not have anything to do with it (I checked). Is there any way to fix this without having to completely reinstall everything?
Its ist important to understant few points related to following queue:restart command.
The queue workers' age confirmed that they restarting in response to that.
php artisan queue:restart
Ref: https://laravel.com/docs/8.x/queues#queue-workers-and-deployment

laravel artisan use of undefined constant STDIN - assumed 'STDIN' infinite loop

I am using laravel 5.6 and have the problem, when I use the command "php artisan vendor:publish" in the console, I get the following error:
[ERROR] Use of undefined constant STDIN - assumed 'STDIN'
Which provider or tag's files would you like to publish?
[0] Publish files from all providers and tags listed below
[1] Provider: Intervention\Image\ImageServiceProviderLaravel5
The problem is, that these messages appear infinite, until I close the console or after a long time it kills the process.
I looked for this issue on google, but only found the problem with stdin and the difference is, that the people who had that problem, didn't call artisan in the command line interface, but directly in a php script.
The same problem appears when I use "php artisan migrate"
I was getting the issue mentioned above while running artisan command to seed the db tables: Artisan::call('db:seed', [...]) while in production.
Adding the --force flag fixed my issue
Artisan::call('db:seed', [
'--force' => true
])
Make sure you use --force flag if you are in production.
I have found a solution for the problem:
I had to add the following line to the artisan file (in the laravel directory).
define('STDIN',fopen("php://stdin","r"));
Now it works.
It's still strange, because normally artisan should work out-of-the-box, without the need to change anything.
Add
if(! defined('STDIN')) define('STDIN', fopen("php://stdin","r"));
to your index.php file. I tried adding this to artisan file but didn't work but placing it in index.php did the trick.
My PHP version is v. 7.4 on Ubuntu 18.04
This problem is caused by application environment.
Change application env to local or add --force parameter after artisan command.
One thing to check is to ensure you are running the correct version of PHP for the version of Laravel.
php -v will show the php version
I was surprised to see that for me, the CLI version of PHP (which is what artisan uses) was really old.
I didn't realize my shared host had many different versions of PHP installed.
I was able to run artisan commands by using the command corresponding to the PHP version I needed to use: php7.1 artisan migrate

Prepend directory to $PATH in Centos 6

I'm looking to globally prepend a directory to my $PATH variable in Centos6. Currently it is as follows:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
I would like it to become:
/opt/plesk/php/7.0/bin/php/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
I've already made a modification which changes the directory correctly for when I run "which php" but that doesn't seem to satisfy scripts that I execute which call php.
EDIT:
Why do I need to do this?
I am running a script called Composer (found here: https://getcomposer.org/), it is used for PHP development and then runs a command automatically which is "php artisan clear-compiled" (used in Laravel 5 projects).
When running the command "php artisan clear-compiled" myself I get no errors because it uses php7 which is configured for the root account. When the script runs it it errors because it is trying to execute using PHP 5.4 which isn't supported by artisan.

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.

Why is my php -v version different from phpinfo()?

I looked at some of the similar questions and they have a similar problem except their php -v version is the one that is higher than the phpinfo() reported version. For when I call phpinfo() from php file it shows 5.5.25 which is correct. In the terminal through ssh I run php -v and it gives me 5.4.43. I'm using GoDaddy hosting and on cPanel I have it set to 5.5. I'm using Composer and Laravel. When I create a new Laravel project it gives me this error:
[~/public_html]$ laravel new blog
Crafting application...
> php -r "copy('.env.example', '.env');"
> php artisan clear-compiled
Script php artisan clear-compiled handling the post-install-cmd event returned with an error
[RuntimeException]
Error Output:
run-script [--dev] [--no-dev] [-l|--list] [script] [args1] ... [argsN]
Application ready! Build something amazing.
You need to use a different path to get to the right version of the command line PHP.
Use
which -a php
To get the paths to the available versions of PHP, then use the full pathname.
For example
/usr/bin/php5

Categories