R
Railway•10mo ago
kmskrishna

Public DB host name is working but private URL is not

Prorject ID: 2a4ccb82-5166-478f-8ad3-5abadca54feb
32 Replies
Percy
Percy•10mo ago
Project ID: 2a4ccb82-5166-478f-8ad3-5abadca54feb
kmskrishna
kmskrishna•10mo ago
I get this error:
No description
Brody
Brody•10mo ago
what errors do you get in the deployment logs?
kmskrishna
kmskrishna•10mo ago
There were no errors in Deployment logs or I am not logging it.
Brody
Brody•10mo ago
this is your own app?
kmskrishna
kmskrishna•10mo ago
This is sendy
kmskrishna
kmskrishna•10mo ago
Sendy - Send Newsletters 100x cheaper via Amazon SES
A self hosted newsletter application that lets you send trackable emails via Amazon Simple Email Service (SES) at 100x cheaper than other hosted solutions.
kmskrishna
kmskrishna•10mo ago
I made a Dockerfile for this.
Brody
Brody•10mo ago
send the dockerfile please and your config.php please
kmskrishna
kmskrishna•10mo ago
# Use the Alpine Linux base image
FROM php:8-fpm-alpine
RUN apk --no-cache add nginx php php-fpm php-xml php-curl php-mysqli curl php-session php-simplexml rsync unzip zip openrc php-gettext

# RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli

ARG SENDY_LICENSE_KEY
ARG MYSQLHOST
ARG MYSQLUSER
ARG MYSQLPASSWORD
ARG MYSQL_DATABASE
ARG CONFIG_FILE
ARG RAILWAY_PUBLIC_DOMAIN



ENV MYSQLHOST=${MYSQLHOST}
ENV MYSQLUSER=${MYSQLUSER}
ENV MYSQLPASSWORD=${MYSQLPASSWORD}
ENV MYSQL_DATABASE=${MYSQL_DATABASE}
ENV RAILWAY_PUBLIC_DOMAIN=${RAILWAY_PUBLIC_DOMAIN}



# Install Nginx and PHP

COPY sendy.conf /etc/nginx/http.d/${RAILWAY_PUBLIC_DOMAIN}.conf

# Expose ports
EXPOSE 8000


# Start both Nginx and PHP-FPM in the foreground when the container starts
RUN echo "Downloading https://sendy.co/download/?license=${SENDY_LICENSE_KEY}" \
&& curl -L -o sendy.zip https://sendy.co/download/?license=${SENDY_LICENSE_KEY} \
&& unzip sendy.zip -d /tmp \
&& rm -rf /tmp/sendy/uploads \
&& rsync -av /tmp/sendy/ /var/www/html/ \
&& rm sendy.zip \
&& rm -rf /tmp/sendy \
&& chown -R www-data:www-data /var/www/html \
&& chmod -R 755 /var/www/html \
|| echo "🚨 Something went wrong with the sendy download, if this is the first time you start this docker stack, this means sendy will not work. If this is not the first time, this means sendy did not auto-update. Please check if the link is live: https://sendy.co/download/?license=${SENDY_LICENSE_KEY}"

#RUN echo "$CONFIG_FILE" > /var/www/html/includes/config.php

COPY config.php /var/www/html/includes/config.php

CMD php-fpm82 -D; nginx -g "daemon off;"
# Use the Alpine Linux base image
FROM php:8-fpm-alpine
RUN apk --no-cache add nginx php php-fpm php-xml php-curl php-mysqli curl php-session php-simplexml rsync unzip zip openrc php-gettext

# RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli

ARG SENDY_LICENSE_KEY
ARG MYSQLHOST
ARG MYSQLUSER
ARG MYSQLPASSWORD
ARG MYSQL_DATABASE
ARG CONFIG_FILE
ARG RAILWAY_PUBLIC_DOMAIN



ENV MYSQLHOST=${MYSQLHOST}
ENV MYSQLUSER=${MYSQLUSER}
ENV MYSQLPASSWORD=${MYSQLPASSWORD}
ENV MYSQL_DATABASE=${MYSQL_DATABASE}
ENV RAILWAY_PUBLIC_DOMAIN=${RAILWAY_PUBLIC_DOMAIN}



# Install Nginx and PHP

COPY sendy.conf /etc/nginx/http.d/${RAILWAY_PUBLIC_DOMAIN}.conf

# Expose ports
EXPOSE 8000


# Start both Nginx and PHP-FPM in the foreground when the container starts
RUN echo "Downloading https://sendy.co/download/?license=${SENDY_LICENSE_KEY}" \
&& curl -L -o sendy.zip https://sendy.co/download/?license=${SENDY_LICENSE_KEY} \
&& unzip sendy.zip -d /tmp \
&& rm -rf /tmp/sendy/uploads \
&& rsync -av /tmp/sendy/ /var/www/html/ \
&& rm sendy.zip \
&& rm -rf /tmp/sendy \
&& chown -R www-data:www-data /var/www/html \
&& chmod -R 755 /var/www/html \
|| echo "🚨 Something went wrong with the sendy download, if this is the first time you start this docker stack, this means sendy will not work. If this is not the first time, this means sendy did not auto-update. Please check if the link is live: https://sendy.co/download/?license=${SENDY_LICENSE_KEY}"

#RUN echo "$CONFIG_FILE" > /var/www/html/includes/config.php

COPY config.php /var/www/html/includes/config.php

CMD php-fpm82 -D; nginx -g "daemon off;"
define('APP_PATH', 'https://'.getenv('RAILWAY_PUBLIC_DOMAIN'));

echo getenv('MYSQLHOST');

/* MySQL database connection credentials (please place values between the apostrophes) */
$dbHost = getenv('MYSQLHOST'); //MySQL Hostname
$dbUser = getenv('MYSQLUSER'); //MySQL Username
$dbPass = getenv('MYSQLPASSWORD'); //MySQL Password
$dbName = getenv('MYSQL_DATABASE'); //MySQL Database Name
//----------------------------------------------------------------------------------//
// OPTIONAL SETTINGS
//----------------------------------------------------------------------------------//

/*
Change the database character set to something that supports the language you'll
be using. Example, set this to utf16 if you use Chinese or Vietnamese characters
*/
$charset = 'utf8mb4';

/* Set this if you use a non standard MySQL port. */
$dbPort = getenv('MYSQLPORT');

/* Domain of cookie (99.99% chance you don't need to edit this at all) */
define('COOKIE_DOMAIN', '');
define('APP_PATH', 'https://'.getenv('RAILWAY_PUBLIC_DOMAIN'));

echo getenv('MYSQLHOST');

/* MySQL database connection credentials (please place values between the apostrophes) */
$dbHost = getenv('MYSQLHOST'); //MySQL Hostname
$dbUser = getenv('MYSQLUSER'); //MySQL Username
$dbPass = getenv('MYSQLPASSWORD'); //MySQL Password
$dbName = getenv('MYSQL_DATABASE'); //MySQL Database Name
//----------------------------------------------------------------------------------//
// OPTIONAL SETTINGS
//----------------------------------------------------------------------------------//

/*
Change the database character set to something that supports the language you'll
be using. Example, set this to utf16 if you use Chinese or Vietnamese characters
*/
$charset = 'utf8mb4';

/* Set this if you use a non standard MySQL port. */
$dbPort = getenv('MYSQLPORT');

/* Domain of cookie (99.99% chance you don't need to edit this at all) */
define('COOKIE_DOMAIN', '');
Brody
Brody•10mo ago
side note, you only need ARG SENDY_LICENSE_KEY not any of the other ARG or ENV stuff becuse the rest arent used during build
kmskrishna
kmskrishna•10mo ago
I got one question - MYSQLPORT variable is for public URL port right. is there any such for private url port. that is the default 3306 because I would want to control both hostname and port from the variables and is there any variable that is defined by Railway that I can directly use for MYSQLPORT
Brody
Brody•10mo ago
ideally there would be a pre defined MYSQLPORT_PRIVATE variable for you to reference, but unfortunately there isnt, so instead you can do MYSQLPORT=${{MySQL.RAILWAY_TCP_APPLICATION_PORT}} https://docs.railway.app/reference/variables#railway-provided-variables
kmskrishna
kmskrishna•10mo ago
I am doing more digging on my own. Will let you know if I make any progress.
Brody
Brody•10mo ago
did that alpine variable not work?
kmskrishna
kmskrishna•10mo ago
I am using those variables so that my local Docker builds work
Brody
Brody•10mo ago
have you set ENABLE_ALPINE_PRIVATE_NETWORKING=true as a service variable on railway?
kmskrishna
kmskrishna•10mo ago
Nope. Trying that. That seems to have fixed the issue. using that variable.
Brody
Brody•10mo ago
great!
kmskrishna
kmskrishna•10mo ago
also do you know any good way to set the server_name parameter in nginx.conf using env variable I found some complex ways like using some nginx lua scripts and all.
Brody
Brody•10mo ago
nginx/nginx.conf doesn’t natively support environment variable expansion, Caddy does however, might be worth to switch to Caddy and its frakenphp module but if setting setting server_name to an environment variable is all you want to do, then setting it to localhost is perfectly fine
kmskrishna
kmskrishna•10mo ago
that will still server the content? nice1
Brody
Brody•10mo ago
thats what railway does and they still do variable expansion https://github.com/railwayapp/nixpacks/blob/main/src/providers/php/nginx.template.conf#L27
kmskrishna
kmskrishna•10mo ago
the nginx is doing a lot of rewrites on the URLs. it would be a pain to switch them to caddy.
Brody
Brody•10mo ago
thats fair
kmskrishna
kmskrishna•10mo ago
Once this is done, I will try to publish this template. Would be my first.
Brody
Brody•10mo ago
that would be a very nice addition, feel free to ping me if you want any template related feedback!
kmskrishna
kmskrishna•10mo ago
I enabled writing nginx logs to stdout. I think I will also enable php-fpm logs as well.
Brody
Brody•10mo ago
sounds good to me
kmskrishna
kmskrishna•10mo ago
also I think it would be cool if railway shell would automatically change the DB url to public url in env variables. Would make my life easier while running stuff locally.
Brody
Brody•10mo ago
you could have a dev environment that has the url set to the public one
Want results from more Discord servers?
Add your server