I'm deploying my Symfony application and I'm getting the error:
An exception has been thrown during the rendering of a template
("Asset manifest file "********/public/build/manifest.json" does not
exist.").
My server public dir is www/.
I put APP_ENV=prod in my .env file but apparently I'm still in dev environment, is there something else to do to pass on production?
The file exists and is in www/build/manifest.json on the server, how do I change the public dir in Symfony ? I tried to add this in my composer.json file :
"extra": {
"...": "...",
"public-dir": "www"
}
but it didn't work.
Any suggestion? Thanks in advance!
Related
I ran the homestead make command successfully.
Afterward, I ran the vagrant up command in the vendor/bin folder, but I get the following error:
Vagrant failed to initialize at a very early stage:
There was an error loading a Vagrantfile. The file being loaded
and the error message are shown below. This is usually caused by
a syntax error.
Path: C:/xampp/htdocs/all-projects/project1/vendor/bin/Vagrantfile
Line number: 0
Message: LoadError: cannot load such file -- C:/xampp/htdocs/all-projects/project1/vendor/bin/vendor/laravel/homestead/scripts/homestead.rb
The path to homstead.rb is incorrect. Such a path does not exist and the homestead.rb file is in another folder for the project. How do I fix the homestead.rb path that is automatically used by vagrant?
P.S. the /laravel folder is present in the project directory.
You need to edit your Vagrantfile. In there is a line that references homestead.rb. Mine looks like
require File.expand_path(File.dirname(__FILE__) + '/scripts/homestead.rb')
Update this to be the correct path.
I got a little struggle with renaming dir to public_html for web host.
According to latest tutorial I'm trying to successfully rename it, but every time when i'm trying to run local server using console command I'm getting an error:
[ERROR] The document root directory ".../.../App/public" does not exist.
I'm sure that I'm doing something wrong with code. But I don't know where. I'm very beginner with Symfony.
Here's my code from composer.json:
"extra": {
"symfony": {
"allow-contrib": false,
"require": "4.2.*",
}
"public-dir": "public_html"
},
Did I understood something wrong with it?
Thanks for help.
If the code snippet represents exactly what you have in your composer.json then I have noticed that it is not correctly formatted json file. In the "extra", after the value of "symfony" key, you need to put a separator "," then in the next line you may add more key:value pairs. AS in:
"extra": {
"symfony": {
"allow-contrib": false,
"require": "4.2.*",
},
"public-dir": "new_public_html_dirname"
}
A not well formatted json file will prevent it from being executed. I hope it helps.
It is important to run composer update.
composer update
As the index.php file is the first file being run (by the webserver) you should just be able to rename the public directory to public_html and it will work, and not need to change anything in the composer.json (though how that would affect the framework code, without at least running any composer-scripts, I do not know).
I've just created a new Symfony 4.2.3 project, and done nothing more than renaming the directory, and running (most) bin/console commands are not affected.
The in-built server will have issues, but you can tell it which directory to use as the docroot with:
mv public public_html
bin/console server:start --docroot=public_html/
[OK] Server listening on http://127.0.0.1:8000
The changes to composer.json are not required.
I'm trying to change the directory of my dependencies on a Symfony 3.4 application.
I need that because I'm working on macOS with Docker and I'd rather have them not shared with the host since the file synchronization is too slow.
The related documentation, says:
The change in the composer.json will look like this:
{
"config": {
"bin-dir": "bin",
"vendor-dir": "/some/dir/vendor"
},
}
That I did
Then, update the path to the autoload.php file in app/autoload.php:
// app/autoload.php
// ...
$loader = require '/some/dir/vendor/autoload.php';
I don't have any autoload.php file in my app directory.
Am I missing something in the doc ?
The application generates the following fatal error:
Warning: require(/some/dir/vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php): failed to open stream: No such file or directory in /vendor/composer/autoload_real.php on line 66
Fatal error: require(): Failed opening required '/some/dir/vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php' (include_path='.:/usr/local/lib/php') in /vendor/composer/autoload_real.php on line 66
I originally created the application with:
$ composer create-project symfony/framework-standard-edition test "3.*"
Open your composer.json file in editor.
Look for "autoload-dev" section
Remove whole "files" part (if exist)
Save file
Run composer install once again
Enjoy the party.
Sample code:
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
},
"files": [
"vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"
]
},
In Symfony 3.4, the file app/autoload.php is removed so you should:
replace old vendor path by the new vendor path directly in web/app.php, web/app_dev.php, bin/console and var/SymfonyRequirements.php files
Rerun the command $ composer install
I had the same issue and it was resolved doing the next.
Follow these 3 steps
1. First of all, modify composer.json to use the new vendor path:
"config": {
...,
"vendor-dir": "/app-vendor"
},
And remove the next line:
"files": ["vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"]
2. Secondly, if you are using docker-compose add a new volume where you'll put your vendors.
volumes:
...
- /app-vendor
PD: /app-vendor is a mounted volume which is now empty directory.
3. Lastly, write require '/app-vendor/autoload.php'; to:
my_project_name/bin/console
my_project_name/web/app.php
my_project_name/web/app_dev.php
PD1: Simply, this line is pointing to the new vendor path.
PD2: It's not necessary to modify any other file (like var/SymfonyRequirements.php as I could read).
Check your changes
Once the changes are ready, remove vendor/ and also remove the containers to avoid future problems.
Start your new containers and execute composer install. Now, /vendor will be /app-vendor, it won't be in the root folder of the project anymore.
For more details, I'd recommend you to go to my docker-symfony repository and check the commits. You'll see a benchmark progression and another tips like cached volumes and non-shared /cache && /logs folders.
All for Symfony 3.4.
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 created custom helper laravel 5.2. I put in folder App/Helpers/Global.php.
and autoload files in composer.json :
"autoload": {
"files" : [
"App/Helpers/Global.php"
]
}
On my Windows PC, it's working fine, but when i deploy to VPS centos I got this error.
PHP Warning: require(/xxxx/xxxxx/public_html/xxxx/vendor/composer/../../App/Helpers/Global.php): failed to open stream: No such file or directory in /xxxx/xxxx/public_html/xxxx/vendor/composer/autoload_real.php on line 66
why Autoloading "files" is relative to vendor directory ?
Thanks in advance.
error custom helper
It seems that OS on your VPS has case sensitive filename file system unlike Windows.
Just replace "App/Helpers/Global.php" with "app/Helpers/Global.php" and it should help.