-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Config:cache for default Laravel configuration creates absolute paths #12263
Comments
You need to run composer and our optimization commands on your server, not before deployment. |
In the Laravel docs quote I mentioned above, "deployment routine" does not explicitly mean that the cache command has to be run on the server and not in the folder which is about to be deployed. Therefore I think it is worth to expand this sentence, so people do not make false assumptions (as I did). Anyway, it's a shame that we cannot use relative paths instead of storage_path() in config files. This would make things much easier for automatic CI deployments. |
Yes, that's why documentation says "deployment routine", not "build routine"... |
i had the same problem when deploying to a server that mounts the codebase into a docker container and so the path inside the docker container is different from the one for the ones stranding here from googleling this, i created a small deployer receipt that replaces the absolute paths in config.php with the path as seen from inside the container: <?php
namespace Deployer;
desc('Run sed to replace absolute paths with docker mappings.');
task('config:fix', function () {
cd('{{release_or_current_path}}');
run("sed -i -- 's/\/absolute\/path\/from\/outside\//\/absolute\/inside\/path\//g' ./bootstrap/cache/*");
}); |
thanks @simonbuehler for the script. For any other person coming there with the same issue, if you use the Here, i'm building the files in the #!/bin/bash
FILES=$(find compiled-views/ -type f)
for file in $FILES; do
newsha=$(grep PATH ${file} \
| sed -e 's/^.*PATH \(.*\) ENDPATH.*$/\1/g' \
| sed -e 's/\/your\/folder\/during\/build\/time\//\/deployed\/folder\//g' \
| tr -d '\n' \
| sha1sum - \
| head -c 40).php
echo "moving $file -> compiled-views/$newsha"
mv $file compiled-views/$newsha
done |
I noticed that when I run
php artisan config:cache
the resulting cache has absolute paths because by default there are somestorage_path()
calls in Laravel config files.I have read the documentation:
The documentation does not say that I should run the command on the server and not on my automated CI build agent. But not everyone has access to
php artisan config:cache
command on their servers for executing it remotely from CI build agent.I think the documentation should be updated to reflect the requirement to run the command on the server.
However, it would be even better to implement some way to generate config cache with relative paths.
Currently I could add a workaround for the issue and create a PHP controller which executes artisan command, and call it during deployment. But the problem is that on our server deployment is set up to work through Git push and only after a few minutes the web site gets synced with current version in the repository. I don't think it would be a good idea to just sit inside my CI deploy script and wait for unknown time just to be able to call URL to my custom controller which in turn executes
php artisan config:cache
.So, we are back to the question - how to make the paths in config files relative to the app root and generate cached config which will work with relative paths?
The text was updated successfully, but these errors were encountered: