Can't connect database to deployed service
anky131997
TRIALOP

2 years 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 MYSQL_URL = ${{ MySQL.MYSQL_URL }} to connect the database. But when I'm trying to deploy the variable

NIXPACKS_BUILD_CMD="

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] php_network_getaddresses: getaddrinfo for mysql.railway.internal failed: No such host is known. (Connection: mysql, SQL: select exists (select 1 from information_schema.tables where table_schema = 'railway' and table_name = 'migrations' and table_type

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

2 years ago

273d71ca-77e9-4819-a0cf-fe0d616f008a


2 years 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

2 years 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?


2 years ago

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


2 years ago

just need to toggle this

1322156270043664474


anky131997
TRIALOP

2 years ago

Thanks. Let me try this.


anky131997
TRIALOP

2 years ago

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

1322161975589076992


2 years ago

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


2 years ago

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


anky131997
TRIALOP

2 years ago

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


2 years 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

2 years ago

Aye aye captain🫡


anky131997
TRIALOP

2 years ago

Yup that worked it's deployed


2 years ago

Awesome!!! Glad you got it working


anky131997
TRIALOP

2 years 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.

1322175238922043504


anky131997
TRIALOP

2 years 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?


2 years ago

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


anky131997
TRIALOP

2 years 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

1322177634523676724


2 years ago

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


anky131997
TRIALOP

2 years ago

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


2 years ago

yea, it's defined in the PORT environment variable


anky131997
TRIALOP

2 years ago

Yeah I can't find that 💀


2 years ago

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


2 years 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

2 years ago

Alright let me check


anky131997
TRIALOP

2 years ago

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


2 years ago

no problem at all


anky131997
TRIALOP

2 years ago

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


2 years 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

2 years ago

Fixed it


anky131997
TRIALOP

2 years 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.


2 years 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

2 years ago

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


2 years ago

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


2 years ago

artisan serve is a development server 🙂


2 years 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

2 years 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 ---

APP_NAME="SBStudios"

APP_ENV="production"

APP_KEY="base64:3D2UHHZ9OoEu/ZC9spxyFaZodtdzbdG3taphCg1W/Ak="

APP_DEBUG="false"

APP_TIMEZONE="UTC"

APP_URL="http://sbstudios-production.up.railway.app"

APP_LOCALE="en"

APP_FALLBACK_LOCALE="en"

APP_FAKER_LOCALE="en_US"

APP_MAINTENANCE_DRIVER="file"

PHP_CLI_SERVER_WORKERS="4"

BCRYPT_ROUNDS="12"

LOG_CHANNEL="stack"

LOG_STACK="single"

LOG_DEPRECATIONS_CHANNEL="null"

LOG_LEVEL="debug"

DB_CONNECTION="mysql"

DB_HOST="mysql.railway.internal"

DB_PORT="3306"

DB_DATABASE="railway"

DB_USERNAME="root"

DB_PASSWORD="zXMGfzVvjgqzkeiheiusQvFOVSiVnCIv"

SESSION_DRIVER="database"

SESSION_LIFETIME="120"

SESSION_ENCRYPT="false"

SESSION_PATH="/"

SESSION_DOMAIN="null"

BROADCAST_CONNECTION="log"

FILESYSTEM_DISK="local"

QUEUE_CONNECTION="database"

CACHE_STORE="database"

CACHE_PREFIX=""

MEMCACHED_HOST="127.0.0.1"

REDIS_CLIENT="phpredis"

REDIS_HOST="127.0.0.1"

REDIS_PASSWORD="null"

REDIS_PORT="6379"

MAIL_MAILER="smtp"

MAIL_HOST="smtp.gmail.com"

MAIL_PORT="465"

MAIL_USERNAME="springbreakstudio@gmail.com"

MAIL_PASSWORD="zeoasteyrgstfadw"

MAIL_ENCRYPTION="tls"

MAIL_FROM_ADDRESS="springbreakstudio@gmail.com"

MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=""

AWS_SECRET_ACCESS_KEY=""

AWS_DEFAULT_REGION="us-east-1"

AWS_BUCKET=""

AWS_USE_PATH_STYLE_ENDPOINT="false"

VITE_APP_NAME="${APP_NAME}"

MYSQL_URL="${{MySQL.MYSQL_URL}}"

NIXPACKS_BUILD_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.


2 years ago

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


2 years 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

2 years ago

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


2 years ago

I'll just delete it myself


anky131997
TRIALOP

2 years ago

My bad


anky131997
TRIALOP

2 years ago

Yeah I was AFK


anky131997
TRIALOP

2 years ago

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


maddsua
HOBBY

2 years ago

Too late it's already in my telegram channel


maddsua
HOBBY

2 years ago

(kidding)


maddsua
HOBBY

2 years ago

Or am I 🤨


maddsua
HOBBY

2 years ago

Wait


maddsua
HOBBY

2 years ago

Bro even had their SMTP credentials there


maddsua
HOBBY

2 years ago

💀


maddsua
HOBBY

2 years ago

@AnKY change all the passwords IMMEDIATELY


maddsua
HOBBY

2 years ago

All of the secrets that you had exposed in that message


maddsua
HOBBY

2 years ago

ASAP


anky131997
TRIALOP

2 years 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.


2 years 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

2 years 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.


2 years 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

2 years ago

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


2 years ago

Awesome, good luck!!!!


2 years ago

!s


Status changed to Solved dev over 1 year ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...