Prepend directory to $PATH in Centos 6 - php

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.

Related

How can I change the Laravel Artisan CLI PHP version?

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.

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

Composer PHP script running old PHP version causing syntax errors?

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.

PHP artisan command has no effect

I created a project in Laravel 5, on localhost. It works perfectly. I uploaded it on Godaddy using FileZilla and tried to run php artisan command. It didn't work. Just to be sure if there's a problem with composer or Laravel, I created a new Laravel project with same name and tried php artisan command it worked. Then I tried copying just app and database folder into newly created project and tried php artisan command, it stopped working just like before.
Can anyone tell me what is the problem here.
I tried running composer install command in project directory as per one suggestion on stackoveflow, didn't work for me
There probably is something in the app/ or database/ directory that's causing some fatal error and your php configuration is set to not display any errors.
Execute php --ini to find out which ini file is used and then configure it to show errors. After saving the ini file, run php artisan again and fix the error.

Cannot execute Laravel Artisan commands on shared hosting

I uploaded laravel app to shared hosting into a domain folder, and made .htaccess so that it redirects requests to laravel's /public folder.
I now want to execute artisan commands through ssh. I tried just typing php artisan list in laravel's root folder on the shared host, but it gives me this output (it prints it in html, but I just copied the exeption for readability):
ErrorException thrown with message "Undefined index: argv"
Stacktrace:
#3 ErrorException in /home5/petophob/public_html/ees-aleksandarnikolic/vendor/symfony/console/Symfony/Component/Console/Input/ArgvInput.php:57
#2 Illuminate\Exception\Handler:handleError in /home5/petophob/public_html/ees-aleksandarnikolic/vendor/symfony/console/Symfony/Component/Console/Input/ArgvInput.php:57
#1 Symfony\Component\Console\Input\ArgvInput:__construct in /home5/petophob/public_html/ees-aleksandarnikolic/vendor/symfony/console/Symfony/Component/Console/Application.php:114
#0 Symfony\Component\Console\Application:run in /home5/petophob/public_html/ees-aleksandarnikolic/artisan:58
What can I do to make it work? I'm on Bluehost, if that's relevant.
Thanks,
Petar
You can try call it: php-cli artisan list
If it will not be working you should probably contact bluehost support it is about server settings.
if artisan commands are not working inside your server, you can execute the PHP scripts via PHP's command-line interface (CLI). inside a server, the server pilot installs various versions of the PHP version. to determine what version of PHP you are using, you can simply render a php_info() page.
to execute artisan command you can run CLI base commands based on your version. if you use php version 7.3 you can use
php7.3-cli artisan list
php7.3-cli artisan migrate
php7.3-cli artisan db:seed
PHP syntax will be changed based on your current version what you have to do is just change the version of your command phpVERSION-cli example php8.0-cli

Categories