I need to increase the upload_max_filesize
directive in php.ini
to allow images over 2MB
to upload to my Laravel site, which is deployed in Railway
using Nixpacks
.
I've already tried to include some init_set('upload_max_filesize', '100M')
in my routes, including this directive in the nginx.conf
, and adding the environment variable PHP_INI_UPLOAD_MAX_FILESIZE
in Railway
. None of these solutions worked.
How can I modify the php.ini
while using Nixpacks
in Railway
?
Although I could not find any solution to do this using Nixpacks
, I finally ended up adding a Dockerfile
in the root folder of the project to do the deployment with docker. If Railways detects a Dockerfile
in the root folder, it automatically executes the deployment using it.
Here the Dockerfile
I used which is working fine with a Laravel app:
FROM php:8.1-apache
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Set up node and npm
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash
RUN apt-get update && apt-get -y install nodejs
# Set working directory
WORKDIR /var/www
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
WORKDIR /var/www/html
COPY . .
#Modify php.ini setings
RUN touch /usr/local/etc/php/conf.d/uploads.ini \
&& echo "upload_max_filesize = 10M;" >> /usr/local/etc/php/conf.d/uploads.ini
#Serve the application
RUN composer install
RUN npm install
CMD php artisan migrate --force && php artisan storage:link && php artisan serve --host=0.0.0.0 --port=$PORT