10

I was given an Amazon EC2 Ubuntu Instance. We are task to create a web application that includes uploading a client video. I have created a file upload application in my localhost and it is working fine. When I migrated the code to the virtual host server, I cannot upload any video and even any file that exceeds 2Mb. I tried editing the php.ini setting upload_max_filesize to 50M and post_max_size to 1000M.

After restarting Apache so many times, the update is not reflected in my phpinfo() information but changes were saved in my php.ini file.

enter image description here enter image description here

I was suspecting that the Amazon EC2 instance given to me has a file upload restrictions but Im not sure if Im right. If I was wrong, how can I override the configuration below? Any help would be very much appreciated.

UPDATE:

I even made sure that I was editing the correct configuration file. Below are the screen shots:

enter image description here

enter image description here

UPDATE:

I tried following what is said in the link with no luck. I have a lot of questions in mind about the link like:

  1. What does tomcatchesides mean about S3 bucket? I uploaded the config file in /var/www/html/.ebextensions . Am I doing the right thing?

My zzz.ini contains the code below and I place it in /etc/php.d/zzz.ini:

[php]
post_max_size = 1000M
upload_max_filesize = 50M

My myconfigfile.config was located in /var/www/html/.ebextensions/myconfigfile.config and contains the code below:

files:
  "/etc/php.ini":
    mode: "000644"
    owner: root
    group: root
    source: http://mybucketname.s3.amazonaws.com/php.ini

  "/etc/php.d/zzz.ini":
    mode: "000644"
    owner: root
    group: root
    source: http://mybucketname.s3.amazonaws.com/zzz.ini

How to know the bucket name of my instance?

I also copied my php.ini from /etc/php/7.0/apache2/php.ini to /etc/php.ini and restarted apache. Still no changes. Am I doing the right thing?

UPDATE:

I ask for the bucket name to the person who gave me the EC2 instance and her reply was.

Yes, you were given access to an EC2 instance. S3 is a different service provided by Amazon and that's not automatically available to EC2 instances. We can create a bucket in S3 for you but it may no longer be needed.

The EC2 instance has around 8GB storage space. You should be able to store multiple videos greater than 2MB in the EC2 file system and access them directly.

Using S3 for file uploads is a good idea especially when your software goes to production. However, to simplify the setup, please use the file system instead to store the videos.

UPDATE :

Running the following commands:

php -i | grep -i max_size

yields: post_max_size => 1000M => 1000M

grep -ir "max_size" /etc/php/7.0/apache2/conf.d/

yieds nothing.

grep -ir "max_size" /etc/php/7.0/

yields

/etc/php/7.0/fpm/php.ini:post_max_size = 1000M
/etc/php/7.0/apache2/php.ini:post_max_size = 1000M
/etc/php/7.0/cli/php.ini:post_max_size = 1000M

My phpinfo() can be access through this link

alyssaeliyah
  • 2,214
  • 6
  • 33
  • 80

3 Answers3

7

After changin the php.ini file I also had to restart FPM:

sudo systemctl restart php-fpm.service

before restarting apache:

sudo systemctl restart httpd

Lenon Tolfo
  • 359
  • 4
  • 9
  • for an AWS EC2 hosted wordpress site I was troubleshooting, this was exactly the issue. had to restart php service in addition to httpd. Thanks! – Vicer Mar 09 '22 at 04:53
4

Check also for:

/etc/php.ini or

/etc/php-[version].ini

and modify the value also in this file. If this is not sufficient, search for:

/etc/php.d/aws.ini

infact it is possible that AWS is overriding your value. If this is the case, the solution is to create a file named /etc/php.d/99uploadsize.ini containing only:

[php]
upload_max_filesize = 100M
post_max_size = 100M

The name 99uploadsize.ini is not mandatory, but remember that the name should be in alphabetical order after aws.ini and in the same directory, because this is the order these ini files are read. Even if the example is not about generical Ubuntu with Apache, this kind of solution is given by Amazon for a similar issue with WP here:

https://aws.amazon.com/it/premiumsupport/knowledge-center/wordpress-themes-2mb/

  • Tried what you said. I created php.d file because it wasnt there and created zzz.ini file containing upload_max_filesize and post_max_size but there is till no changes in the phpinfo. – alyssaeliyah May 24 '18 at 08:08
  • Is there any .htaccess setting php_value post_max_size 8M? ..but I think that if you wrote the application this is not the case.. And did you restart also fpm as apokryfos suggested? The correct command is: restart php7.0-fpm – IgrewupwithSlackware May 24 '18 at 08:27
  • where to locate .htaccess? I tried restart php7.0-fpm, but it says "command not found". – alyssaeliyah May 24 '18 at 08:38
  • @Eliyah, the command depends from your operating system and your php fpm version (it could be also service php7.0-fpm restart or service php7-fpm restart) You can find an almost exhaustive list here: https://serverfault.com/questions/189940/how-do-you-restart-php-fpm The file .htaccess in Apache, to be able to override these values, should be in the "root directory" of your host ( /var/www/project-name/.htaccess or similar) – IgrewupwithSlackware May 24 '18 at 08:53
  • I dont have .htaccess in /var/www/html. I confirmed its non-existence throug looking at the putty. I can clearly remember, I havent used it since I log in Amazon Ec2 instance. – alyssaeliyah May 24 '18 at 08:56
  • My PHP FPM is inactive so it wont restart. – alyssaeliyah May 24 '18 at 09:08
  • I also couldn't find aws.ini – alyssaeliyah May 27 '18 at 05:35
  • Thanks @IgrewupwithSlackware, you saved me – Faridul Khan Jul 06 '23 at 13:05
1

Sorry guys, for bothering all of you, my bad. I was banging my head for this for almost 4 days and it turns out that I have only made a syntax error in my php.ini. I updated my server php.ini with my newly installed php in my localhost and phpinfo() was updated after apache restart.

alyssaeliyah
  • 2,214
  • 6
  • 33
  • 80