6 months ago
I'm new in Railway. I'm trying to use the free tier to deploy my small Laravel Project. I deployed my GitHub repo. I created a MySQL service, but I can't connect it to my repo. I added a reference variable MYSQLURL = ${{ MySQL.MYSQLURL }} to connect the database. But when I'm trying to deploy the variable
NIXPACKSBUILDCMD="
composer install &&
npm install --production &&
php artisan optimize &&
php artisan config:cache &&
php artisan route:cache &&
php artisan view:cache &&
php artisan migrate --force &&
php artisan db:seed
"
It's not working. Build is failing. And when I'm trying to use CMD to run "php artisan migrate" it's showing the error -- SQLSTATE[HY000] [2002] phpnetworkgetaddresses: getaddrinfo for mysql.railway.internal failed: No such host is known. (Connection: mysql, SQL: select exists (select 1 from informationschema.tables where tableschema = 'railway' and tablename = 'migrations' and tabletype
in ('BASE TABLE', 'SYSTEM VERSIONED')) as exists
)
can anyone advise me what to do? I'm having a hardtime figuring it out.
0 Replies
6 months ago
Hey, you can't use the private network during build. You have a few options:
perform migrations and other database operations during runtime,
use public network during build and private network during runtime
orenable the new builder in your service settings which allows private network usage during build
I'm confused since I'm new at this, how do I use public network during build and private network during runtime? What exactly do I have to change?
6 months ago
honestly I think in your case the cleanest solution would be just to use the new builder
6 months ago
just need to toggle this
Well I tried it. The build process was running for a long time, then it failed and now it's showing this error.
6 months ago
hm! I guess it's a good thing it's still in beta huh
6 months ago
in that case i'd recommend just performing migrations during runtime for now 🤣
6 months ago
just do all this
php artisan optimize &&
php artisan config:cache &&
php artisan route:cache &&
php artisan view:cache &&
php artisan migrate --force &&
php artisan db:seed
in your start command instead of your build command
6 months ago
Awesome!!! Glad you got it working
Yeah it's deployed but it's showing this error. I'm now trying to figure out what exactly is going on. Although I don't see any error in deploy logs. They are clean.
In the documentation it's said, maybe the target port is set to some other port. How do I figure out which port is the right port?
6 months ago
the right port is defined in the PORT
environment variable that Railway automatically injects into your environment
So it's not an issue with PORT. There are actually no issues with deployment. The deploy logs are clean. I'm getting the errors in HTTP logs
6 months ago
that's the HTTP logs you see when you're not listening on the correct port
any idea where to get the right port? I have no idea where you get the right one.
6 months ago
yea, it's defined in the PORT
environment variable
6 months ago
it's an environment variable so you can't see it anywhere, you need to access it within your code
6 months ago
I don't use PHP but from what I can tell, you'd need to do this
php artisan serve --host=0.0.0.0 --port=$PORT
6 months ago
no problem at all
well I did find the port, it's 8080. I switched the port. But it's still not working and showing the error.
6 months ago
you need to use the start command I gave you because I think it serves on 127.0.0.1
by default and it should serve on 0.0.0.0
It's not showing Application failed to respond anymore, but it's showing 500 Server error. I think I have given some wrong environment variables. Let me check.
6 months ago
awesome, yea i don't think Railway returns a 500 error ever so it's probably an issue with your app there
to connect the database with the service, this ( MYSQLURL = ${{ MySQL.MYSQLURL }} ) reference variable works right?
6 months ago
yea, MYSQL_URL=${{MySQL.MYSQL_URL}}
should work fine
6 months ago
artisan serve is a development server 🙂
6 months ago
oh, i didn't know that, my bad - i don't use php 😭
will come back to this thread when I'm awake again (going to bed gn)
Hi there. I'm still having trouble with this. I configured everything as they are supposed to be (Or I think I did atleast). The "Application failed to respond" error is gone. But error 500-server error still persists. I checked Laravel Logs and it's showing it can't find the mysql.railway.internal host. I believe I configured the ENV variables correctly, here are they ---
APPNAME="SBStudios" APPENV="production"
APPKEY="base64:3D2UHHZ9OoEu/ZC9spxyFaZodtdzbdG3taphCg1W/Ak=" APPDEBUG="false"
APPTIMEZONE="UTC" APPURL="http://sbstudios-production.up.railway.app"
APPLOCALE="en" APPFALLBACKLOCALE="en" APPFAKERLOCALE="enUS"
APPMAINTENANCEDRIVER="file"
PHPCLISERVERWORKERS="4" BCRYPTROUNDS="12"
LOGCHANNEL="stack" LOGSTACK="single"
LOGDEPRECATIONSCHANNEL="null"
LOGLEVEL="debug" DBCONNECTION="mysql"
DBHOST="mysql.railway.internal" DBPORT="3306"
DBDATABASE="railway" DBUSERNAME="root"
DBPASSWORD="zXMGfzVvjgqzkeiheiusQvFOVSiVnCIv" SESSIONDRIVER="database"
SESSIONLIFETIME="120" SESSIONENCRYPT="false"
SESSIONPATH="/" SESSIONDOMAIN="null"
BROADCASTCONNECTION="log" FILESYSTEMDISK="local"
QUEUECONNECTION="database" CACHESTORE="database"
CACHEPREFIX="" MEMCACHEDHOST="127.0.0.1"
REDISCLIENT="phpredis" REDISHOST="127.0.0.1"
REDISPASSWORD="null" REDISPORT="6379"
MAILMAILER="smtp" MAILHOST="smtp.gmail.com"
MAILPORT="465" MAILUSERNAME="springbreakstudio@gmail.com"
MAILPASSWORD="zeoasteyrgstfadw" MAILENCRYPTION="tls"
MAILFROMADDRESS="springbreakstudio@gmail.com"
MAILFROMNAME="${APPNAME}" AWSACCESSKEYID=""
AWSSECRETACCESSKEY="" AWSDEFAULTREGION="us-east-1" AWSBUCKET=""
AWSUSEPATHSTYLEENDPOINT="false"
VITEAPPNAME="${APPNAME}" MYSQLURL="${{MySQL.MYSQLURL}}" NIXPACKSBUILD_CMD="
composer install --optimize-autoloader --no-dev &&
npm install --production
"
Kindly help me understand what exactly I'm doing wrong here? It will be a big help.
6 months ago
I don't think it's smart sharing your environment variables like that, it has things like your database password and api keys
6 months ago
that 500 error is an in-app error, it's NextJS's default error page, you should check logs and see what the issue is
6 months ago
I'll just delete it myself
I did check log, I believe it's problem with the database. I can't seem to connect it
I'm new to this dude. I didn't know how these things work. Well I'm still trying to resolve the issue I'm facing.
6 months ago
change your exposed passwords + keys first, then we’ll solve your problem. Madd didn’t intend to be rude, but leaking your keys is very bad
No no it's fine I didn't find it rude. I did a dumb mistake I know. I actually panicked and nuked the whole project. I'm starting deploying from scratch.
6 months ago
@AnKY Am I clear to mark as solved? Your original question was answered after all
If you run into trouble again you'd of course be welcome to open another thread 🙂
Sure mark it as resolved. I'm starting from scratch anyways. If I run into problem again I'll reach out.
6 months ago
Awesome, good luck!!!!
6 months ago
!s
Status changed to Solved dev • 6 months ago