英文:
How can I modify php.ini using Railway Nixpacks?
问题
我需要增加php.ini中的upload_max_filesize指令,以允许上传超过2MB的图像到我的Laravel站点,该站点部署在Railway上,使用Nixpacks。
我已经尝试在我的路由中包含一些init_set('upload_max_filesize', '100M'),将此指令包含在nginx.conf中,并在Railway中添加了环境变量PHP_INI_UPLOAD_MAX_FILESIZE。这些解决方案都没有奏效。
在使用Nixpacks和Railway时,我该如何修改php.ini?
英文:
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?
答案1
得分: 0
以下是您要翻译的内容:
尽管我无法找到使用Nixpacks来执行此操作的解决方案,但最终我在项目的根目录中添加了一个Dockerfile来使用Docker进行部署。如果 Railways 在根目录中检测到一个Dockerfile,它会自动使用它来执行部署。
这是我使用的Dockerfile,它在 Laravel 应用中正常工作:
FROM php:8.1-apache
# 在docker-compose.yml中定义的参数
ARG user
ARG uid
# 安装系统依赖项
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip
# 清除缓存
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# 安装 PHP 扩展
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# 获取最新的 Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# 设置 node 和 npm
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash
RUN apt-get update && apt-get -y install nodejs
# 设置工作目录
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 . .
# 修改 php.ini 设置
RUN touch /usr/local/etc/php/conf.d/uploads.ini \
    && echo "upload_max_filesize = 10M;" >> /usr/local/etc/php/conf.d/uploads.ini
# 启动应用程序
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
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论