How can I change the Laravel Artisan CLI PHP version? - php

I posted a question about clearing the cache here
the problem was I can't clear cache after editing the .env file. That is still my real problem. (I can't reset the server and I cant use artisan cmds)
But this problem needs to be solved before I can solve that one:
I cannot run artisan commands. I have a shared hosting account where my environment PHP version is 7.14 the PHP artisan CLI is using the default PHP 5.4 so I cannot do: php artisan cache:clear etc
I have tried things like
$exitCode = Artisan::call('config:cache');
And...
$process = new Process('/opt/php71/lib artisan config:cache');
$process->run();
Keep in mind that my application works fine, and PHP version is 7.14 according to PHPINFO.
So how can I either get Laravel to clear its cache another way or get artisan to run using a specific PHP version?

where my environment PHP version is 7.14 the PHP artisan CLI is using the default PHP 5.4
No, artisan will use whatever version your environment is set to run – the shebang looks like this:
#!/usr/bin/env php
And if you're calling it like php artisan ... then the shebang isn't even used. In either case, you should adjust your path so that PHP 7.1 is called when you run php (i.e. the directory containing PHP 7.1 should come before the one containing 5.4) and it will work fine.

Related

Laravel Error: Erroneous data format for unserializing 'Symfony\Component\Routing\CompiledRoute'

I ran these commands: php artisan route:clear and php artisan cache:clear. Then I got this error on whatever I want to do: running artisan command, running composer command, rendering any view that worked just fine. Can not do anything at all.
I searched for the problem and seems that this has happened because of changing the php version from 7.4 to 7.3. Yes, I have done this about 10 days ago, now I am not able to resolve it and make it work again. I use Nginx and tried anything suggested on the web, but can not solve the problem. I had apache and could not solve it, I removed apache completely and installed nginx. Now any other project works fine with nginx, but only this project which I ran php artisan route:clear and php artisan cache:clear commands, has problem and displays this error on every action I want to do: Erroneous data format for unserializing 'Symfony\Component\Routing\CompiledRoute'.
How can I solve this problem?
I got this same error when I was experimenting with Laravel Envoy. I think I pulled the 7.0 version of Envoy onto of my Laravel 5.8 version app. The way to solve it for me was to clear out the bootstrap/cache directory of the app with the command rm -fr bootstrap/cache/* from the root Laravel directory. Once I did that I was able to use my application normally and all the artisan commands began working.

php artisan serve get cached or does not react while updating code in Laravel 5.5. After a restart, it works again each time

My IDE is phpstorm and running on WAMP Server. While coding, it does not show the expected response, always returns the previously requested response (In postman). Each time, I need to close 'php artisan serve' with CTRL+C and then run again to get the expected response.
I tried changing IDE, changing port but it does not work. Of course, I tired to save manually ( CTRL+S) but the problem persists.
I also tried the following commands:
php artisan cache:clear
php artisan config:clear
php artisan route:clear
composer dump
But the problem still persists.
The issue might be the composer command. Please, have a look on my setup in the Makefile:
run:
php artisan config:cache
php artisan config:clear
php artisan cache:clear
composer.phar dump-autoload -o
php artisan serve
And it's ready to go with a Laravel's "clean build".
Can you try with a diferent request tool, like doing a GET on your browser?
Or just create a new endpoint to test that. This way you make sure that changes are being saved.
I recommend you make tests to see if:
the problem is on your postman (a cache maybe?);
the problem is that your code isn't being saved;
the problem is on your local server (a persistent cache?);
My tip is: Try to eliminate the possible causes and you should achieve an answer.
Let´s try to make sure about above items and if them are ok, we check possible another ones.

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

PhpStorm + XAMPP not showing latest PHP version in command line

I am using OSX running on El Capitan and setting up PhpStorm and the Laravel environment has been a nightmare. I created a project setting up Composer and created it with laravel/laravel from the options menu.
As you can see in the screen shot, the PHP version says 5.6.31.. but if I type php -v in the command line. It gives me php 5.5 (as shown in the bottom left)
If I type php -v in the terminal I also get php 5.6.
which php returns me /usr/local/bin/php
I originally had a problem where PHP would not upgrade to 5.6.. but I managed to solve this with homebrew.
And if I use terminal and cd into the folder to run artisan key:generate and config:clear .. I am able to get the Laravel homepage to load (but typing this from the PhpStorm command line does not work).
My understanding is that the command line is pointing to the directory of PHP that came with my Mac? So how do I point it to the upgraded version? Or is the problem something else?
I think this is a strange problem and already a few people I have asked have not been able to solve it (also setting this up is all very new to me).
what I did is to set an alias on my ~/.bashrc to point php command to point to /Applications/XAMPP/bin/php
e.g. alias php="/Applications/XAMPP/bin/php"
in your case, you can use your XAMPP's full path to your php binary file as you might have different installation paths.
You should be able to add:
export PATH=/Applications/XAMPP/xamppfiles/bin/php5.6.31:$PATH
to your ~/.bash_profile (assuming you're running a bash shell). Then just run source ~/.bash_profile and it should all work.

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.

Categories