如何使用Railway Nixpacks修改php.ini?

huangapple go评论92阅读模式
英文:

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 应用中正常工作:

  1. FROM php:8.1-apache
  2. # 在docker-compose.yml中定义的参数
  3. ARG user
  4. ARG uid
  5. # 安装系统依赖项
  6. RUN apt-get update && apt-get install -y \
  7. git \
  8. curl \
  9. libpng-dev \
  10. libonig-dev \
  11. libxml2-dev \
  12. zip \
  13. unzip
  14. # 清除缓存
  15. RUN apt-get clean && rm -rf /var/lib/apt/lists/*
  16. # 安装 PHP 扩展
  17. RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
  18. # 获取最新的 Composer
  19. COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
  20. # 设置 node 和 npm
  21. RUN curl -sL https://deb.nodesource.com/setup_18.x | bash
  22. RUN apt-get update && apt-get -y install nodejs
  23. # 设置工作目录
  24. WORKDIR /var/www
  25. RUN apt-get update && apt-get install -y \
  26. libfreetype6-dev \
  27. libjpeg62-turbo-dev \
  28. libpng-dev \
  29. && docker-php-ext-configure gd --with-freetype --with-jpeg \
  30. && docker-php-ext-install -j$(nproc) gd
  31. WORKDIR /var/www/html
  32. COPY . .
  33. # 修改 php.ini 设置
  34. RUN touch /usr/local/etc/php/conf.d/uploads.ini \
  35. && echo "upload_max_filesize = 10M;" >> /usr/local/etc/php/conf.d/uploads.ini
  36. # 启动应用程序
  37. RUN composer install
  38. RUN npm install
  39. 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:

  1. FROM php:8.1-apache
  2. # Arguments defined in docker-compose.yml
  3. ARG user
  4. ARG uid
  5. # Install system dependencies
  6. RUN apt-get update && apt-get install -y \
  7. git \
  8. curl \
  9. libpng-dev \
  10. libonig-dev \
  11. libxml2-dev \
  12. zip \
  13. unzip
  14. # Clear cache
  15. RUN apt-get clean && rm -rf /var/lib/apt/lists/*
  16. # Install PHP extensions
  17. RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
  18. # Get latest Composer
  19. COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
  20. # Set up node and npm
  21. RUN curl -sL https://deb.nodesource.com/setup_18.x | bash
  22. RUN apt-get update && apt-get -y install nodejs
  23. # Set working directory
  24. WORKDIR /var/www
  25. RUN apt-get update && apt-get install -y \
  26. libfreetype6-dev \
  27. libjpeg62-turbo-dev \
  28. libpng-dev \
  29. && docker-php-ext-configure gd --with-freetype --with-jpeg \
  30. && docker-php-ext-install -j$(nproc) gd
  31. WORKDIR /var/www/html
  32. COPY . .
  33. #Modify php.ini setings
  34. RUN touch /usr/local/etc/php/conf.d/uploads.ini \
  35. && echo "upload_max_filesize = 10M;" >> /usr/local/etc/php/conf.d/uploads.ini
  36. #Serve the application
  37. RUN composer install
  38. RUN npm install
  39. CMD php artisan migrate --force && php artisan storage:link && php artisan serve --host=0.0.0.0 --port=$PORT

huangapple
  • 本文由 发表于 2023年5月25日 20:45:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76332419.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定