Can't connect database to deployed service
anky131997
TRIALOP

a year 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.

Solved

60 Replies

anky131997
TRIALOP

a year ago

273d71ca-77e9-4819-a0cf-fe0d616f008a


a year ago

Hey, you can't use the private network during build. You have a few options:

  1. perform migrations and other database operations during runtime,

  2. use public network during build and private network during runtime
    or

  3. enable the new builder in your service settings which allows private network usage during build


anky131997
TRIALOP

a year ago

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?


a year ago

honestly I think in your case the cleanest solution would be just to use the new builder


a year ago

just need to toggle this

1322156270043664400


anky131997
TRIALOP

a year ago

Thanks. Let me try this.


anky131997
TRIALOP

a year ago

Well I tried it. The build process was running for a long time, then it failed and now it's showing this error.

1322161975589077000


a year ago

hm! I guess it's a good thing it's still in beta huh


a year ago

in that case i'd recommend just performing migrations during runtime for now 🤣


anky131997
TRIALOP

a year ago

I don't know how to do that actually🥹 💀


a year 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


anky131997
TRIALOP

a year ago

Aye aye captain🫡


anky131997
TRIALOP

a year ago

Yup that worked it's deployed


a year ago

Awesome!!! Glad you got it working


anky131997
TRIALOP

a year ago

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.

1322175238922043400


anky131997
TRIALOP

a year ago

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?


a year ago

the right port is defined in the PORT environment variable that Railway automatically injects into your environment


anky131997
TRIALOP

a year ago

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

1322177634523676700


a year ago

that's the HTTP logs you see when you're not listening on the correct port


anky131997
TRIALOP

a year ago

any idea where to get the right port? I have no idea where you get the right one.


a year ago

yea, it's defined in the PORT environment variable


anky131997
TRIALOP

a year ago

Yeah I can't find that 💀


a year ago

it's an environment variable so you can't see it anywhere, you need to access it within your code


a year 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

anky131997
TRIALOP

a year ago

Alright let me check


anky131997
TRIALOP

a year ago

Thanks a lot for help brother you've been a big help


a year ago

no problem at all


anky131997
TRIALOP

a year ago

well I did find the port, it's 8080. I switched the port. But it's still not working and showing the error.


a year 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


anky131997
TRIALOP

a year ago

Fixed it


anky131997
TRIALOP

a year ago

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.


a year ago

awesome, yea i don't think Railway returns a 500 error ever so it's probably an issue with your app there


anky131997
TRIALOP

a year ago

to connect the database with the service, this ( MYSQLURL = ${{ MySQL.MYSQLURL }} ) reference variable works right?


a year ago

yea, MYSQL_URL=${{MySQL.MYSQL_URL}} should work fine


a year ago

artisan serve is a development server 🙂


a year 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)


anky131997
TRIALOP

a year ago

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.


a year ago

I don't think it's smart sharing your environment variables like that, it has things like your database password and api keys


a year 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


maddsua
HOBBY

a year ago

Nice, somebody for sure has made a copy of your db credentials now


a year ago

I'll just delete it myself


anky131997
TRIALOP

a year ago

My bad


anky131997
TRIALOP

a year ago

Yeah I was AFK


anky131997
TRIALOP

a year ago

I did check log, I believe it's problem with the database. I can't seem to connect it


maddsua
HOBBY

a year ago

Too late it's already in my telegram channel


maddsua
HOBBY

a year ago

(kidding)


maddsua
HOBBY

a year ago

Or am I 🤨


maddsua
HOBBY

a year ago

Wait


maddsua
HOBBY

a year ago

Bro even had their SMTP credentials there


maddsua
HOBBY

a year ago

💀


maddsua
HOBBY

a year ago

@AnKY change all the passwords IMMEDIATELY


maddsua
HOBBY

a year ago

All of the secrets that you had exposed in that message


maddsua
HOBBY

a year ago

ASAP


anky131997
TRIALOP

a year ago

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.


a year 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


anky131997
TRIALOP

a year ago

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.


a year 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 🙂


anky131997
TRIALOP

a year ago

Sure mark it as resolved. I'm starting from scratch anyways. If I run into problem again I'll reach out.


a year ago

Awesome, good luck!!!!


a year ago

!s


Status changed to Solved dev about 1 year ago


Loading...