laravel 7 artisan key:generate not working - php

when i run php artisan key:generate in cmd it's return
file_get_contents(/project/positiv/core/vendor/psy//.env): failed to open stream: No such file or directory
at
/project/positiv/core/vendor/laravel/framework/src/Illuminate/Foundation/Console/KeyGenerateCommand.php:96
{
file_put_contents($this->laravel->environmentFilePath(), preg_replace(
$this->keyReplacementPattern(),
'APP_KEY='.$key,
file_get_contents($this->laravel->environmentFilePath())
));
}
I am trying to generate APP_KEY!!!

At first generate APP_KEY with the command php artisan key:generate --show. It will print contents on your terminal which you can copy and paste wherever you want. In this case APP_KEY=value on your .env file.
Generated Key format will be something like base64:xxxxxxxxxxxxxxxxxxxxxxx.

It seems that you are trying to run artisan command outside the project.
Make sure your terminal is targeting the exact project you want to trigger

Related

php artisan serve not generating url (localhost:8000) in right directory

I completed upgrades from laravel 5 to laravel 8.
But my php artisan serve is not working.
I mean when i type php artisan serve and type enter then we should get an output showing some localhost link.
But for me it is not doing that
C:\Users\kr php artisan serve
C:\Users\kr
go to the .env file and change localhost to 127.0.0.1

how to set Log rotate in laravel?

Right now I'm using a single log file, but there is requirement to make it daily , but for the current date, the file name must be laravel.log
laravel-2020-08-30.log
laravel-2020-08-31.log
laravel-202-009-01.log -> the current date must be laravel.log
`
Is it possible to get the logs daily, but named like this?
laravel.log
While the older (up to a week) are named like this:
laravel-2020-08-30.log
You can try given solution for you problem.
Update your .env file.
LOG_CHANNEL=daily
then you can run following this command on your terminal inside project root directory.
php artisan config:clear && php artisan cache:clear && php artisan config:cache
Now you can check your storage folder inside logs directory with following name conversion.
For ex:
laravel-2020-09-01.log

Get all Laravel artisan commands for interface

When you use php artisan in the command line you get a list of all commands. Are there any opportunity to get all Laravel artisan commands programmatically? I need it for example to use it in a select field in the interface.
To get all command objects:
\Artisan::all()
To get all command names:
array_keys(\Artisan::all())
use Illuminate\Contracts\Console\Kernel;
...
$commands = resolve(Kernel::class)->all();
Use shell-exec command.
http://php.net/manual/en/function.shell-exec.php
$output = shell_exec('php artisan');
echo $output;
if I understand the query correctly, you can use CLI (eg bash in debian) to:
&& for individual calls - each subsequent call will be made after the previous performance, eg:
php artisan migrate:fresh && php artisan fixtures:up && php artisan db:seed && php artisan serv
aliases entered in .bash_profile
alias migrate = "php artisan migrate"
and using command migrate in Laravel project.
info: https://gist.github.com/JeffreyWay/5542264
You can put them in your routes like this:
Route::get('/foo', function()
{
$exitCode = Artisan::call('command:name', ['--option' => 'foo']);
//
});
https://laravel.com/docs/5.0/artisan#calling-commands-outside-of-cli

file_put_contents(C:\storage\framework\views/27f511f5644086daa68b2cf835bf49f5148aba43.php): failed to open stream: No such file or directory

so i keep getting this error on my live server but not on my local host, everything works normal on my localhost but when i deploy my website on online server it keep giving me this error
file_put_contents(C:\appname\storage\framework\views/27f511f5644086daa68b2cf835bf49f5148aba43.php): failed to open stream: No such file or directory
i tried php artisan config:cache but nothing really worked
I suppose your issue is due to the Laravel Configuration Caching.I suggest you
Remove the configuration cache file
Flush the application cache
Create a cache file for faster configuration loading
To do this, run the following Artisan commands on your command line
php artisan config:clear
php artisan cache:clear
php artisan config:cache
Where you don't have access to the command line on your server, you can programmatically execute commands like this:
Route::get('/clear-cache', function() {
$exitCode = Artisan::call('config:clear');
$exitCode = Artisan::call('cache:clear');
$exitCode = Artisan::call('config:cache');
return 'DONE'; //Return anything
});
I hope this is helpful.
I'm going to guess that you have the wrong path being used, so try this to ensure that regardless of the server, you will have the right path:
$path = dirname(__FILE__);
file_put_contents($path.DIRECTORY_SEPARATOR.'27f511f5644086daa68b2cf835bf49f5148aba43.php');
This assumes that you are trying to write to the same folder as the code file that is running this.
You can also use the following to determine exactly what the path is on each server:
echo getcwd();
Looks like your storage/ directory is not writable. Laravel requires that directory to be writable.
If you're on linux/mac, run this
chmod 0755 storage/ -R
Hope that helps.
Try and use next command "php artisan cache:clear" will help you to clear cache for app

How to execute "php artisan migrate" and other Laravel commands in remote server?

I'm using Laravel 4.2 in remote server and I want to execute Laravel commands php artisan migrate but I don't know how.
You can ssh to the server and perform the command, you can add your servers public key to the remote server to do this without a password. I made a bash script with the following code which I can then execute manually via command line or from a program, lets say I call it myscript.sh with the following code
ssh root#127.0.0.1 << EOF
cd /var/www/app/;
php artisan migrate --force; // force prevents artisan from asking for a yes/no on production
exit;
EOF
now I can write 'sh myscript.sh' and it will run migrations on the remote server.
For the completeness of this article, you do this with Windows host using PS remote (enable first) then...
$Username = "{domain}\{domain account}"
$PasswordSS = ConvertTo-SecureString '{domain account password}' -AsPlainText -Force
$Cred = New-Object System.management.Automation.PSCredential $Username,$PasswordSS
Invoke-Command -ComputerName {server name} -ScriptBlock { cd d:\wwwroot\{website};php artisan migrate } -Credential $Cred
This will return the result to your local machine.
I use this in VSTS release deployments all the time.
The preferred way to do this:
ssh into your server (for example, username root & server ip 1.1.1.1: ssh root#1.1.1.1).
go to your project folder (for example: cd /var/....)
run the command php artisan migrate.
Original post (not the best way):
You can setup a cronjob like this:
* * * * * /usr/bin/php /var/www/app/artisan schedule:run
This will run every minute and run the migration.
You can change this to everything you want.
If you want to open a url what while be excecuting the command.
Use this code:
Artisan::call('migrate');
Hope this works!
With Mac terminal
Step 1
sh root#your.ip.address e.g 181.6.41.221
Step 2
Enter your password
Step 3
cd /home/admin/web/yourdomain.com/public_html
Step 4 Laravel command:
"php artisan migrate"
Without the "quote"
Ask your host for your IP address and Password if not known by you.
The solution to this problem could be running once a php code (on the server) like this:
<?php
// installation.php file
echo exec('php /var/www/laravel-app/artisan migrate:install');
and than you need to visit installation.php in your browser.
After migration you should remove the installation file, so nobody can execute it again

Categories