I generate php files with Apache Thrift
thrift -out / --gen php:nsglobal=src\\Application\\Package\\Thrift package.thrift
The above command generates code in the following path src/Application/Package/Thrift and set src\Application\Package\Thrift for namespace but I use Psr-4 (with composer) in my project we know src as App so namespace should be App\Application\Package\Thrift
my project structure
src |
| Application |
| | Package |
| | | Thrift
I went generate files in Thrift folder with namespace same as following:
App\Application\Package\Thrift
Do you have an idea to solve this problem?
I try add namespace php App.Application.Package to IDL file and run following command:
thrift -out /src --gen php /data/service.thrift
But it create extra App folder => src/App/Application/Package/Thrift
Declare the namespace in the IDL file:
namespace php Whatever.You.Want
Full example can be found here
Also, remove the nsglobal option and just do
thrift -out / --gen php package.thrift
i need App in namespace and src in folder name
If you need the folder being different from what the namespace says, consider writing a shell script (or batch file) to move the generated files to where you need them to be after Thrift code generation.
PS: Not sure if specifying a root folder as the output target is such a great idea at all.
Related
I have installed Laravel before and I deleted that folder, and now after several months I install Laravel installer but when I write the command laravel new in Windows Powershell it returns this error.
_ _
| | | |
| | __ _ _ __ __ ___ _____| |
| | / _` | '__/ _` \ \ / / _ \ |
| |___| (_| | | | (_| |\ V / __/ |
|______\__,_|_| \__,_| \_/ \___|_|
In NewCommand.php line 153:
Application already exists!
new [--dev] [--jet] [-f|--force] [--] [<name>]
I created project. But I deleted it. When I create project again with the same name, I encountered this problem. After, I runned this command:
laravel new project-name --force
Only, I added --force end of command.
I have faced the same issue while creating a new project on the latest Laravel through Composer but didn't find any solution and at the last, I tried to create a Laravel project by the following command and it's working as expected.
composer create-project --prefer-dist laravel/laravel ProjectName
or, you should remove that folder and let it be created by command as follows:
laravel new ProjectName
Explanation:
As I get the following error.
_ _
| | | |
| | __ _ _ __ __ ___ _____| |
| | / _` | '__/ _` \ \ / / _ \ |
| |___| (_| | | | (_| |\ V / __/ |
|______\__,_|_| \__,_| \_/ \___|_|
In NewCommand.php line 184:
Application already exists!
new [--dev] [--jet] [--stack [STACK]] [--teams] [-f|--force] [--] [<name>]
I tried to figure out this issue and found a function that is placed under %appdata%\Composer\vendor\laravel\installer\src\NewCommand.php on line 184 as follows:
/**
* Verify that the application does not already exist.
*
* #param string $directory
* #return void
*/
protected function verifyApplicationDoesntExist($directory)
{
if ((is_dir($directory) || is_file($directory)) && $directory != getcwd()) {
throw new RuntimeException('Application already exists!');
}
}
here verifyApplicationDoesntExist function is checking that the application folder you are trying to create has existed or not, it's not checking the application folder's size so it doesn't matter if the folder is empty or not. so due to code like that, the composer thinks application already been created that's why it throws an error like your application already exists.
To tackle this issue, you just need to delete your empty project folder and create it by command laravel new ProjectName and that will create project folder itself without giving any error like Application already exist!.
If you're having problems, delete the parent directory. There's a chance there are hidden folders scattered across it.
Otherwise you can try creating a new folder in another directory and running Laravel new in it.
The folder location doesn't matter, it just generates content of a Laravel app.
Once you've created a new folder, you can move all the files across to your other folder with the following:
mv laravel/* /var/app/myfolderlocation
It happened to me too.
Maybe you created your laravel project directly in your linux shell instead of making it through the power shell "indirect" interface to your linux machine.
In my case I solved it following the next steps:
1.- Deleting the laravel-project directly in the ubuntu linux shell. rm -R laravel-project.
2.- Then, through power shell i executed again the curl command in the "sublinux" terminal like this: curl -s https://laravel.build/example-app | bash
Then the process started without problems, creating all the laravel files and docker images and containers.
All the tutorials followed by me direct to the microsoft step by step tutorial,
https://learn.microsoft.com/en-us/windows/wsl/install-win10
but it hidden some key steps that you can find in this amazing video:
https://www.youtube.com/watch?v=rr6AngDpgnM, thank you dogcomp for take the time that need some begginers (and not so beginners, like me).
change your Newcommand.php file
with github Newcommand.php file
https://github.com/laravel/installer/blob/master/src/NewCommand.php
The error means that the directory already exists.
Do the following to get around.
Go to a temp directory.
Execute the laravel new project-name there.
Copy the contents of the newly created directory to the actual project directory.
Though this might be late but i think it might help someone in difficult times. This error is related to the folder already in existence
Here's how i was able solve this issue:
i closed the vscode holding reference to the folder i intend installing laravel in. then
cd .. to come out from the folder.
next up. laravel new [target-folder-name] -f
and problem solved.
I'm hoping this would help someone.
While previously you would need to first create the directory then cd the console there and run laravel new, but currently you have to:
First ensure the my-project directory does NOT exist.
Run laravel new my-project to create the directory for you.
Wait for composer install command (which will auto-run) to finish.
For me in the end, it just logs Application ready! Build something amazing.
But finally, maybe go further and edit the auto-generated ./my-project/.env file, for example, set DB_DATABASE to something other than my_project or change APP_URL=http://my-project.test to APP_URL=http://localhost address.
When I run the php artisan optimize command with the --force option, my application instance doesn't work at http://localhost/project/public/invoice/create.
However, it does work at http://localhost:8000/invoice/create when I run php artisan serve.
Why isn't http://localhost/project/public/invoice/create working? How can I rollback?
The Laravel file structure is set up:
public
|-- css
| -- app.css
|-- js
| -- app.js
| -- some-other.js
|-- index.php
These files referenced as follows:
http://localhost/css/app.css
http://localhost/js/app.js
http://localhost/index.php OR http://localhost/
The /public directory is the base and contains the index.php file, which is the entry point for all requests entering your application and configures autoloading. This directory also houses your assets such as images, JavaScript, and CSS.
I'm using the Encore/Webpack in my Symfony project, but Im having troubles with the installation.
I'm following the official guide: Link to official guide
My project folder:
projectname
---/app
---/assets
/css
/global.scss
/js
/main.js
...
---/node_modules
/.bin
/encore
...
---/web
/build
etc
I was following
Create a new file called webpack.config.js at the root of your
project.
It looks like:
projectname
...
webpack.config.js
I filled it with the example code. Afterwards I wanted to 'build' the assets with the command encore dev on path: projectname\node_modules\.bin
When I do this, I get the following error code:
Running webpack ...
No configuration file found and no output filename configured via CLI option.
A configuration file could be named 'webpack.config.js' in the current directory.
Use --help to display the CLI options.
I have no idea what I'm doing wrong. When I move the webpack.config.js to the .bin folder.. that part works, but than the build doesn't work, because it wants to install the files into .../.bin/build/ which is not correct. I want it into projectname/build like the example.
try this commend it's work for me
install webpack-notifier#^1.6.0 --save-dev
I've a project I try to run it but I am getting a following error:
PHP Fatal error: Class 'Dotenv' not found in `/home/maras/Documents/eCodile/debtorcare/server/bootstrap/app.php on line 5`
I'm struggling with this error during trying to execute a php artisan start I tried to reinstall all dependencies but it didn't work.
I've just tried to run some commands based on other similar problems I found in the Internet but any of them worked. I tried ie:
composer require vlucas/phpdotenv --prefer-dist
Ive got a file .env.
This is a file where error is placed:
<?php
require_once __DIR__.'/../vendor/autoload.php';
Dotenv::makeMutable();
Dotenv::load(__DIR__.'/../');
Dotenv::makeImmutable();
/*
|--------------------------------------------------------------------------
| 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__.'/../')
);
Is it possible the error is connected with wrong configuration of a database or phpMyAdmin? Or maybe Ive got .env placed in wrong place?
I try to run this project in development.
I guess the cwd was changed while you're running the command. make sure that composer.json, .env, "vendor/autoload.php" can be loaded from the project root.
maybe you need to run "composer dump-autoload" after the Dotenv installation,
As c9s suggests, Check to make sure that you are loading an existing vendor/autoload.php with something like:
$vendor_audoload = __DIR__.'/../vendor/autoload.php';
print $vendor_audoload;
if(file_exists($vendor_audoload)){
print " Exists!";
} else {
print " Does not exist!";
}
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