Build PHP 7.3 with Laravel. How can i do it?

thomaslegal10PRO

a year ago

I have an old application. How can i make build in service?

0 Replies

thomaslegal10PRO

a year ago

N/A


thomaslegal10PRO

a year ago

Project ID: N/A


a year ago

You would need to write a Dockerfile to use unsupported php versions


thomaslegal10PRO

a year ago

Okay. I need a Dockerfile.


thomaslegal10PRO

a year ago

Have a application, but i have questions about how make it.


thomaslegal10PRO

a year ago

Can send me?


a year ago

@Thomas Mendonça are you brazilian? if so, do you mind upvoting this community suggestion ? Bora trazer o Railway pro Brasil 😉


a year ago

Also, I'll send you a dockerfile example


a year ago

Do you use Composer or Artisan?


thomaslegal10PRO

a year ago

Both


thomaslegal10PRO

a year ago

Yeah!! I am Brazilian ❤️


thomaslegal10PRO

a year ago

I need composer run my Laravel project


a year ago

Ok, one sec


thomaslegal10PRO

a year ago

Okay


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

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

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


a year ago

this is also an old project, lol


a year ago

It just doesn't has artisan


thomaslegal10PRO

a year ago

Okay


thomaslegal10PRO

a year ago

I will try here


thomaslegal10PRO

a year ago

Need I to config something in Railway settings?


a year ago

you shouldn't have to


thomaslegal10PRO

a year ago

okay


thomaslegal10PRO

a year ago

1230193023971758300


thomaslegal10PRO

a year ago

Error 😢


a year ago

full build logs please -


thomaslegal10PRO

a year ago


a year ago

change php:7.4-fpm to php:7.3-fpm


a year ago

There's some incompatibilities between the two


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


thomaslegal10PRO

a year ago

Okay, one sec


thomaslegal10PRO

a year ago

error

1230196689164308500


a year ago

build logs again please


thomaslegal10PRO

a year ago


thomaslegal10PRO

a year ago

There is, my bro


a year ago

im not the php guy, you will have to wait for a response from medim, please be patient as this is community support


a year ago

replace it to php:7.3-fpm-alpine


a year ago

i'm wondering if docker-ext exists in php:7.3-fpm by default 🤔


a year ago

im sure the alpine one does tho


thomaslegal10PRO

a year ago

okay, one sec


thomaslegal10PRO

a year ago

haha no problem, I will wait.


thomaslegal10PRO

a year ago

thanks for you help


thomaslegal10PRO

a year ago

1230199842655965400


thomaslegal10PRO

a year ago

hehe fail again


thomaslegal10PRO

a year ago

:"(


a year ago

going forward, please only send the logs you get from the bookmarklet, the screenshots are not very helpful


a year ago

alpine doesn't has apt-get lmao


a year ago

wait a sec


thomaslegal10PRO

a year ago

Ow, okay.


a year ago

one sec, i'm redoing the dockerfile to be alpine based


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

a year ago

let's see the next error lmao


a year ago

(it prob won't gonna find one of those packages since i migrated debian to alpine-linux)


thomaslegal10PRO

a year ago

ok


thomaslegal10PRO

a year ago

one minute


thomaslegal10PRO

a year ago

1230203860761575400


thomaslegal10PRO

a year ago


a year ago

💀


a year ago

what is weird is that it runs the docker-php-ext in line 21 but no the one that configures gd


a year ago

you can try removing that line entirely if your app doesn't rely on gd


a year ago

or try changing it to RUN docker-php-ext-configure gd \ --with-freetype \ --with-png \ --with-jpeg


thomaslegal10PRO

a year ago

okay


thomaslegal10PRO

a year ago

what's gd?


a year ago

Image manipulation


thomaslegal10PRO

a year ago

Ah okay


thomaslegal10PRO

a year ago

one sec


thomaslegal10PRO

a year ago

1230206530947776500


a year ago

whitespaces?


a year ago

^


a year ago

tbh just remove that entire line


a year ago

if its needed we'll find a way to add it


a year ago

lets get that app up first


thomaslegal10PRO

a year ago

Okay


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

thomaslegal10PRO

a year ago


a year ago

almost there, lol


thomaslegal10PRO

a year ago

hehe


thomaslegal10PRO

a year ago

yeah


thomaslegal10PRO

a year ago

more one


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

a year ago

it installs from source, we need git


thomaslegal10PRO

a year ago

RUN apk update && apk add --no-cache again?


thomaslegal10PRO

a year ago

twice?


thomaslegal10PRO

a year ago

Install Git

RUN apk update && apk add --no-cache

INSTALL DEPS

RUN apk update && \
apk add --no-cache \
nginx \


a year ago

edited it, forgot to remove that line


thomaslegal10PRO

a year ago

ah


thomaslegal10PRO

a year ago

okay


a year ago

also, do you got the default.conf and supervisord.conf at the same dir level as your dockerfile?


thomaslegal10PRO

a year ago

yes, i do


thomaslegal10PRO

a year ago

building…


thomaslegal10PRO

a year ago


a year ago

yeah it needs gd


a year ago

lmao


thomaslegal10PRO

a year ago

Oh God


thomaslegal10PRO

a year ago

And now?


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

a year ago

re added GD with some php 7.2 args


a year ago

this help thread made my remember my hate for php in prod


a year ago

also, good thing railway doesn't charge build time


thomaslegal10PRO

a year ago

Yeah hehe


thomaslegal10PRO

a year ago

So good


thomaslegal10PRO

a year ago


thomaslegal10PRO

a year ago

error


a year ago

you are using a github repo as package in composer


a year ago

1230214536519225300


a year ago

hmm..


thomaslegal10PRO

a year ago

okay


thomaslegal10PRO

a year ago

i will remove


thomaslegal10PRO

a year ago

one minute


a year ago

is it needed?


a year ago

seems like its a private repo


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


thomaslegal10PRO

a year ago

i will remove, it is trash


a year ago

..did it build?


thomaslegal10PRO

a year ago

build complete


thomaslegal10PRO

a year ago

but don't show the default page


a year ago

prob some nginx config


thomaslegal10PRO

a year ago

I how put "/public"?


thomaslegal10PRO

a year ago

to publish


a year ago

@Brody I set a 8080 port in my server.listen so I guess he would need to add a PORT=8080 env var?


a year ago

.


a year ago

@Thomas Mendonça create a PORT=8080 env var


thomaslegal10PRO

a year ago

Oooh


thomaslegal10PRO

a year ago

this is the problem


thomaslegal10PRO

a year ago

!!


a year ago

we may need to mess a bit with the default.conf now, since I use that specific config to fastcgi


thomaslegal10PRO

a year ago

one minute


thomaslegal10PRO

a year ago

i will set port


thomaslegal10PRO

a year ago

ah fail


thomaslegal10PRO

a year ago

1230220183398908000


thomaslegal10PRO

a year ago


a year ago

no errors


a year ago

just wait


a year ago

try refreshing it


thomaslegal10PRO

a year ago

i do it


a year ago

<:thonking:573392943260631050>


a year ago

can you send the url here?


a year ago

Thomas, where did you set the env var


a year ago

(I also think there's some issues with the default.conf)



a year ago

would you mind answering this question


thomaslegal10PRO

a year ago

APPENV=local APPDEBUG=true
APPKEY= DBHOST=
DBDATABASE= DBUSERNAME=
DB_PASSWORD=
PORT=8080


a year ago

can you please answer the question


a year ago

Did u set it in the Railway Env tab or locally?


thomaslegal10PRO

a year ago

in the railway system variables


a year ago

1230222007052927200


thomaslegal10PRO

a year ago

Railway env tab


thomaslegal10PRO

a year ago

Railway env tab


a year ago

@Brody would it be too hard to migrate from nginx to caddy?


a year ago

if you where familiar with the technologies involved, no


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

a year ago

laravel serves in the /public folder


a year ago

saw you mentioning it, I forgot about that


thomaslegal10PRO

a year ago

Okay


thomaslegal10PRO

a year ago

Building…


thomaslegal10PRO

a year ago

One minute


thomaslegal10PRO

a year ago

nothing yet


thomaslegal10PRO

a year ago

"fastcgi_pass 127.0.0.1:9000;"


thomaslegal10PRO

a year ago

Is it right?


a year ago

Anything in the logs?


thomaslegal10PRO

a year ago


a year ago

yes.


a year ago

I'm out of ideas <:PepeCRY:1214283858267348992>
we got it to build and deploy but I suck at nginx


thomaslegal10PRO

a year ago

Ahh :/


thomaslegal10PRO

a year ago

So close



a year ago

we can try the default conf from laravel docs


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

}```


thomaslegal10PRO

a year ago

okay


thomaslegal10PRO

a year ago

One minute


thomaslegal10PRO

a year ago


a year ago

That's normal, just supervisord starting things up


thomaslegal10PRO

a year ago

Yeah


thomaslegal10PRO

a year ago

But same page


thomaslegal10PRO

a year ago

Application failed to respond



a year ago

<:sadcat:786868978382536704>


thomaslegal10PRO

a year ago

ô sufoco


thomaslegal10PRO

a year ago

very difficult


thomaslegal10PRO

a year ago


thomaslegal10PRO

a year ago

I was set this default.conf


thomaslegal10PRO

a year ago

Now is play life

1230246986930983000


thomaslegal10PRO

a year ago

Now is the problem


a year ago

English only please


thomaslegal10PRO

a year ago

Sorry


thomaslegal10PRO

a year ago

Someone help me?


a year ago

U are now listening to port 80


a year ago

So that env var u set at railway should also be 80 but if it works I guess u alrady did that


a year ago

But seems like file serving is still a bit off since it says 404


a year ago

Is it an API? you can try doing a request to it


thomaslegal10PRO

a year ago

Yeah, railway service on port 80


thomaslegal10PRO

a year ago

env


thomaslegal10PRO

a year ago

Web but not API


thomaslegal10PRO

a year ago

I managed to find an error on port 9000, already in use. With this information, can you help me with any solution tips?


a year ago

Its already in use by the fastcgi


a year ago

oh nvm, u changed it to 80


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


a year ago

and what did u do to hit that error?


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


a year ago

@Thomas Mendonça


a year ago

send ur default.conf here for me to edit it


thomaslegal10PRO

a year ago


a year ago

just change the listen to listen 80;


a year ago

(also change the env var in railway to 80)


thomaslegal10PRO

a year ago

i'm trying run local


thomaslegal10PRO

a year ago

not success


thomaslegal10PRO

a year ago

can you analize, please?


a year ago

that default conf won't work locally


a year ago

that's railway specific



thomaslegal10PRO

a year ago

the same problem, if run docker local, run in railway


a year ago

to run locally:
change server_name to [localhost](localhost)
to run on railway:
change server_name to 0.0.0.0


thomaslegal10PRO

a year ago

Aah okay


thomaslegal10PRO

a year ago

But the nginx, the same is error?


a year ago

404?


thomaslegal10PRO

a year ago

yeah


thomaslegal10PRO

a year ago

not found the app


a year ago

yeah, I don't know what to do anymore lmao


thomaslegal10PRO

a year ago

okay


thomaslegal10PRO

a year ago

one minute


thomaslegal10PRO

a year ago

i will try


definewaterHOBBY

a year ago

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:link

definewaterHOBBY

a year ago

its under Custom Build Command


definewaterHOBBY

a year ago

and just put this in


definewaterHOBBY

a year ago

i dont use any form of changes than those cmds, no custom railway conf or anything


thomaslegal10PRO

a year ago

Okay


thomaslegal10PRO

a year ago

What's PHP version?


thomaslegal10PRO

a year ago

@Faith


definewaterHOBBY

a year ago

its 8.2, it auto does it


definewaterHOBBY

a year ago

im using nixpacks


thomaslegal10PRO

a year ago

Good


thomaslegal10PRO

a year ago

Mine 7.3


thomaslegal10PRO

a year ago

😢


thomaslegal10PRO

a year ago

Knows someone how run PHP 7.3?


definewaterHOBBY

a year ago

a guy further up gave a composer with 7.3 try his


thomaslegal10PRO

a year ago

im try all


thomaslegal10PRO

a year ago

nothing that solved


thomaslegal10PRO

a year ago

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!


a year ago

Share them here @Thomas Mendonça


a year ago

So I can see what I missed