Trouble using sandbox of symfony - php

I'm new to symfony and I am trying to run a simple command on the command line but I get an error message.
When I try to execute the command:
d:\new_xam\xampp\htdocs\sf_sandbox_1_2\sf_sandbox>symfony propel:build-model "
I get the error:
'php.exe' is not recognized as an
internal or external command,operable
program or batch file.
Can anybody help me?

This is a fairly common issue on Windows systems for people new to Symfony and/or PHP. It seems to be an issue with the PHP path. See here: http://forum.symfony-project.org/index.php/m/44895/?srch=php.exe+command#msg_44895

Can you try to use the real path for PHP?
i.e.,
"C:\Program Files\PHP\PHP.exe" symfony propel:build-model
At your Symfony directory.

You should be able to prefix everything with "php".
So instead of symfony propel:build-model you can do php symfony propel:build-model.

Related

VS Code can not reach Symfony\Component and Symfony\Bundle

I am trying to create a simple symfony project.
I run this on console:
composer create-project symfony/skeleton myProjectName
php -S 127.0.0.1:8000 -t myProjectName/public
Project succesfully run at localhost:8000. However, when I begin to inspect the code, I realized VS Code editor is indicating "Undefined type" error in projectDirectory/src/Kernel.php file. Do you have any ideas why this happens and any suggestions towards solution?
I use PHP v7.4.32 and Symfony 5.4 for development. My helper extentions are PHP Intelephense v1.8.2 and PHP IntelliSense v1.0.11.
projectDirectory/src/Kernel.php
The Error
Since it runs succesfully on browser, I dubted that the classes exist somewhere but the VSCode could not solve the relative paths. Then, I tried a couple of extensions. Installation of PHP v1.22.11089 created by DEVSENSE and PHP Namespace Resolver v1.1.9 created by Mehedi Hassan has solved the problem.

How to clear cache automatically on symfony?

I'm trying to create a new route like this:
#Route("/restaurant/", name="restaurant")
#Route("/work/", name="work")
#return Response
But when I visit /work/symfony in my browser, it returns this message:
Unable to parse file "/Applications/XAMPP/xamppfiles/htdocs/apps/symfony/vendor/sensio/framework-extra-bundle/src/DependencyInjection/../Resources/config/annotations.xml": The XML file "/Applications/XAMPP/xamppfiles/htdocs/apps/symfony/vendor/sensio/framework-extra-bundle/src/DependencyInjection/../Resources/config/annotations.xml" is not valid.
When I clear the cache with the following command, it works:
php bin/console cache:clear -v
How can I fix this, without need to clear my cache all the time?
I found the solution by starting a symfony server instead of using XAMPP by running : symfony server:start as simple as that ...

Symfony messenger can't consume messages

Few weeks ago I set up a Message system with Symfony Messenger and it worked great.
Today I wanted to create new object through message, so I went to my server and type the command to consume message
First I had this result
$ bin/console messenger:consume-messages amqp_notifications
/usr/bin/env: ‘php\r’: No such file or directory
It never happened before with my files, and I never changed the line ending or encoding of my file sin PHPstorm.
I tried to use $ php bin/console messenger:consume-messages amqp_notifications
but then I had this error.
Attempted to load class "AMQPConnection" from the global namespace.
Did you forget a "use" statement?
Pretty weird, because I have have the php-amqp ext installed as you can see on the screenshot of my phpinfo
I didn't change anything in my Message class or Handler.
Also, I tried to call new AMQPConnection() on a random action, just to try, and I didn't get the error.
I'm completely lost with this error this time, as everything is installed.
I use PHP 7.3.1 and symfony Messenger 4.2.2
It seems your second issue was already solved by ccKep on his comment.
The first one is that the specific shebang line #!/usr/bin/env php executes the first php found in the $PATH. So if you already have uninstalled it, which seems the case, or it has a symbolic link to another php version, you can get a wrong result.
Tries to check what is inside the $PATH and replace the PHP path for the correct one. You might get the place running which php.

MongoDb not found in ZF2 controller

I have few controllers in my zf2 project which work perfectly in the browser using apache and via command line.
However, I recently installed MongoDb so I can store some data using the driver found in (http://php.net/manual/en/set.mongodb.php)
My issue is, when I try to access the driver via controller + browser, I get the following message error in my apache logs :
PHP Fatal error: Class 'MongoDb\Driver\Manager' not found.
'MongoDb\Driver\Manager' is the namespace for this Driver.
If I execute some other controllers via command line, MongoDb works correctly.
Does anyone know why is this happening? I cannot see the issue :(
Thank you
I found that my php.ini was pointing to mongo.so instead of mongodb.so
That fixed the issue
http://php.net/manual/en/mongodb.installation.manual.php
Thank you for your help

sf2 php command-line issues for deployment #OVH

Hi there,
I am facing a quite annoying issue.
Situation
I would like to deploy symfony2 application in production on mutualized servers of OVH (pro). I got shell access (ssh), my database works fine and my files are online.
Issue
I cannot manage to make any php command line work. That is, for all major commandline:
- updating web directory : php app/console assets:install web
- updating databases: php app/console doctrine:schema:update --force
- downloading composer: php -r "eval('?>'.file_get_contents('http://getcomposer.org/installer'));"
-etc...
I get parse errors such as:
syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in
or
Error in argument 1, char 2: option not found r (that one was for composer download)
it seems a pretty common pb, however I couldn't manage to fix it :/
Any hints welcome!
Thanks in advance,
Cheers
On ovh, you can choose witch php is used by altering the cmd line :
/usr/local/bin/php.ORIG.5_4 -> php.ORIG.5.4.6
/usr/local/bin/php.ORIG.5_3 -> php.ORIG.5.3.16
/usr/local/bin/php.ORIG.5_2 -> php.ORIG.5.2.17
/usr/local/bin/php -> php.ORIG.4
I had a simular problem with deploying symfony2 project. I`m not sure that this is the case here, but my problem was with the cache. For some of the symfony2 console commands it uses cached paths, and if you have changed the location of the project this could cause the problem. It uses a cached path when trying to delete the cache :D so my suggestion is to go and delete manually the cache i app/cache.
Hope i helped

Categories