R
Railway11mo ago
wdytgn

Getting 413 Request Entity Too Largenginx/1.24.0

Hey guys so i have deployed my applications via github, which is laravel app, when i upload images which is only 1.1MB, it said that the request entity too large. How can i solve this? please send me any help since i'm new on deploying and stuff
Solution:
place these two files into the root of your project
Jump to solution
44 Replies
MantisInABox
MantisInABox11mo ago
This is an issue with the default nginx configuration. Your file exceeds the default client_max_body_size which can be configured through nginx. I am not 100% sure on how to adjust it within Railway, but adjusting this value would help significantly. Let me see if I can figure it out for you. This could also be an issue with the php configuration in the container... the php.ini you can change upload_max_filesize and post_max_size
wdytgn
wdytgnOP11mo ago
thanks for replying btw, how to configure the php.ini? i dont have any file named php.ini, should i create it instead? and pull it to my main branch?
Brody
Brody11mo ago
vin is working on a drop in solution, stay tuned
MantisInABox
MantisInABox11mo ago
Then let me know if your upload works for you
wdytgn
wdytgnOP11mo ago
hey i just lost the solution that u sent me before, could u please resend it?
MantisInABox
MantisInABox11mo ago
Brody deleted the message by accident, but could you place a file in the root of your project called nixpacks.toml then paste the following in EXACTLY as you see it. Then redeploy and try your upload
[phases.setup]
cmds = ['echo "upload_max_filesize=100M;" >> /nix/store/rzcijhxwxbld02mpvx288nf6bzv7ybhz-php-with-extensions-8.2.10/lib/php.ini', 'echo "post_max_size=100M;" >> /nix/store/rzcijhxwxbld02mpvx288nf6bzv7ybhz-php-with-extensions-8.2.10/lib/php.ini']
[phases.setup]
cmds = ['echo "upload_max_filesize=100M;" >> /nix/store/rzcijhxwxbld02mpvx288nf6bzv7ybhz-php-with-extensions-8.2.10/lib/php.ini', 'echo "post_max_size=100M;" >> /nix/store/rzcijhxwxbld02mpvx288nf6bzv7ybhz-php-with-extensions-8.2.10/lib/php.ini']
wdytgn
wdytgnOP11mo ago
okay lemme try it
Brody
Brody11mo ago
it wasn’t by accident 🤣
wdytgn
wdytgnOP11mo ago
you mean here right and then i got this
Dockerfile:25

-------------------

23 | # build phase

24 | COPY . /app/.

25 | >>> RUN composer install && php artisan optimize && php artisan storage:link && php artisan migrate --force --seed

26 |

27 |

-------------------

ERROR: failed to solve: process "/bin/bash -ol pipefail -c composer install && php artisan optimize && php artisan storage:link && php artisan migrate --force --seed" did not complete successfully: exit code: 1



Error: Docker build failed
Dockerfile:25

-------------------

23 | # build phase

24 | COPY . /app/.

25 | >>> RUN composer install && php artisan optimize && php artisan storage:link && php artisan migrate --force --seed

26 |

27 |

-------------------

ERROR: failed to solve: process "/bin/bash -ol pipefail -c composer install && php artisan optimize && php artisan storage:link && php artisan migrate --force --seed" did not complete successfully: exit code: 1



Error: Docker build failed
No description
MantisInABox
MantisInABox11mo ago
Okay, you can remove it. Back to the drawing board for me
wdytgn
wdytgnOP11mo ago
No description
wdytgn
wdytgnOP11mo ago
okayy
MantisInABox
MantisInABox11mo ago
Wait no. You didn't commit the file properly You need to copy everything I sent, exactly how I sent it including the [phases.setup]
wdytgn
wdytgnOP11mo ago
ah okayy wait sorry my bad bro
wdytgn
wdytgnOP11mo ago
still failed vin \
No description
No description
MantisInABox
MantisInABox11mo ago
You didn't change anything else in your repo, other than the nixpacks.toml correct?
wdytgn
wdytgnOP11mo ago
yes i didnt change anything
MantisInABox
MantisInABox11mo ago
And there were no errors before?
wdytgn
wdytgnOP11mo ago
no it was successfully deployed
wdytgn
wdytgnOP11mo ago
No description
MantisInABox
MantisInABox11mo ago
Okay, you can delete the nixpacks.toml file, and in the meantime, can you tell me if this Dockerfile works? Create Dockerfile in the root of your repo, and paste EXACTLY how it is here
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 = 100M;" >> /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
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 = 100M;" >> /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
If this doesn't work, I will have to try something else
wdytgn
wdytgnOP11mo ago
okayy, wait for a while, lemme try
wdytgn
wdytgnOP11mo ago
is it okay if the docker file using php:8.1 and my composer.json use 8.2?
No description
MantisInABox
MantisInABox11mo ago
That should be fine, if it gives you an error, you can change the dockerfile first line to be 8.2-apache
wdytgn
wdytgnOP11mo ago
No description
MantisInABox
MantisInABox11mo ago
Hmmmm
wdytgn
wdytgnOP11mo ago
i changed it into php:8.2-apache, and its now still deploying, at least the build was successful the deployment was successful, but why am i getting the page expired after uploading the image? hey its deployed now but the page is expired it said php artisan serve --host=0.0.0.0 --port=$PORT do i really need this?
wdytgn
wdytgnOP11mo ago
it's all good when running in local?
No description
Brody
Brody11mo ago
please revert to a working state, no dockerfile, no nixpacks.toml, etc
wdytgn
wdytgnOP11mo ago
okay brody, how bout the getting 413?
Brody
Brody11mo ago
you had this working at one point before opening this thread, right?
wdytgn
wdytgnOP11mo ago
yes, the page is okay, but when the users upload the profile picture that is larger than 1M, the server would return 413
Brody
Brody11mo ago
thats fine, please revert to that state
wdytgn
wdytgnOP11mo ago
okay after i revert to that state, when i try to login, it would go back to login form again the data i entered is correct
Brody
Brody11mo ago
please get your app into a state where it works before we try to tackle the file upload issue again
wdytgn
wdytgnOP11mo ago
wow it worked thank you for helping me
Brody
Brody11mo ago
what worked
wdytgn
wdytgnOP11mo ago
reverting the state but i still havent figured how to solve the 413
Brody
Brody11mo ago
so you are in a position now where you could deploy your code again and it would work (ignoring the file upload issue)
wdytgn
wdytgnOP11mo ago
yes that is correct
Solution
Brody
Brody11mo ago
place these two files into the root of your project
Brody
Brody11mo ago
without them, i can reproduce the 413 error, with then, my file uploads without issue
wdytgn
wdytgnOP11mo ago
okay brody, lemme try thank uuuu sooo much Brody it worked all hail thanks also Vin it means so much to me since this deployment for my final project (pre-grad) haha keep shining bro
Brody
Brody11mo ago
happy to help 🙂
Want results from more Discord servers?
Add your server