Error Deploying simple PHP code.

Howdy, I tried to deploy using 2 methods ( on other providers including Heroku everything seems working) Method 1 : Deploy using PHP (auto deduct) It works but with 1 major problem. I need to have a folder writable (777) where json files will be stored when user submits request. and also files needs to writeable when user will modify request _ stored in json file e.g: aliya_29_abc.json ERROR: file aliya_29_abc.json is not writable permission denied. Method 2 : Using docker This method is usually easy and works on Heroku. 1 file Dockerfile 1 Folder src/ includes all website code.. It does deploy successfully but when i generate domain and open domain it gives error ( i have tried some tweaks - but no luck) USEFUL INFORMATION You might need below details... GitHub source code : https://github.com/amjiddader/railway_apache2 (original project is private but this link shows exact same method) Railway Project Domain: https://railwayapache2-production-7e56.up.railway.app/ Project ID: 8fa60338-0ec0-4114-a6ba-31f63fb07aa6 Railway Error: Application failed to respond ----------------------------------- Note: i tried with EXPOSE 8080 / 80 and 10 others I have Tried different images i.e: FROM ubuntu:20.04 '/ FROM php:8.2-apache ,/ FROM php:8.2-fpm Final thoughts... I never though i will stuck in this situation , i have always used Heroku and still using heroku only drawback is DYNO are small lazy as they sleep every 30 mins.. I am totally new to Heroku ..
GitHub
GitHub - amjiddader/railway_apache2: Deploying simple php website o...
Deploying simple php website on railway.app . Contribute to amjiddader/railway_apache2 development by creating an account on GitHub.
41 Replies
Percy
Percy2y ago
Project ID: N/A
amjiddader
amjiddaderOP2y ago
Mentioned : 8fa60338-0ec0-4114-a6ba-31f63fb07aa6
Brody
Brody2y ago
use nixpacks, and save files into /app/storage
amjiddader
amjiddaderOP2y ago
I m new here i have no idea.. should i use Dockerfile ??? or direct deply?
Brody
Brody2y ago
well technically railway uses docker no matter what you do but you shouldnt need a dockerfile to do this also, the src folder will have to be renamed to app
amjiddader
amjiddaderOP2y ago
if i am copying files from src/ folder to /var/www/html on docker - does it make any sense where to copy from? And without docker how can i save files to /app/storage?? If you could share any repo or even modify my repo to make it work....
Brody
Brody2y ago
you dont need a dockerfile
Brody
Brody2y ago
Adam
Adam2y ago
Sounds like you’re not familiar with Nixpacks. Nixpacks detects what your app needs to run and creates + runs a dockerfile for you automatically That’s the main draw of Railway. In most cases you don’t need to configure your build manually Your issue with files not being writable can be fixed by chmod-ing the file before you write to it
amjiddader
amjiddaderOP2y ago
chmod without docker? how... https://railwayapache2-production.up.railway.app/test.php Warning: file_put_contents(test.txt): Failed to open stream: Permission denied in /app/test.php on line 2
Brody
Brody2y ago
write files to /app/storage
amjiddader
amjiddaderOP2y ago
if i store file on my git repo at /app/storage/test.php same erroe: permession denied
Brody
Brody2y ago
bruh
amjiddader
amjiddaderOP2y ago
ook ... let me check Warning: file_put_contents(/app/storage/test.txt): Failed to open stream: No such file or directory in /app/test.php on line 2
Brody
Brody2y ago
@aleks please
root
root2y ago
Try adding a storage folder in your repo with a dummy file so Git will track it.
amjiddader
amjiddaderOP2y ago
Here is file: how can i host this and also it should create new json file .. for now i am using : test.txt https://github.com/amjiddader/railway_apache2/raw/main/app/test.php
root
root2y ago
I'm afraid this is not entirely correct; your app will end up in /app, so the folder should just be storage rather than app/storage, but it will not be created for you, just detected and its permissions modified.
Brody
Brody2y ago
mb
root
root2y ago
Brody, why'd you delete your message?
Brody
Brody2y ago
wrong info
root
root2y ago
maybe an env var should be added to make it create the folder woohoo! an excuse to write more perl!
Brody
Brody2y ago
or or or storage volume 🙂
root
root2y ago
maybe NIXPACKS_DATA_FOLDER Oh right, those exist now
Brody
Brody2y ago
you can use them for whatever now, temp files, permanent files, sqlite dbs, etc
root
root2y ago
Oh, yeah, actually, for this usecase, you should probably create a storage volume. Just type /beta
amjiddader
amjiddaderOP2y ago
i am very new to nix ... so could you try to host on your github and deploy?
root
root2y ago
Sure!
Brody
Brody2y ago
what does deply mean
root
root2y ago
deploy
Brody
Brody2y ago
oh deploy
amjiddader
amjiddaderOP2y ago
i mean DEPLOY
Brody
Brody2y ago
no worries
root
root2y ago
seems as if perms are messed up with the volume as well
Brody
Brody2y ago
i dont have any issues with perms
root
root2y ago
probably has something to do with NGINX running as a different user
amjiddader
amjiddaderOP2y ago
beta thing seems working (as per documentation )
thanks for beta invitation ... so if we mount new volume
Brody
Brody2y ago
mount point should be /storage in your repo, put the index.php file in an /app folder and remove the /storage folder from the repo too
root
root2y ago
I'm trying some stuff over here, hold y'all's respective horses please yep, perms have problems should probably ping in jr to let him know @jr, it seems like volumes don't currently have the correct perms for PHP apps, since they run as a different user - would it be possible to use 777 by default on volumes, or would that be a security risk? Or, is there some way to detect volumes through environment variables, so that the PHP provider could do that automatically? Anyhoo, for a duct tape fix, try adding a volume and setting your start command in your service settings to chmod -R ugo+rwx <path to volume goes here> && perl /assets/prestart.pl /assets/nginx.template.conf /nginx.conf && (php-fpm -y /assets/php-fpm.conf & nginx -c /nginx.conf)
jr
jr2y ago
Yes this is a know caveat with volumes at the moment. They are mounted as the root user. Not just specific to nixpacks or php provider. We will be looking into the best solution next week
Want results from more Discord servers?
Add your server