I want to change my Laravel 8 project but I run into an issue when I use this command: php artisan app:name new_name
The error is:
There are no commands defined in the "app" namespace.
I went through some solutions proposed in Stack Overflow, Github and other forums, but nothing seems to solve the issue.
Thanks in advance for your help!
Run php artisan list to see all the commands available
There is none app:name
To change the name of your project edit your .env and modify APP_NAME
go to .env file
open .env file in any code editor
find at APP-NAME = "" in .env file
edit APP-NAME = "Your Project Name"
put your desired name in "" (double quotes)
save .env file
restart your server
I think it will be work.
Thanks
// go to .env file change your app name example below
APP_NAME=type your project name here
Got to .env file at the root of you project and update APP_NAME="Your app name"
Also php artisan app:name new_name doesn't exist. You can do php artisan list to see all available artisan commands.
I have successfully install Laravel with Sail, the app is just fine, I can run it using sail up. however I am unable to migrate the database, everytime I run sail artisan migrate the following error thrown.
There is no existing directory at "/home/dariel/www/2021/nsmart/storage/logs" and it could not be created: Permission denied
at vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:172
168▕ set_error_handler([$this, 'customErrorHandler']);
169▕ $status = mkdir($dir, 0777, true);
170▕ restore_error_handler();
171▕ if (false === $status && !is_dir($dir)) {
➜ 172▕ throw new \UnexpectedValueException(sprintf('There is no existing directory at "%s" and it could not be created: '.$this->errorMessage, $dir));
173▕ }
174▕ }
175▕ $this->dirCreated = true;
176▕ }
+10 vendor frames
11 [internal]:0
Illuminate\Foundation\Bootstrap\HandleExceptions::handleException()
I am stuck at this point, any help would be appreciated. thanks in advance.
You can try this
php artisan route:clear;
php artisan config:clear;
php artisan cache:clear;
sail artisan migrate;
As the error states: There is no existing directory at /home/dariel/www/2021/nsmart/storage/logs Permission denied. So you have to run mkdir /home/dariel/www/2021/nsmart/storage/logs and done...
Remember to have storage folder accesible for the process running your artisan command, it needs to use any folder inside storage.
And, if I am not wrong, sail up will give you an error, so that is why it is trying to do something in the logs folder.
Ia m trying to set up Snipe IT on Windows server 2016 (VM) . I stack on part where i need to generate key.
When i execute php artisan key:generate i get following error.I checked ".env" file and I think everything is correct. I tried with composer install and update but same error acours...
Does anyone now how to fix this issue ?
Many thanks in advance
https://i.stack.imgur.com/vUmBk.png
Do you mean to generate application key?
'key' => env('APP_KEY', 'SomeRandomString') in file app.php
if you mean it then executes this command php artisan key:generate
With xampp I made a virtual host named leeromgeving.dev. But when I enter this in my bar its shows this.
It worked before, I don't know what is causing this. If I need to provide some code. Please inform me.
Thanks for the answers but unfortunately none of them worked.
This is what I get now after typing this in
Try Following Steps
-> delete .env file
-> copy .env.example .env
-> php artisan key:generate
-> remove env() in 'key' in config/app.php
or See https://laracasts.com/discuss/channels/laravel/the-only-supported-ciphers-are-aes-128-cbc-and-aes-256-cbc-with-the-correct-key-lengths
you have to insert the APP_KEY in your env file, use this command to generate a new Application key
php artisan key:generate
I'm trying out the PHP micro Framework Lumen (from Laravel).
One of my first steps was to look into the .env.example file and make a copy of it to have my .env file. There is a variable APP_KEY just like there is in Laravel. Now I tried out the simple command php artisan key:generate to get my new key But I ran into the following error message:
[InvalidArgumentException] There are no commands defined in the "key"
namespace.
Does some one know how I can generate keys for Lumen?
Update with solution
So I found my favorite solution for this problem. On the command line (Linux) I run php -r "echo md5(uniqid()).\"\n\";" what gives me something like this 7142720170cef01171fd4af26ef17c93.
If you are going to use Lumen more often, you may want to create an alias in your .bashrc, which is located in your home directory /home/USERNAME. To do so, you can open the file with nano ~/.bashrc or vi ~/.bashrc and copy the following alias at the end of the file, alias phpkey='php -r "echo md5(uniqid()).\"\n\";"'. Now you can use the command phpkey which will give you a 32 character long random string :)
The Laravel command is fairly simple. It just generates a random 32 character long string. You can do the same in Lumen. Just temporarily add a route like this:
$router->get('/key', function() {
return \Illuminate\Support\Str::random(32);
});
Then go to /key in your browser and copy paste the key into your .env file.
Afterwards remove the route.
Obviously you could also use some random string generator online. Like this one
Firstly, you have to register your key generator command, put this Lumen Key Generator Commands to app/Console/Commands/KeyGenerateCommand.php. To make this command available in artisan, change app\Console\Kernel.php:
/**
* The Artisan commands provided by your application.
*
* #var array
*/
protected $commands = [
'App\Console\Commands\KeyGenerateCommand',
];
After that, configure your application so that Illuminate\Config\Repository instance has app.key value. To do this, change bootstrap/app.php:
<?php
require_once __DIR__.'/../vendor/autoload.php';
Dotenv::load(__DIR__.'/../');
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/
$app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../')
);
$app->configure('app');
After that, copy your .env.example file to .env:
cp .env.example .env
Ignore this step if you already use .env file.
Enjoy you key:generate command via:
php artisan key:generate
Edit
You may use Lumen Generator. It covers so much commands you are missing from Laravel.
Simply use PHP CLI. Run this from your local or a remote command line to generate a random 32-character Lumen APP_KEY:
php -r "echo bin2hex(random_bytes(16));"
Output: bae48aba23b3e4395b7f1b484dd25192
Works with PHP 7.x on Mac and Windows.
An easy solution is just running PHP code from the terminal (without using tinker, because that is not available with Lumen):
php -r "require 'vendor/autoload.php'; echo str_random(32).PHP_EOL;"
It uses Laravel's Str::random() function that makes use of the secure random_bytes() function.
For me the easiest way to generate a Lumen key is typing on console one of these commands:
date | md5
date | md5sum
or
openssl rand -base64 24
depending of your environment. In my case, I aways use date | md5 on mac
The APP_KEY generation is a step of development process (I don't think that creating temporarily routes is a practical way to do it). The function str_random can help us, but this function is part of Laravel/Lunmen framework.
I recommend running tinker
php artisan tinker
and then run the function
>>> str_random(32)
The result is the key you're looking for.
=> "y3DLxnEczGWGN4CKUdk1S5GbMumU2dfH"
To generate key and use laravel command you need to install one package. The details are as below:
You have to install package composer require flipbox/lumen-generator
You have to add $app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class); into bootstrap/app.php file.
Link: https://github.com/flipboxstudio/lumen-generator
All I do on mac is execute this command in the terminal:
date | md5 | pbcopy
This copies the value into the clipboard and so you can easily paste the key into the .env file.
I have used these commands:
php -r \"copy('.env.example', '.env');\"
php -r "echo password_hash(uniqid(), PASSWORD_BCRYPT).\"\n\";"
The command generates a key similar to this:
$2y$10$jb3kw/vUANyzZ4ncMa4rwuR09qldQ2OjX8PGrVB5dIlSnUAPCGjFe
This answer was inspired by #thomas-venturini 's update to the question. Here's a bash script that takes care of creating .env and updating it with an APP_KEY using the aforementioned PHP command and the UNIX sed command:
#!/usr/bin/env bash
function generate_app_key {
php -r "echo md5(uniqid()).\"\n\";"
}
APP_KEY=$(generate_app_key)
sed -e s/APP_KEY=.*$/APP_KEY=${APP_KEY}/g .env.example > .env
Hope someone finds this useful.
Run php -a to start up interactive php playground.
Then run echo substr(md5(rand()), 0, 32); to generate a 32 character string.
You can then copy/paste into the .env file.
1.Open your terminal setup file:
vim ~/.zshrc
2.Create an alias for generating random strings:
# Lumen Key Generate
alias lumen-key="php -r \"require 'vendor/autoload.php'; echo base64_encode(str_random(32)).PHP_EOL;\""
3.Get a key whenever you need:
~/your-lumen-project via 🐘 v7.3.0
➜ lumen-key
VkxTYWZZSnhVNVEzRThXelBGZVJDVGZVYTNTcm9peHY=
You can also remove the third step by adding the key directly in .env using PHP.
[Flipbox\LumenGenerator]
Fix error: there are no comands defined...
[boostrap/app] Check if you register the Flipbox\LumenGenerator after return $app. If so move the Service provider register before return app...
/**
* Configure extra LARAVEL commands to a lumen app
* Check avaliable commands in git: flipboxstudio lumen-generator
*/
if($app->environment() !== 'production'){
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);
}
return $app;
Lumen 8.0 / flipbox/lumen-generator 8.2
It Worked 100%
Simply install the flipbox/lumen-generator package
composer require flipbox/lumen-generator.
Inside your bootstrap/app.php file, add:
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);
Then after you can able to run php artisan commands,
more info: https://github.com/flipboxstudio/lumen-generator