Symfony can not find config_.yml - php

I have a symfony project of which I can't clear the cache of all of a sudden. I only made some changes to twig. I always clean the cache with the following command.
php bin/console cache:clear --no-warmup -e
After executing the command I get the following message:
The file "C:\xampp\htdocs\postcodezoeker\app/config/config_.yml" does not exist.
After searching on Google I found some other post on Stackoverflow. They pointed out to use the following command which executes with no errors.
php bin/console cache:clear --env=prod
But when I go to webpage I get the following error:
Fatal error: Cannot redeclare class Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser in C:\xampp\htdocs\postcodezoeker\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser.php on line 24
I created a clean new project and tried to execute the commands and still got the same thing. Reinstalling XAMPP did not do the trick and a newer version of symfony neither.
I hope you guys can help me out. I use PHP version 5.6.15 and Symfony 3.4

The call you are using does not provide any information about the environment:
php bin/console cache:clear --no-warmup -e
...forces Symfony to run using the environment (empty string). The service configuration is read from the file config_.yml afterwards, which (according to that error message) does not exist.
Either provide a value for the environment (for example using -e prod) or don't use -e after all.

Related

Symfony 4.1 cache not being created

I've recently upgraded Symfony to the new Symfony4.1. As seen over here we no longer need to setup file permissions anymore. I ran the command:
php bin/console cache:warmup
And no errors came while running that. However when I try and view the website. I get the following error.
Uncaught RuntimeException: Unable to write in the cache directory (/var/www/mywebsite.com/var/cache/prod)\n in /var/www/mywebsite.com/var/bootstrap.php.cache
Obviously this means that the new feature of Symfony4.1 is not working for me. Any idea what might be causing this?
Give permissions to cache directory with bash command:
sudo chmod -R a+rw /path/to/cache_directory/

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

Can't use shell_exec for laravel artisan command in live server

I am using shell_exec command to run my artisan commands in the background. But when I run shell_exec in production server.
The route code as follows
Route::get('/test/exec', function () {
echo shell_exec('php ../artisan migrate:status 2>&1; echo $?');
});
it throws me error as follows.
PHP Fatal error: Cannot redeclare class Illuminate\Support\Traits\Macroable in /var/www/production/bootstrap/cache/compiled.php on line 6109 255
But when I run the same command in my local I got the output.
Laravel versin - 5.1.46
php version - PHP 5.5.9
os version - ubuntu
14.04
These are same on both servers. Where things went wrong. Please, some one helps me with this.
For this error try to run the following commands:
php artisan clear-compiled
php artisan optimize
this should regenerate compiled.php file.
As for executing artisan commands from within your code there are better ways than using shell_exec - for example using Laravel build in support for programmatically executing commands
The error
% Cannot redeclare class %
also occurs when you inject a class that has the same name as the one you are actively editing/modifying.
In your case, please make sure that you have not injected a class with the name "Macroable" elsewhere. If you have, make sure that the namespace is unique.

"Could not open input file: bin/console" Error comes when try to Run the Symfony Application

$ cd my_project_name/
$ php bin/console server:run
When I added following commands and tried to run my symfony application this error comes,
"Error:Could not open input file: bin/console"
As #chapay and #cered says we can use this command instead.
php app/console server:run
Its Symfony 2 command and the one I had problems with is Symfony 3 command. And I found out few other times also this issue comes.
for sometimes we can replace 'bin' with 'app'. like,
php bin/console doctrine:mapping:import --force AcmeBlogBundle xml
php app/console doctrine:mapping:import --force AcmeBlogBundle xml
And if not we can choose the correct command in 'http://symfony.com/doc/' site by changing the version.
The file app/console was moved to bin/console in Symfony 3.
So instead of running
php bin/console server:run #valid in Symfony 3
Try running:
php app/console server:run #valid in Symfony 2
Before to use this command make sure you installed dependencies from composer.json
Run:
composer update
also make sure you are under the project folder (cd your_project), else it gives you the same error ( Could not open input file: bin/console )
It works when I use start instead of run : php app/console server:start
If you use git - you should check if bin/console is added to repository. Some versions may have .gitignore in bin/ folder, so bin/console may work on your local PC and not work on server because of it.
In Symfony 6, somehow the bin folder is still ignored from git, even though it should be there.
You can check my other answer here: https://stackoverflow.com/a/73958225/9675721
create a fresh new symfony application
copy the /bin folder
if it is missing, copy the /config/packages folder as well
add these lines to .gitignore:
!/bin/
!/config/packages/*

Could not open input file: app/console (Symfony 2)

Recently I started working with Symfony2. Unfortunately the php app/console commands doesn't work at both my MAMP server as Vagrant server (MAC OSX). I tried to make a bundle with the following command
php app/console generate:bundle --namespace=Vendor/NameBundle
and also tried to fix a problem with
php app/console assets:install web
And both commands returned the following in my terminal:
Could not open input file: app/console
Does someone know how to fix this problem? I AM working at my project directory like: mac/applications/mamp/htdocs/project but it is still not working. I also tried to reinstall a new symfony project but that was not a fix.
I guess my php isn't working at all in my terminal...
So the problem was the version number. Symfony version 3.0 is available now so if you're do not selecting a version number at your project install it will automaticly install version 3.0 instead of 2.7. The new command is:
$ php bin/console generate:bundle --namespace=Vendor/NameBundle
instead of
$ php app/console generate:bundle --namespace=Vendor/NameBundle
Add php to your Path Environment Variable so that you can execute php from the command line
(You may need to restart your computer after step 1) From the command line type: php -version to test whether php has successfully been added to your pathenvironment variable
Depending on the version of Symfony you have, you will need to execute either php app/console or php bin/console where console is a php file inside the app or bin directories in your project root. To check which command to use, look into your project directories, if bin/ directory is present then execute php bin/console as console.php is located in that directory.
From the command line, cd into your project root directory and run the appropriate command as mentioned above. To check whether you are in the correct directory, run the dir command, if all your Symfony project directories: app/, bin/, src/, vendors/ etc. are displayed, then the php app/console (bin/console) ... command should run successfully.
or just create a new 2.8.x symfony project using:
symfony new yourAppName 2.8
instead of:
symfony new yourAppName
(which would create a new 3.x symfony project)
in this way you will be able to use:
php app/console

Categories