I have a symfony 3.3 application deployed to a shared hosting, when accessing any url of the application i got this error:
[2018-01-17 21:54:24] request.CRITICAL: Uncaught PHP Exception
Symfony\Component\Config\Exception\FileLoaderLoadException:
"[Semantical Error] The annotation
"#Sensio\Bundle\FrameworkExtraBundle\Configuration\Route" in class
AppBundle\Controller\ConventionAccommodationController does not exist,
or could not be auto-loaded in
/usr/home/convenciones.bookingarea.com/web/src/AppBundle/Controller/
(which is being imported from
"/usr/home/convenciones.bookingarea.com/web/app/config/routing.yml").
Make sure annotations are enabled." at
/usr/home/convenciones.bookingarea.com/web/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php
line 168 {"exception":"[object]
(Symfony\Component\Config\Exception\FileLoaderLoadException(code:
0): [Semantical Error] The annotation
\"#Sensio\Bundle\FrameworkExtraBundle\Configuration\Route\" in
class AppBundle\Controller\ConventionAccommodationController does
not exist, or could not be auto-loaded in
/usr/home/convenciones.bookingarea.com/web/src/AppBundle/Controller/
(which is being imported from
\"/usr/home/convenciones.bookingarea.com/web/app/config/routing.yml\").
Make sure annotations are enabled. at
/usr/home/convenciones.bookingarea.com/web/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php:168,
Doctrine\Common\Annotations\AnnotationException(code: 0):
[Semantical Error] The annotation
\"#Sensio\Bundle\FrameworkExtraBundle\Configuration\Route\" in
class AppBundle\Controller\ConventionAccommodationController does
not exist, or could not be auto-loaded. at
/usr/home/convenciones.bookingarea.com/web/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:54)"}
[]
Be aware that i am not able to execute composer.phar in the shared machine so i have to launch install and dump-autoload commands at my local machine and rsync vendor and var/bootstrap.php.cache of my machine with the production server directory.
This code and configuration works without problems in local develop machines and a staging server at Rackspace but throws the FileLoaderLoadException in the shared hosting for production.
I have disabled opcache and apc in the production server to discard php accelerator issues. That change do not solve the issue.
#app/config/routing.yml
app:
resource: '#AppBundle/Controller/'
type: annotation
#src/AppBundle/Controller/ConventionAccommodationController
<?php
namespace AppBundle\Controller;
use AppBundle\Entity\Sala;
use AppBundle\Entity\Hotel;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
.....
$ ls vendor/sensio/framework-extra-bundle/Configuration/
Cache.php Method.php Security.php
ConfigurationAnnotation.php ParamConverter.php Template.php
ConfigurationInterface.php Route.php
thanks a lot any clue welcomed.
I have just managed to solve this with composer clearcache followed by composer update.
Related
I'm having autowiring issues within symfony since I have updated my Docker to the latest version.
I am not entirely sure of the causality here but certainly, my issues started appearing only after updating my docker. Since this was the case I obviously tried to revert back to a previous docker version but still had the same issues as on the new build. That's why I am doubtful of the causality.
I'm now on: Docker version 3.5.2 with Docker Engine v20.10.7
docker-engine config is the unchanged config:
{
"registry-mirrors": [],
"insecure-registries": [],
"debug": false,
"experimental": false,
"features": {
"buildkit": true
},
"builder": {
"gc": {
"enabled": true,
"defaultKeepStorage": "20GB"
}
}
}
when I started my first project I had an issue with the composer not reading my lib-folder. This was solved as described below but it might provide some more insight, context and things I have checked/done
At first my mind went to this Windows env variable. Alas, it was set so it was not the problem.
Secondly, my mind went to file ownership or file permissions but also not the problem. Everything in my containers was owned by root and had rwx permissions.
Thirdly I thought it might be because of the new WSL2 backend I had to install. Until the day of the update I had still been running on the Hyper-V backend. Luckily there is a setting in docker where you can switch off the use of WSL-2 and revert to Hyper-V but this was also not the solution to my problem.
My composer.json looked like this:
"autoload": {
"classmap": [
"scripts/composer/ScriptHandler.php",
"lib/",
...
],
"psr-4": {
...
}
},
Everything but (some) files of lib were present in my autoload_classmap.php
After fiddling about for too long I finally tried the following and suddenly my problems on my first project were gone
"autoload": {
"classmap": [
"scripts/composer/ScriptHandler.php",
"lib/*",
...
],
"psr-4": {
...
}
},
I still don't understand why the first one should not work. It has worked until this thursday since the infamous update.
Now on to the second project and I really can't figure out what's going on and I'm at a loss for words. My colleagues can't seem to figure out what's wrong either. This second project is something more recent so not loading a classmap anymore and everything follows PSR-4 standards.
This is the autoload part of the composer.json:
"autoload": {
"psr-4": {
"App\\": "src/",
"Project\\": "scripts/"
}
},
This is my services.yaml (These are just the standard symfony settings AFAIK):
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{Entity,Migrations,Tests,Kernel.php}'
This is my docker PHP container:
php:
container_name: "${DOCKER_PROJECT_NAME}_php"
environment:
COLUMNS: 80
PHP_FPM_GROUP: wodby
PHP_FPM_USER: wodby
PHP_SENDMAIL_PATH: "/usr/sbin/sendmail -t -i -S mailhog:1025"
PHP_DEFAULT_CHARSET: 'utf-8'
PHP_DATE_TIMEZONE: 'UTC'
PHP_UPLOAD_MAX_FILESIZE: '10M'
PHP_POST_MAX_SIZE: '10M'
PHP_DISPLAY_ERRORS: 'On'
PHP_DISPLAY_STARTUP_ERRORS: 'On'
PHP_MAX_EXECUTION_TIME: '30000'
PHP_MAX_INPUT_TIME: '60'
PHP_MAX_INPUT_VARS: '2000'
PHP_ERROR_REPORTING: 'E_ALL'
PHP_LOG_ERRORS: 'On'
PHP_LOG_ERRORS_MAX_LEN: '0'
PHP_MEMORY_LIMIT: '512M'
PHP_SESSION_GC_MAXLIFETIME: '700000'
PHP_REALPATH_CACHE_SIZE: '4096K'
PHP_REALPATH_CACHE_TTL: '3600'
PHP_XHPROF: $PROFILING_ENABLED
env_file:
- .env
image: "wodby/php:7.4-dev-4.16.2"
volumes:
- "./:/var/www/html"
## For php profiler traces
- "files:/mnt/files"
On startup I am getting the following Runtime Exception:
Cannot autowire service "App\Form\Wizard\DaysOffType": argument "$daycareTransformer" of method "__construct()" references class "App\Form\DaycareTransformer" but no such service exists.
This class is not new, it's been in code for 2 years. It's in the right folder and the namespacing is correct. Also the src folder is included in the autoload_psr4.php.
The DaycareTransformer that "can't be found" is located in src/Form under the namespace App\Form as per psr4 namespace convention
<?php
namespace App\Form;
use App\Entity\Daycare;
use App\Service\DaycareService;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
class DaycareTransformer implements DataTransformerInterface
{
private $daycareService;
public function __construct(DaycareService $daycareService)
{
$this->daycareService = $daycareService;
}
...
}
There have not been any recent changes to this code. Not to the DaysOffType which has the DaycareTransformer injected and not to the DaycareTransformer.
I am the only person having these issues as I am the only one who runs Docker on a Windows machine. Production and QA environments are all up and running so there is no structural problem in the code.
It could be because the project running symphony in this case was locate at Windows partition (C: or D: or whatever inside your window) and not Linux distro.
If you are using WSL (most likely), you should always store Linux related project inside your distro (Ubuntu in my case, I store it it ~/...). You should not store Linux related project in /mnt/... when using WSL.
When I said "Linux related" I mean whatever project usually want to run on Linux environment, or using docker
Don't know if this could solve it for others because there could be a wide range of reason for this problem. But this is how I solve mine.
We've got the same problem on a Windows machine with Docker and Symfony 5.x.
We continued to work on this machine, but we changed our configuration.
For example, for your error I would use the following config.
Cannot autowire service "App\Form\Wizard\DaysOffType": argument "$daycareTransformer" of method "__construct()" references class "App\Form\DaycareTransformer" but no such service exists.
config/services.yml or config/services_dev.yml
services:
App\Form\DaycareTransformer: ~
We defined all the required classes from our errors and it solved our problem. But it solved problem only for one URL instead of all. You need to check each your routes or classes that use Symfony's autowire.
Unfortunately, the solution like declaration of resources didn't for us. We had to define all the required classes from our errors.
services:
App\DataTransformer\:
resource: '../src/DataTransformer/'
Don't redefined your classes that have already defined in your config, because it replaces your configuration and may make other errors.
You can do it in config/services.yml and commit it or you can use config/service_dev.yml and don't commit it if you haven't use this config before. In the second way you also can change .gitignore and add there the filename.
# Ignore changes for the file and don't track it.
config/services_dev.yml
WARNING! If you still have problems with it define all the required classes in services.yml instead of two or more config files.
We don't have this problem on Linux and MacOS machines.
In a Symfony 5.1.8 project I updated the httplug bundle to version 1.19.0.
It is mentioned in the changelog:
ConfiguredClientsStrategy no longer implements
EventSubscriberInterface, this has been moved to
ConfiguredClientsStrategyListener to avoid initializing the strategy
on every request.
That results in an error in In
EventDispatcher.php line 270
Failed to create closure from callable: class 'Http\HttplugBundle\Discovery\ConfiguredClientsStrategy' does not have a method 'onEvent'
I had the same issue on Symfony 4.4.16, and I had to manually remove the old cache to fix it on production:
rm -rf var/cache/prod && bin/console cache:clear
I am trying to configure the bundle from : https://symfony.com/doc/master/bundles/DoctrineFixturesBundle/index.html
and when I try to run the command :
$ php bin/console doctrine:fixtures:load
getting error:
In LoadDataFixturesDoctrineCommand.php line 95:
Could not find any fixture services to load.
You need to update (app/config/services.yml)
services:
resource: '../../src/DataFixtures/*'
https://symfony.com/doc/master/bundles/DoctrineFixturesBundle/index.html
Other problem is here in to the above tutorial
// src/DataFixtures/AppFixtures.php
namespace App\DataFixtures;
name space should be :
namespace DataFixtures;
Problem
I'm trying to setup a custom directory structure
for some shared classes in my Symfony project. I
want to create a custom folder in the root of my
project and I want to use the Symfony auto-load
feature to automatically register services from
that folder.
So I added a custom services namespace to the
services.yaml file:
# src ./config/services.yaml
services:
...
TestNamespace\:
resource: '../TestNamespace/*'
...
And I added an empty class in the custom folder:
# src ./TestNamespace/TestClass.php
namespace TestNamespace;
class TestClass
{
}
When I run the app I get the following error:
(1/2) InvalidArgumentException
Expected to find class "TestNamespace\TestClass" in file
"/path/to/ClassLoadErrorDemo/demo/TestNamespace/TestClass.php"
while importing services from resource
"../TestNamespace/*", but it was not found! Check the
namespace prefix used with the resource.
(2/2) FileLoaderLoadException
Expected to find class "TestNamespace\TestClass" in file
"/path/to/ClassLoadErrorDemo/demo/TestNamespace/TestClass.php" while
importing services from resource "../TestNamespace/*", but it was not
found! Check the namespace prefix used with the resource in
/path/to/ClassLoadErrorDemo/demo/config/services.yaml (which is loaded
in resource "/path/to/ClassLoadErrorDemo/demo/config/services.yaml").
I double checked the paths, namespace and the class
name multiple times and everything seems fine and I
don't understand why I still get the error.
Controllers in the ./src folder seem to load fine.
What am I doing wrong here?
Steps to reproduce
I created a demo repo to isolate the problem.
git clone https://github.com/smoelker/SymfonyClassLoadErrorDemo.git
cd SymfonyClassLoadErrorDemo/demo
composer install
mv TestNamespace/TestClass.php_ TestNamespace/TestClass.php
php bin/console server:start
Update your composer.json autoload setup
{
[...]
"autoload": {
"psr-4": {
"TestNamespace\\": "TestNamespace/",
"": "src/"
}
},
[...]
}
After run: composer dump-autoload and try again.
composer dump-autoload --classmap-authoritative will only work if your src directory is present at the time you run the command.
This can be an issue with multi-stage Docker builds in particular, when you are normally only copying the composer.json/composer.lock into the build image.
I have used Symfony a lot in the past and haven't had many problems. I have been trying to deploy it on a different server (Ubuntu 16 w/ Apache) and am having a lot of issues.
I am getting 500 error now (https://bereanboard.com/app_dev.php). What I have tried is to go to *.com/config.php and *.com/app_dev.php to see issues (I had to temporarily comment out the section that forbids access from non localhost). I have also been checking the Apache error.log and Symfony's var/logs/prod.log.
Keep in mind it works fine on local MAMP and on my previous CentOS.
First, I am for the first time encountering permission problems for var/cache and var/logs. This was pretty easy to fix with commands like chmod -R 777 var/cache. But why did this issue come up only on this new server? Anyway, config.php on the new server is now telling me "All checks passed".
Second, in var/logs/prod.log I am getting all sorts of 'Can't find class, did you forget a "use" statement?' errors. Some of these are for a twig extension AppBundle/Twig/AppExtension.php.
Here are some Critical erros:
request.CRITICAL: Uncaught PHP Exception InvalidArgumentException:
"Class "AppBundle\Controller\HomeController" does not exist." at
/home/travis/var/cache/prod/classes.php line 4872
{"exception":"[object] (InvalidArgumentException(code: 0): Class
\"AppBundle\Controller\HomeController\" does not exist. at
/home/travis/var/cache/prod/classes.php:4872)"} []
and
php.CRITICAL: Class 'AppBundle\Twig\AppExtension' not found
{"exception":"[object]
(Symfony\Component\Debug\Exception\FatalThrowableError(code: 0):
Class 'AppBundle\Twig\AppExtension' not found at
/home/travis/var/cache/prod/appProdProjectContainer.php:2881)"} []
[2017-01-19 06:35:03] request.CRITICAL: Uncaught PHP Exception
Symfony\Component\Debug\Exception\ClassNotFoundException: "Attempted
to load class "AppExtension" from namespace "AppBundle\Twig". Did you
forget a "use" statement for another namespace?" at
/home/travis/var/cache/prod/appProdProjectContainer.php line 2881
{"exception":"[object]
(Symfony\Component\Debug\Exception\ClassNotFoundException(code:
0): Attempted to load class \"AppExtension\" from namespace
\"AppBundle\Twig\".\nDid you forget a \"use\" statement for another
namespace? at
/home/travis/var/cache/prod/appProdProjectContainer.php:2881)"} []
[2017-01-19 06:35:03] request.CRITICAL: Exception thrown when handling
an exception
(Symfony\Component\Cache\Exception\InvalidArgumentException: Cache
directory is not writable
(/home/travis/var/cache/prod/pools/CtBqbs+VrF) at
/home/travis/var/cache/prod/classes.php line 1194)
{"exception":"[object]
(Symfony\Component\Cache\Exception\InvalidArgumentException(code:
0): Cache directory is not writable
(/home/travis/var/cache/prod/pools/CtBqbs+VrF) at
/home/travis/var/cache/prod/classes.php:1194)"} []
Also, it's worth mentioning that that a fresh, empty project made from the command symfony new project does work.
*EDIT
I have consulted these Symfony docs. I have tried every way of clearing cache that I could find.
*EDIT
Here is services.yml
services:
app.twig_extension:
class: AppBundle\Twig\AppExtension
arguments: ["#doctrine.orm.entity_manager", "#security.token_storage"]
public: false
tags:
- { name: twig.extension }
It seems that there is an access problem for your web server.
Check user which launching apache on Centos by
# egrep -i '^user|^group' /etc/httpd/conf/httpd.conf
It should return apache
Then give the good privilege to /home/travis directory:
Option 1: You could have a look on Stack Echange / AskUbuntu and adapt it with apache user instead of www-data
Option 2: With first option, if you've created a folder, Apache cannot write to it. This can be "fixed" by setting umask 0007 and adding yourself (travis) to the Apache group, so that newly created files and folders are writeable by the group.
Option 2 is better if ou have enough privileges to change mask.
Try to clear cache :
php bin/console cache:clear --env=prod
and set files permissions :
chmod -R 777 var/cache
chmod -R 777 var/logs
chmod -R 777 var/sessions
hope this help you.
I had faced the same problem before once. You will have to complete remove the vendor folder
rm -R vendor/
and freshly install all the dependencies again.
php composer.phar install
This will resolve the issue.