R
Railway16mo ago
Teph Gab

Unable to write in public file in laravel

Hello, i'm getting an error Unable to write in the "/app/public/assets/img when tryng to upload file in my laravel project. but its wrking fine in local. can i please find some help
49 Replies
Percy
Percy16mo ago
Project ID: N/A
Percy
Percy16mo ago
⚠️ experimental feature
Teph Gab
Teph Gab16mo ago
allow me a moment please where can i find project id
Brody
Brody16mo ago
in the url
Brody
Brody16mo ago
/project/<project-id>
Teph Gab
Teph Gab16mo ago
f6829ea4-4060-43ad-8286-84b2ca8e2a56 Are we still connected?
Brody
Brody16mo ago
our php guy doesn't seem to be online right now so you'll have to wait, it is the weekend after all 🙂
Teph Gab
Teph Gab16mo ago
Ah alright. thank you i will wait
Brody
Brody16mo ago
oh but i will say, you probably dont want to be uploading files to the app running on railway since storage isnt persistent, any uploaded files will be wiped on the next deployment, youd ideally want to use a storage bucket
Teph Gab
Teph Gab16mo ago
can you help me with that?
Brody
Brody16mo ago
thats a bit out of the scope of what these help threads are for, sorry
Teph Gab
Teph Gab16mo ago
i anderstand, but can you please help me uploading image on the public folder anyway?
Brody
Brody16mo ago
you probably dont want to be uploading files to the app running on railway since storage isnt persistent, any uploaded files will be wiped on the next deployment
Teph Gab
Teph Gab16mo ago
yes i anderstand, but i would like to get it working anyway
Brody
Brody16mo ago
^
Teph Gab
Teph Gab16mo ago
Alright thank you for your help. i will wait
njoguamos
njoguamos16mo ago
This error occurs in Laravel because of permission issues associated with running Laravel inside a docker image.
A workaround is to create nixpacks.json in your root dir and adds commands for changing file permissions (See image for example).
Teph Gab
Teph Gab16mo ago
Thank you. let me try Shoud i just leave setup depenOn and build part blank i'm sorry i'm not really familiar with nixpacks stil not working😢 hello, i still have the same issue. please help
njoguamos
njoguamos16mo ago
Create nixpack.json and paste the following code. Repalce yarn with npm (if need be).
{
"providers": [
"php"
],
"phases": {
"setup": {
"nixPkgs": [
"..."
],
"aptPkgs": [
"..."
]
},
"install": {
"dependsOn": [
"setup"
],
"cmds": [
"mkdir -p /var/log/nginx && mkdir -p /var/cache/nginx",
"sudo chown -R $USER:$USER storage bootstrap public",
"sudo chmod -R 777 storage bootstrap public",
"sudo chmod -R 777 bootstrap/cache/",
"yarn install --frozen-lockfile",
"yarn run build",
"composer install --no-interaction --prefer-dist --optimize-autoloader"
]
},
"build": {
"dependsOn": [
"install"
],
"cmds": [
"php artisan migrate --force",
"php artisan config:cache",
"php artisan cache:clear",
"php artisan event:cache",
"php artisan route:cache",
"php artisan view:cache"
]
}
}
}
{
"providers": [
"php"
],
"phases": {
"setup": {
"nixPkgs": [
"..."
],
"aptPkgs": [
"..."
]
},
"install": {
"dependsOn": [
"setup"
],
"cmds": [
"mkdir -p /var/log/nginx && mkdir -p /var/cache/nginx",
"sudo chown -R $USER:$USER storage bootstrap public",
"sudo chmod -R 777 storage bootstrap public",
"sudo chmod -R 777 bootstrap/cache/",
"yarn install --frozen-lockfile",
"yarn run build",
"composer install --no-interaction --prefer-dist --optimize-autoloader"
]
},
"build": {
"dependsOn": [
"install"
],
"cmds": [
"php artisan migrate --force",
"php artisan config:cache",
"php artisan cache:clear",
"php artisan event:cache",
"php artisan route:cache",
"php artisan view:cache"
]
}
}
}
Teph Gab
Teph Gab16mo ago
thank you so mush let me try right now no need to change anything after npm? upload has failed this time
njoguamos
njoguamos16mo ago
What error are you getting? Open the logs and share.
Teph Gab
Teph Gab16mo ago
#15 5.166 npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility #15 5.228 npm WARN deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead #15 5.564 npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. #15 12.14 #15 12.14 added 778 packages, and audited 779 packages in 11s #15 12.14 #15 12.14 80 packages are looking for funding #15 12.14 run npm fund for details #15 12.15 #15 12.15 2 vulnerabilities (1 low, 1 high) #15 12.15 #15 12.15 To address issues that do not require attention, run: #15 12.15 npm audit fix #15 12.15 #15 12.15 To address all issues (including breaking changes), run: #15 12.15 npm audit fix --force #15 12.15 #15 12.15 Run npm audit for details. #15 12.15 npm notice #15 12.15 npm notice New major version of npm available! 8.19.2 -> 9.6.2 #15 12.15 npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.6.2; #15 12.15 npm notice Run npm install -g npm@9.6.2 to update! #15 12.15 npm notice #15 DONE 12.6s #16 [12/16] RUN npm run build #16 sha256:8fe0a53ac486fb426dede79f431d23a738f8cee2eb40c07a0fb6c4051e363c56 #16 0.763 npm ERR! Missing script: "build" #16 0.764 npm ERR! #16 0.764 npm ERR! To see a list of scripts, run: #16 0.764 npm ERR! npm run #16 0.766 #16 0.767 npm ERR! A complete log of this run can be found in: #16 0.767 npm ERR! /root/.npm/_logs/2023-03-28T19_45_38_164Z-debug-0.log #16 ERROR: executor failed running [/bin/bash -ol pipefail -c npm run build]: exit code: 1 -----
[12/16] RUN npm run build:
----- executor failed running [/bin/bash -ol pipefail -c npm run build]: exit code: 1 Error: Docker build failed
Array.prototype.sort() - JavaScript | MDN
The sort() method sorts the elements of an array in place and returns the reference to the same array, now sorted. The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values.
Teph Gab
Teph Gab16mo ago
let me provide full log
njoguamos
njoguamos16mo ago
Share your package.json
Teph Gab
Teph Gab16mo ago
{ "private": true, "scripts": { "dev": "npm run development", "development": "mix", "watch": "mix watch", "watch-poll": "mix watch -- --watch-options-poll=1000", "hot": "mix watch --hot", "prod": "npm run production", "production": "mix --production" }, "devDependencies": { "@popperjs/core": "^2.10.2", "axios": "^0.21", "bootstrap": "^5.1.3", "laravel-mix": "^6.0.6", "lodash": "^4.17.19", "postcss": "^8.1.14", "resolve-url-loader": "^5.0.0", "sass": "^1.32.11", "sass-loader": "^11.0.1" }, "dependencies": { "@casl/ability": "^6.3.3", "@casl/vue": "^2.2.1", "@vue-stripe/vue-stripe": "^4.5.0", "laravel-vue-pagination": "^3.0.0-beta.1", "moment": "^2.29.4", "pdf-viewer-vue": "^0.2.7", "sweetalert2": "^11.7.3", "vue": "^3.2.36", "vue-loader": "^17.0.1", "vue-router": "^4.0.13", "vue-sweetalert2": "^5.0.5" } }
njoguamos
njoguamos16mo ago
The error is happening because you don't have build in your package. Change npm run build to npm run production
Teph Gab
Teph Gab16mo ago
ok let me try you mean change npm run development to npm run prodcution in my package.json file right?
njoguamos
njoguamos16mo ago
In nixpack.json
Teph Gab
Teph Gab16mo ago
okay allow me a moment i'm stil getting the same error Unable to write in the "/app/public/assets/img
njoguamos
njoguamos16mo ago
Are you trying to save files to public disk?
Teph Gab
Teph Gab16mo ago
yes its working localy public folder in laravel
Brody
Brody16mo ago
^ you could have had that working by now, just saying
Teph Gab
Teph Gab16mo ago
i anderstand file will deleted on deploy but i woud like to be abel to save file anyway
njoguamos
njoguamos16mo ago
Well, if that is the case. Start by adding php artisan storage:link to your build command. Then let me know the results.
Teph Gab
Teph Gab16mo ago
alright let me try same issue
njoguamos
njoguamos16mo ago
I am curious, what are you uploading at deployment stage?
Teph Gab
Teph Gab16mo ago
i can share from vscode if you want are you there?
njoguamos
njoguamos16mo ago
Sure.
Teph Gab
Teph Gab16mo ago
Teph Gab
Teph Gab16mo ago
can you see whats wrong?
njoguamos
njoguamos16mo ago
Check your inbox.
Teph Gab
Teph Gab16mo ago
wich one. vscode?
njoguamos
njoguamos16mo ago
No. Your discord private message.
Teph Gab
Teph Gab16mo ago
accepted
renatoalvarez
renatoalvarez14mo ago
I have the same issue in Laravel, I need to upload files to use import actions, In this use case it is not necessary to have persistence because uploaded files are temporary
Brody
Brody14mo ago
save files to /app/storage
renatoalvarez
renatoalvarez14mo ago
it works well thanks: 'temporary_files' => [ 'disk' => 'local', 'directory' => 'app/storage/filament-import', ],
Brody
Brody14mo ago
no prob 🙂