In AWS Elastic Beanstalk, how to change parameter of php.ini - php

I am running a website using AWS Elastic Beanstalk. In AWS Elastic Beanstalk, the default upload_max_filesize in php.ini is limited to 2M. I want to increase the upload_max_filesize to 20M. I do the following thing and 'Upload and Deploy' EBS by uploading the new application source codes with the new 99my_php_ini_change.config. But it does not automatically create the /etc/php.d/zzz_my_own_php.ini. I also
'Create New Application' using Elastic Beanstalk, but I did not see the file /etc/php.d/zzz_my_own_php.ini was successfully created either.
Where is the error?
I thing I did was:
put file 99my_php_ini_change.config inside folder .ebextensions under application root.
99my_php_ini_change.config contains :
files:
"/etc/php.d/zzz_my_own_php.ini" :
mode: "000644"
owner: root
group: root
content: |
upload_max_filesize=20M

Do you see any error messages in the log file at /var/log/eb-activity.log? You can view the full log file by doing an eb ssh, or you can retrieve it through the EB console or from the command-line using eb logs. If there are any errors, please show your log file here.
Also, YAML files are very sensitive to whitespace. You might try the following instead (notice the two spaces per indent level, lack of space before the colon, and lack of newline):
files:
"/etc/php.d/zzz_my_own_php.ini":
mode: "000644"
owner: root
group: root
content: |
upload_max_filesize=20M

Related

AWS Elastic Beanstalk PHP logs not in CloudWatch

I have a PHP application running via AWS Elastic Beanstalk. But the PHP error logs don't seem to be included in CloudWatch alongside the access logs, etc. How do I send them to CloudWatch?
Based on some spelunking, the php error logs seem to be sent to /var/logs/php-fpm/www-error.log, decided by the setting in /etc/php-fpm.d/www.conf:
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
The only logs sent to CloudWatch for PHP based on the info here are:
/var/log/eb-engine.log
/var/log/eb-hooks.log
/var/log/httpd/access_log
/var/log/httpd/error_log
/var/log/nginx/access.log
/var/log/nginx/error.log
You could add custom configuration to have the CloudWatch agent pick up the correct file. Or, you could just add the php error messages to a file already being sent. This can be done via the following in a file .ebextensions/my.config:
/etc/php-fpm.d/www-my-overrides.conf:
mode: "000644"
owner: root
group: root
# For some reason, EB configures the php errors to go to /var/log/php-fpm/www-error.log,
# but doesn't include that file in the default log files sent to CloudWatch. This directs
# the log files to the error file that is being sent to CloudWatch
content: |
[www]
php_admin_value[error_log] = /var/log/httpd/error_log
I'm not sure but I think the www-my-overrides.conf file name needs to be alphabetically after www.confg in the same directory.
If you are using nginx, then you need to use /var/log/nginx/error.log as the error log target -- CloudWatch seems to ignore /var/log/httpd unless you use Apache, so even if you write to it, the changes won't show up in CloudWatch.
files:
/etc/php-fpm.d/www-my-overrides.conf:
mode: "000644"
owner: root
group: root
# For some reason, EB configures the php errors to go to /var/log/php-fpm/www-error.log,
# but doesn't include that file in the default log files sent to CloudWatch. This directs
# the log files to the error file that is being sent to CloudWatch
content: |
[www]
php_admin_value[error_log] = /var/log/nginx/error.log
Additionally, you need to make that file writeable by the php-fpm process which is run as webapp by default, plus you want to make sure it exists ... which it won't yet on new instance creation, so it's very important to do both commands:
container_commands:
01-command:
command: echo "-- DEPLOYMENT --" >> /var/log/nginx/error.log
02-command:
command: chmod 666 /var/log/nginx/error.log

Deploying Symfony 4 to Heroku

I have set up a new symfony 4 project that I am trying to deploy on heroku. I have the app set up and running successfully locally. I bascially followed the instructions from the heroku tutorial here. However, this tutorial is only written for symfony versions 2 and 3.
I had set up a symfony 3 app in the past successfully, I had to create a Procfile to direct the heroku server to the web/ directory, as per the instructions in the "Best Practices" section. In this S4 installation I don't see a web/ folder, so I didn't create a Procfile. Heroku uses a default command in this case.
I have created 2 config vars in heroku config: APP_ENV, SYMPHONY_ENV both are set to prod. I deploy the app the heroku, it all deployed successfully, but when I try to access the page, I just get a 403 Forbidden. In the logs I get this, which is maybe the correct functionality since I didn't write any code yet:
[autoindex:error] [pid 116:tid 139699079337728] [client
10.5.228.216:17171] AH01276: Cannot serve directory /app/: No matching DirectoryIndex (index.php,index.html,index.htm) found, and
server-generated directory index forbidden by Options directive
I don't see an app folder, but I do see a folder called public with an index file inside.
Does anyone have experience deploying the new version of Symfony 4 to Heroku, if so any tips would be greatly appreciated. Thanks!
On Symfony 4 the web folder was replaced by public. You still need to create the Procfile file and add this line:
web: vendor/bin/heroku-php-apache2 public/
In my case I defined a Procfile with the following content :
web: $(composer config bin-dir)/heroku-php-apache2 public/
But it was not enough, I had to install apache-pack with composer :
composer require apache-pack (using symfony flex) or composer require symfony/apache-pack
(I found the solution on the heroku-buildpack-php repository)
The best solution is to create a Procfile in the root of your repository,
with the following content:
web: $(composer config bin-dir)/heroku-php-apache2 public/

AWS Elastic BeanStalk php.ini file update

I would like to increase my minimum upload filesize from 2MB to 64 MB for my php web application.. I have a config file stored in an .ebextensions directory.. While deploying to aws, an error occurred:
The configuration file .ebextensions/yep.config in application version try10 contains invalid YAML or JSON. YAML exception: while scanning a simple key in "", line 7, column 7: upload_max_filesize = 64M ^ could not found expected ':' in "", line 8, column 7: post_max_size = 64M ^ , JSON exception: Unexpected character (f) at position 0.. Update the configuration file.
Below is my config file that I am starting out with. I have spend 8 hours troubleshooting with no luck. Any help will be very much obliged.
files:
"/etc/php.ini":
mode: "000755"
owner: root
group: root
content: |
upload_max_filesize = 64M
post_max_size = 64M
I am using this successfully in an Elastic Beanstalk application. Just put the following into your yep.config file inside of your .ebextensions directory in the root of your application.
files:
"/etc/php.d/project.ini" :
mode: "000644"
owner: root
group: root
content: |
upload_max_filesize=64M
post_max_size=64M

Elastic Beanstalk multi-container and php.ini

I'm using the Elastic Beanstalk multi-container environment. I've created my own lightweight PHP7 + nginx image (https://github.com/maestrooo/eb-docker-php7) which comes with some sane PHP.ini settings (https://github.com/maestrooo/eb-docker-php7/blob/master/config/custom.ini).
However, I'd like to turn off the "opcache.validate_timestamps" option. The problem is that if I do it in the custom.ini in the image, it will also be applied on development.
I therefore wanted to be able to set it to "off" through .ebextensions file (this way it will only be deployed on production, as eb local run command ignore .ebextensions files), so I added a .ebextensions/server.config file to something like that:
files:
"/usr/local/etc/php/conf.d/project.ini":
mode: "000644"
owner: root
group: root
content: |
opcache.validate_timestamps = off
While the file is properly added to the instance, unfortunately it is still to "On". It seems because PHP needs to be restarted, but I've been unable to know how I could restart PHP in the context of the Docker multi-container environment.
Did anyone were able to do something similar?
Thanks

Changing php.ini on Elastic Beanstalk

I am trying to configure my beanstalk application, setting the max_input_vars=5000 in php.ini.
I found this link which does pretty close to what I want except a little different. Instead of copying from S3 I just want to create a file with that line. The below is my code in a file named phpini.config found in the .elasticbeanstalk folder.
files:
"/etc/php.d/project.ini" :
mode: "000777"
owner: root
group: root
content: |
max_input_vars=5000
However, the value is not changing, as I seen when I run phpinfo(), nor is there a project.ini file created in /etc/php.d/.
Is there something I am missing out? Or is there a way I can see if this config file is being run?
Edit
Seems like the .config file is supposed to be in .ebextensions instead of .elasticbeanstalk according to AWS Docs. Making the change didnt make things work though.
The cleanest way what we did to install a svn plugin that is to use a .ebextensions config file in my project archive:
Sample you can go like this create a file .ebextensions/eb.config file:
files:
"/etc/php.d/project.ini" :
mode: "000644"
owner: root
group: root
content: |
u max_input_vars=5000
I tried the abaid778 snippet code and does not work so I remove de 'u' before max_input_vars and that work now.
files:
"/etc/php.d/project.ini" :
mode: "000644"
owner: root
group: root
content: |
max_input_vars = 5000
I couldn't make the previous suggestions work but was able to change the php.ini value with .htaccess:
php_value max_input_vars 5000
How to set the max_input_vars directive in an .htaccess file

Categories