Custom Build Command for Laravel app
ilvalerione
PROOP

12 days ago

Railway for PHP/Laravel application install composer dependecies with "composer install" command. This command includes the dev dependendencies I need to exclude instead.

Looking at the Railway documentation I can se a "Custom Build Command": https://docs.railway.com/builds/build-and-start-commands

My Laravel app not only need to install composer packages but also it has a Vuejs frontend that needs to be built.

Looking at the build logs in my application service it shows a lot of operations. How can I customize only the composer command leaving all other build steps unchanged?

$20 Bounty

5 Replies

Status changed to Awaiting Railway Response Railway 12 days ago


You can use a custom Railpack configuration (https://railpack.com/config/file) or a Dockerfile.


ilvalerione
PROOP

12 days ago

My doubt is: Do a custom configuration file replace the entire build process? Because I need to customize only one command, and I don't know anything about all the other operations or commands railpack run at build time. How can I replace only the part I need to change? Do the "railpack.json" file only replace steps I define into? Or do it replace the entire build process? Is there something in the build logs of the service that I can use to understand how to replace only the step I need to change?


You can’t only modify one part of the process. It’s more of a “modify it entirely or you don’t” type of situation. You could probably get an AI agent (eg, Claude or ChatGPT) to create a custom Dockerfile for you.


12 days ago

A railpack.json config does not replace the whole build. It layers on top of the auto-detected plan, so any step you don't define stays exactly as detected. If you only want to change how dependencies are installed, you define just the install step's commands and everything else, including your Vue frontend build, keeps running unchanged. You can see the per-step override syntax, including the "..." form that appends your command after the auto-generated ones rather than replacing them, at railpack.com/config/file. The "Custom Build Command" field in service settings is different: that one overrides the build phase as a whole, which is why the config file is the better fit when you only want to touch one step.


Status changed to Awaiting User Response Railway 12 days ago


ilvalerione
PROOP

12 days ago

Reading the build logs from standard Railway deployments I see this steps:

Steps

──────────

▸ prepare

$ mkdir -p /usr/local/etc/php/conf.d


$ mkdir -p /conf.d/

▸ extensions

$ install-php-extensions intl bcmath pcntl zip gd ctype curl dom fileinfo filter hash mbstring openssl pcre pdo session tokenizer xml pdo_mysql redis

▸ install:composer

$ composer install --optimize-autoloader --no-scripts --no-interaction

▸ install:node

$ npm ci

▸ prune:node

$ npm prune --omit=dev --ignore-scripts

▸ build

$ npm run build


$ mkdir -p storage/framework/{sessions,views,cache,testing} storage/logs bootstrap/cache && chmod -R a+rw storage


$ php artisan config:cache


$ php artisan event:cache


$ php artisan route:cache


$ php artisan view:cache

It seems composer install is named "install:conposer"

Is this a correct railway config file to override only that step?

{

"$schema": "https://schema.railpack.com",

"steps": {

  "install:composer": {

    "commands": ["composer install --optimize-autoloader --no-scripts --no-interaction --no-dev"]

  }

}

}


Status changed to Awaiting Railway Response Railway 12 days ago


Railway
BOT

12 days ago

This thread has been opened as a bounty so the community can help solve it.

Status changed to Open Railway 12 days ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...