Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: php.ini upload_max_filesize [amazon-cloudformation] #174

Closed
michael-newman opened this issue Jun 8, 2018 · 4 comments
Closed

Comments

@michael-newman
Copy link

(This is an issue tracker! You will probably find an answer to your question on Stack Overflow. If not, use the tag amazon-cloudformation to post your question, and the chances are high that we or someone from the community will point you in the right direction. We are not able to answer your questions via email or the project's issue tracker.)

(Override all values in parentheses)


TemplateID: wordpress/wordpress-ha-aurora
Region: us-west-2

Hello,

I have been enjoying getting familiar with your templates... everything seems to run smoothly, thank you.

However, the template defaults the upload_max_filesize=2M and I cannot seem to find concise enough instructions online to walk me through a change. My example is that I cannot load the Divi Theme, which is a pretty popular theme, as the divi.zip theme file is 7M which is far past the default max filesize of 2M.

Although, I would appreciate anyone's assistance/instructions and I'll be sure to give it a go, I believe a reasonable solution, which would also add value to users of the template, is really to improve the defaults or enable template configuration variables for this and other php configuration changes.

Thank you in advance for any guidance/direction.

Regards, Mike

@ghost
Copy link

ghost commented Jun 9, 2018

@michael-newman

Here's everything you need to customize the php configuration and also the OPcache configuration. Start by looking for the php packages. You'll see code that looks like the following:

`
config:
packages:
yum:
php70: []
php70-gd: []
php70-opcache: []
php70-mysqlnd: []
php70-mbstring: []
mysql56: []
httpd24: []

`

Speaking of the php packages, notice I have added in several php modules which most WordPress websites need, namely, gd and mbstring. I recommend you add these in.

Just below the php packages look for a sed command under the following:

`
files:
'/root/php.sh':
content: !Sub |
#!/bin/bash -ex

`

You'll see a sed command for OPcache. This is where you want to add additional sed commands to fully customize your php config and OPcache config. All you need to do is insert the below sed commands and customize the values for your needs.

Here is an example:
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 200M/' /etc/php.ini

In this example the first value ( = 2M) is what the sed command is looking for in the string. The second value (= 200M) is your replacement value. That is what sed does; it looks for a specified string and can replace part of that string. So all the sed commands below are outlined for you and all you need to do is choose your values. The values below are what I currently use.

Here are all the sed commands you'll need:

PHP CONFIGURATION

Confirm that sed command is successfully replacing the string in /etc/php.ini

`
sed -i 's/max_execution_time = 30/max_execution_time = 300/' /etc/php.ini
sed -i 's/max_input_time = 60/max_input_time = 300/' /etc/php.ini
sed -i 's/; max_input_vars = 1000/max_input_vars = 10000/' /etc/php.ini
sed -i 's/memory_limit = 128M/memory_limit = 512M/' /etc/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 200M/' /etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 200M/' /etc/php.ini
sed -i 's/max_file_uploads = 20/max_file_uploads = 200/' /etc/php.ini

`

OPCACHE CONFIGURATION

Confirm that sed command is successfully replacing the string in /etc/php-7.0.d/10-opcache.ini
Reference statistics section in WP OPcache plugin to determine optimal OPcache configuration

`
sed -i 's/opcache.memory_consumption=128/opcache.memory_consumption=256/g' /etc/php-7.0.d/10-opcache.ini
sed -i 's/opcache.interned_strings_buffer=8/opcache.interned_strings_buffer=16/g' /etc/php-7.0.d/10-opcache.ini
sed -i 's/opcache.max_accelerated_files=4000/opcache.max_accelerated_files=10000/g' /etc/php-7.0.d/10-opcache.ini
sed -i 's/;opcache.max_wasted_percentage=5/opcache.max_wasted_percentage=10/g' /etc/php-7.0.d/10-opcache.ini
sed -i 's/;opcache.validate_timestamps=1/opcache.validate_timestamps=1/g' /etc/php-7.0.d/10-opcache.ini
sed -i 's/;opcache.revalidate_freq=2/opcache.revalidate_freq=60/g' /etc/php-7.0.d/10-opcache.ini
sed -i 's/;opcache.fast_shutdown=0/opcache.fast_shutdown=0/g' /etc/php-7.0.d/10-opcache.ini

`

After putting all of this in your template and updating in CloudFormation you need to force the creation of new EC2 templates for the settings to take effect. The easiest way to do this is to either manually terminate or reboot the instances in EC2. When you do this new instances will automatically be created using the new launch configuration.

The last step is to verify the settings are working. To do that just SSH into an instance and look at the values in /etc/php.ini and /etc/php-7.0.d/10-opcache.ini. If your sed commands worked you'll see your values in these files.

Lastly, for OPcache I highly recommend you install the WP OPcache plugin. It does a wonderful job of showing how OPcache is being used by WordPress. You can use the information in that plugin to further tailor the OPcache configuration.

Here is that plugin:
https://wordpress.org/plugins/flush-opcache/

If you use this plugin don't try to flush the cache with it, as it will only flush the cache of the instance you are connected to at that time. OPcache must be flushed on all instances simultaneously. So just use this plugin to gather information for the OPcache config.

I hope you find this helpful!

~ Michael

@michael-newman
Copy link
Author

Michael,

THANK YOU... this information is tremendously helpful. Appreciate your thoughtful guidance, details, and the insights to add the additional php modules as well.

I am now able to proceed forward, and once I flesh out the site, I'll revisit the Opcache for further tailoring...

Have a great weekend!

Regards, Mike

@ghost
Copy link

ghost commented Jun 9, 2018

@michael-newman

I'm glad I was able to help you. When I saw your message it was such an easy thing, I wanted to lend a hand. I've been using these templates for some time now, so I know all the tricks! ;)

If you have anything else come up and need some help/advice don't hesitate to ask.

You have a great weekend too!

~ Michael

P.S. More importantly than flushing OPcache is invalidating the CloudFront distribution after every deployment (or manual change) you make to the files. You'll quickly run into annoying caching issues otherwise when making changes.

@michaelwittig
Copy link
Contributor

I opened up a pull request #175 to make sure that those values are available in the original template as well. Thanks @ILLUMINICE for posting them!

I will close this issue and merge the PR as soon as the tests have passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants