2 years ago
I have an old application. How can i make build in service?
242 Replies
2 years ago
You would need to write a Dockerfile to use unsupported php versions
2 years ago
@Thomas Mendonça are you brazilian? if so, do you mind upvoting this community suggestion ? Bora trazer o Railway pro Brasil 😉
2 years ago
Also, I'll send you a dockerfile example
2 years ago
Do you use Composer or Artisan?
2 years ago
Ok, one sec
2 years ago
This is my dockerfile using php 7.4 and composer
FROM composer:2.4.4 AS composer
FROM php:7.4-fpm as base
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
#UPDATE
RUN apt-get update
#INSTALL DEPS
RUN apt-get install -y \
nginx \
supervisor \
zlib1g-dev \
libzip-dev \
libjpeg-dev \
libxml2-dev \
libonig-dev \
libicu-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev
#SETUP PHP EXTENSIONS
RUN docker-php-ext-install gd soap zip intl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
FROM base as config
#COPY NGINX AND SUPERVISOR CONF
COPY default.conf /etc/nginx/conf.d/default.conf
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
FROM config as app
WORKDIR /var/www/html
COPY . .
RUN composer install --ignore-platform-req=ext-bcmath --no-dev
EXPOSE 8080
CMD ["/usr/bin/supervisord"]2 years ago
default.conf
server {
listen 8080;
server_name 0.0.0.0;
root /var/www/html;
# pass the PHP scripts to FastCGI server
# listening on 127.0.0.1:9000
location / {
try_files $uri /public/index.php?q=$uri&$args;
}
# comment vv
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
}
}2 years ago
supervisor.conf
```[supervisord]
nodaemon=true
[program:nginx]
command=nginx -g "daemon off;"
autostart=true
autorestart=true
stdoutlogfile=/dev/stdout stdoutlogfilemaxbytes=0 stderrlogfile=/dev/stderr
stderrlogfilemaxbytes=0
[program:php-fpm]
command=php-fpm
autostart=true
autorestart=true
stdoutlogfile=/dev/stdout stdoutlogfilemaxbytes=0 stderrlogfile=/dev/stderr
stderrlogfilemaxbytes=0```
2 years ago
this is also an old project, lol
2 years ago
It just doesn't has artisan
2 years ago
you shouldn't have to
2 years ago
full build logs please -
2 years ago
change php:7.4-fpm to php:7.3-fpm
2 years ago
There's some incompatibilities between the two
2 years ago
This new minor version brings with it a number of new features and a few incompatibilities that should be tested for before switching PHP versions in production environments.
2 years ago
build logs again please
2 years ago
im not the php guy, you will have to wait for a response from medim, please be patient as this is community support
2 years ago
replace it to php:7.3-fpm-alpine
2 years ago
i'm wondering if docker-ext exists in php:7.3-fpm by default 🤔
2 years ago
im sure the alpine one does tho
2 years ago
going forward, please only send the logs you get from the bookmarklet, the screenshots are not very helpful
2 years ago
alpine doesn't has apt-get lmao
2 years ago
wait a sec
2 years ago
one sec, i'm redoing the dockerfile to be alpine based
2 years ago
FROM composer:2.4.4 AS composer
FROM php:7.3-fpm-alpine as base
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
#INSTALL DEPS
RUN apk update && \
apk add --no-cache \
nginx \
supervisor \
zlib-dev \
libzip-dev \
libjpeg-turbo-dev \
libpng-dev \
freetype-dev \
libxml2-dev \
oniguruma-dev \
icu-dev
#SETUP PHP EXTENSIONS
RUN docker-php-ext-install gd soap zip intl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
FROM base as config
#COPY NGINX AND SUPERVISOR CONF
COPY default.conf /etc/nginx/conf.d/default.conf
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
FROM config as app
WORKDIR /var/www/html
COPY . .
RUN composer install --ignore-platform-req=ext-bcmath --no-dev
EXPOSE 8080
CMD ["/usr/bin/supervisord"]2 years ago
let's see the next error lmao
2 years ago
(it prob won't gonna find one of those packages since i migrated debian to alpine-linux)
2 years ago
💀
2 years ago
what is weird is that it runs the docker-php-ext in line 21 but no the one that configures gd
2 years ago
you can try removing that line entirely if your app doesn't rely on gd
2 years ago
or try changing it to RUN docker-php-ext-configure gd \ --with-freetype \ --with-png \ --with-jpeg
2 years ago
Image manipulation
2 years ago
whitespaces?
2 years ago
^
2 years ago
tbh just remove that entire line
2 years ago
if its needed we'll find a way to add it
2 years ago
lets get that app up first
2 years ago
FROM composer:2.4.4 AS composer
FROM php:7.3-fpm-alpine as base
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
#INSTALL DEPS
RUN apk update && \
apk add --no-cache \
nginx \
supervisor \
zlib-dev \
libzip-dev \
libjpeg-turbo-dev \
libpng-dev \
freetype-dev \
libxml2-dev \
oniguruma-dev \
icu-dev
#SETUP PHP EXTENSIONS
RUN docker-php-ext-install soap zip intl
FROM base as config
#COPY NGINX AND SUPERVISOR CONF
COPY default.conf /etc/nginx/conf.d/default.conf
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
FROM config as app
WORKDIR /var/www/html
COPY . .
RUN composer install --ignore-platform-req=ext-bcmath --no-dev
EXPOSE 8080
CMD ["/usr/bin/supervisord"]2 years ago
almost there, lol
2 years ago
FROM composer:2.4.4 AS composer
FROM php:7.3-fpm-alpine as base
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
#INSTALL DEPS
RUN apk update && \
apk add --no-cache \
nginx \
supervisor \
zlib-dev \
libzip-dev \
libjpeg-turbo-dev \
libpng-dev \
freetype-dev \
libxml2-dev \
oniguruma-dev \
icu-dev \
git
#SETUP PHP EXTENSIONS
RUN docker-php-ext-install soap zip intl
FROM base as config
#COPY NGINX AND SUPERVISOR CONF
COPY default.conf /etc/nginx/conf.d/default.conf
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
FROM config as app
WORKDIR /var/www/html
COPY . .
RUN composer install --ignore-platform-req=ext-bcmath --no-dev
EXPOSE 8080
CMD ["/usr/bin/supervisord"]2 years ago
it installs from source, we need git
Install Git
RUN apk update && apk add --no-cache
INSTALL DEPS
RUN apk update && \
apk add --no-cache \
nginx \
2 years ago
edited it, forgot to remove that line
2 years ago
also, do you got the default.conf and supervisord.conf at the same dir level as your dockerfile?
2 years ago
yeah it needs gd
2 years ago
lmao
2 years ago
FROM composer:2.4.4 AS composer
FROM php:7.3-fpm-alpine as base
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
#INSTALL DEPS
RUN apk update && \
apk add --no-cache \
nginx \
supervisor \
zlib-dev \
libzip-dev \
libjpeg-turbo-dev \
libpng-dev \
freetype-dev \
libxml2-dev \
oniguruma-dev \
icu-dev \
git
#SETUP PHP EXTENSIONS
RUN docker-php-ext-install gd soap zip intl
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
FROM base as config
#COPY NGINX AND SUPERVISOR CONF
COPY default.conf /etc/nginx/conf.d/default.conf
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
FROM config as app
WORKDIR /var/www/html
COPY . .
RUN composer install --ignore-platform-req=ext-bcmath --no-dev
EXPOSE 8080
CMD ["/usr/bin/supervisord"]2 years ago
re added GD with some php 7.2 args
2 years ago
this help thread made my remember my hate for php in prod
2 years ago
also, good thing railway doesn't charge build time
2 years ago
you are using a github repo as package in composer
2 years ago

2 years ago
hmm..
2 years ago
is it needed?
2 years ago
seems like its a private repo
2 years ago
and its a hassle since you would need to generate SSH keys just to clone them with composer but its a bad idea to upload your SSH keys to your repo so you would need repo secrets… so lets avoid all that
2 years ago
..did it build?
2 years ago
prob some nginx config
2 years ago
@Brody I set a 8080 port in my server.listen so I guess he would need to add a PORT=8080 env var?
2 years ago
.
2 years ago
@Thomas Mendonça create a PORT=8080 env var
2 years ago
we may need to mess a bit with the default.conf now, since I use that specific config to fastcgi
2 years ago
no errors
2 years ago
just wait
2 years ago
try refreshing it
2 years ago
<:thonking:573392943260631050>
2 years ago
can you send the url here?
2 years ago
Thomas, where did you set the env var
2 years ago
(I also think there's some issues with the default.conf)
2 years ago
would you mind answering this question
APPENV=local APPDEBUG=true
APPKEY= DBHOST=
DBDATABASE= DBUSERNAME=
DB_PASSWORD=
PORT=8080
2 years ago
can you please answer the question
2 years ago
Did u set it in the Railway Env tab or locally?
2 years ago

2 years ago
@Brody would it be too hard to migrate from nginx to caddy?
2 years ago
if you where familiar with the technologies involved, no
2 years ago
try this default.conf
server {
listen 8080;
server_name 0.0.0.0;
root /var/www/html/public; # Adjust the root directory to point to the public directory of your Laravel app
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}2 years ago
laravel serves in the /public folder
2 years ago
saw you mentioning it, I forgot about that
2 years ago
Anything in the logs?
2 years ago
yes.
2 years ago
I'm out of ideas <:PepeCRY:1214283858267348992>
we got it to build and deploy but I suck at nginx
2 years ago
we can try the default conf from laravel docs
2 years ago
```server {
listen 8080;
listen [::]:8080;
server_name 0.0.0.0;
root /var/www/html/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}}```
2 years ago
That's normal, just supervisord starting things up
2 years ago
<:sadcat:786868978382536704>
2 years ago
English only please
2 years ago
U are now listening to port 80
2 years ago
So that env var u set at railway should also be 80 but if it works I guess u alrady did that
2 years ago
But seems like file serving is still a bit off since it says 404
2 years ago
Is it an API? you can try doing a request to it
I managed to find an error on port 9000, already in use. With this information, can you help me with any solution tips?
2 years ago
Its already in use by the fastcgi
2 years ago
oh nvm, u changed it to 80
2 years ago
fastcgi port can't be the same as your listen port afaik, so put like listen on 80 and fastcgi port on a number > 1000
2 years ago
and what did u do to hit that error?
2 years ago
maybe that was the error this entire time, try changing it to like 8080, also you cannot use fastcgi as a unix socket, last time I used it like this on railway it wouldn't work pecause of specific perms.
it needs to be on a port
2 years ago
@Thomas Mendonça
2 years ago
send ur default.conf here for me to edit it
2 years ago
just change the listen to listen 80;
2 years ago
(also change the env var in railway to 80)
2 years ago
that default conf won't work locally
2 years ago
that's railway specific
2 years ago
to run locally:
change server_name to localhost
to run on railway:
change server_name to 0.0.0.0
2 years ago
404?
2 years ago
yeah, I don't know what to do anymore lmao
Hey idk if this will help at allll BUT i also use laravel on railway and these are my build cmds
composer install && php artisan optimize:clear && php artisan migrate --force && php artisan storage:linki dont use any form of changes than those cmds, no custom railway conf or anything
Guys, I come to you to let you know that it worked!
It was difficult, but I managed to solve it. If you want, I'll put the 3 files here.
I am very grateful to those who helped me and spent time working with me to resolve it. A special hug to @Medim , who was great!
2 years ago
Share them here @Thomas Mendonça
2 years ago
So I can see what I missed






