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
Project ID:
N/A
Mentioned : 8fa60338-0ec0-4114-a6ba-31f63fb07aa6
use nixpacks, and save files into /app/storage
I m new here i have no idea..
should i use Dockerfile ??? or direct deply?
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
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....
you dont need a dockerfile
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
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
write files to
/app/storage
if i store file on my git repo at /app/storage/test.php
same erroe: permession denied
bruh
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
@aleks please
Try adding a
storage
folder in your repo with a dummy file so Git will track it.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
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.mb
Brody, why'd you delete your message?
wrong info
maybe an env var should be added to make it create the folder
woohoo! an excuse to write more perl!
or or or storage volume 🙂
maybe
NIXPACKS_DATA_FOLDER
Oh right, those exist nowyou can use them for whatever now, temp files, permanent files, sqlite dbs, etc
Oh, yeah, actually, for this usecase, you should probably create a storage volume.
Just type
/beta
and then read this
https://docs.railway.app/reference/volumes
i am very new to nix ... so
could you try to host on your github and deploy?
Sure!
what does deply mean
deploy
oh deploy
i mean DEPLOY
no worries
seems as if perms are messed up with the volume as well
i dont have any issues with perms
probably has something to do with NGINX running as a different user
beta thing seems working (as per documentation )
thanks for beta invitation ... so if we mount new volume
thanks for beta invitation ... so if we mount new volume
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
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)
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