I'm using docker-compose, and I want to add this setting to my php.ini
upload_max_filesize = 50M
but I'm confused I have 2 php.ini, please see the screenshot
how can I persist my additional setting to the php.ini?
Thank you in advance
Use docker cp <php_container_name>:/usr/local/etc/php/php.ini-development . to copy the ini file from the container to host. Change the settings as you like then mount the edited file into the container. In the compose file add this to your php service:
volumes:
- /home/user/my-edited-php.ini:/usr/local/etc/php/php.ini
It should appear in the directory inside the container as php.ini.
Related
I'm using a container in Docker to host my Laravel app and this container is connected to another container using Nginx to host it. I'm trying to import a SQL file into my Laravel app with a seeder that's like this
$path = public_path('sql/2022_11_16_import_table.sql');
$sql = file_get_contents($path);
DB::unprepared($sql);
However, it displayed the error
Symfony\Component\Debug\Exception\FatalErrorException : Allowed memory size of 134217728 bytes exhausted (tried to allocate 186885432 bytes)
at /var/www/database/seeds/SqlFileSeeder.php:16
I have figured this is due to my memory_limit in php.ini is being 128M so I went ahead and changed it by changing the php.ini-development and php.ini-production file inside the PHP container and then restart the whole container and the Nginx container. However, when I tried
php -ini
again the memory_limit is still 128M=>128M despite both the php.ini file has been changed. I have also tried ini_set('memory_limit','200M'); but it still seems to have no effect.
You can add a command at the end of your docker file to copy the php.ini-production or php.ini-development to /usr/local/etc/php/php.ini.
Something like this:
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini && \
sed -i -e "s/^ *memory_limit.*/memory_limit = 4G/g" /usr/local/etc/php/php.ini
php.ini-production file will not read. PHP initialization work with php.ini files, which are end .ini extension. You can add volume in Docker for main php.ini files like that:
volumes:
- 'configs/php.ini:/usr/local/etc/php/php.ini'
Content of php.ini
memory_limit = 200M
If you will do it manually after docker compose up, then you will need to run some commands:
Enter to Docker container
docker compose -it my_container_name bash
Restart PHP-fpm and Nginx services
service php-fpm restart
service nginx reload
Thanks for the suggestions. I have used php.ini based on the 2 files and after reloading nginx it worked as intended. Alternatively I also tried
ini_set right before
$path = public_path('sql/2022_11_16_import_table.sql');
$sql = file_get_contents($path);
DB::unprepared($sql);
and it also did the job. Previously I ini_set in another file but after further reading I hace come to realized it just set for the current working file and not globally.
can anyone show me how to upload and store video using laravel ?
whenever i try to upload a video it gives me post too large exception.
I also changed values in php.ini file like post_max_size etc but did not worked
As others said, you have to set "post_max_size" parameter on php.ini file. If you are using php under the ubuntu, you could find the php.ini file on the path like: "/etc/php/7.2/fpm/php.ini". The path may differ according to your php version or installation method.
sudo nano /etc/php/7.2/fpm/php.ini
and also for Command-line version:
sudo nano /etc/php/7.2/cli/php.ini
Now, search for "post_max_size" using CTRL+w functional keys. The default value is
post_max_size = 8M
I changed the value to
post_max_size = 500M
press CTRL+O and then enter the "y" to confirm changes. do this flow for "upload_max_filesize" parameter; we changed it from:
upload_max_filesize = 2M
to
upload_max_filesize = 500M
now confirm the changes with CTRL+O and then exit with CTRL+X .
It could be useful to change some other parameters like "memory_limit", so on (check this article from DigitalOcean).
Don't forget to reload new configurations:
sudo service php7.2-fpm restart
You should check if the php.ini options are getting loaded correctly. There are a lot of ways to overwrite this configuration file.
A quick Google search gave me this page: http://php.net/manual/en/configuration.changes.php
In Ubuntu 16.04 with Nginx (LEMP) I created the file /etc/php/7.0/fpm/zz_overrides.ini.
The file contains only this code:
[PHP]
post_max_size = 2000M
upload_max_filesize = 2000M
max_execution_time = 3000
cgi.fix_pathinfo=0
After creating the file I saved it and restarted Nginx and PHP-FPM:
systemctl restart nginx.service
/etc/init.d/php*-fpm restart
And yet, I don't see the effect. For example, I can still upload data up until 2 megabytes instead 2000 megabytes, see:
My question
Why is the zz_overrides.ini file isn't effective?
Create a php file with the following content:
<?php
phpinfo();
?>
There you can see all current settings.
In the first section you have "Additional .ini files parsed".
So you can see which files are loaded.
Also "Scan this dir for additional .ini files" shows you which additional folders are scanned for config files.
What I had to do is to enable my additional php.ini file
I did so by creating a softlink (symlink) to it, in conf.d directory:
ln -s /etc/php/7.0/fpm/zz_overrides.ini 20-zz-overrides.ini
Then indeed I saw the desired change:
Version-agnostic variant
A version-agnostic (version independent) variant of this command is this:
ln -s /etc/php/*/fpm/zz_overrides.ini 20-zz-overrides.ini
I'm a noob and using Wordpress on Google cloud. When attempting to upload a new theme, I get the following error message:
The uploaded file exceeds the upload_max_filesize directive in php.ini.
This is a limitation seems to be set by Google Compute Engine. I've found info about the limitation being set in the php.ini file, but I can't seem to locate that file anywhere.
Can anyone give some idiot proof, step-by-step instructions to increase the upload size beyond 2MB? I've installed the WP plug-ins that should do this, but the problem must be server side.
I'm not sure what operating system you are using or what version of PHP you are using. I run an Ubuntu 12.04 instance from Amazon Web Services using PHP-FPM. But, the instructions should be basically the same for you. The directory where your php.ini file is saved may be slightly different in item 3. Go hunt for it.
Log in to your server via SSH.
Change user to root: sudo /bin/bash
Edit the php.ini file: nano /etc/php5/fpm/php.ini
Find the line that says upload_max_filesize = 2M . In nano, you can search by typing Ctrl W.
Change to whatever file size you want Whatever you type must have an M (megabytes) or G (gigabytes) at the end (e.g. upload_max_filesize = 200M or =1G).
Aim for the lowest number that you NEED, and keep in mind that PHP has another setting elsewhere that sets how long it will wait before a timeout. You can set a 2G upload limit, but if your timeout is 30 seconds you're still going to fail unless you can upload 2G in 30 seconds. As a general rule, aim low.
Type Ctrl X to exit, save your file changes.
Restart PHP by typing service php5-fpm restart
In your Google development console dashboard, at the left, under Compute you have Instance of MV
click to see all your instance parameters
click on ssh button to access to your server
tape find / -name php.ini to find the directory of your php.ini
tape sudo nano in my case it was sudo nano /etc/php5/apache2/php.ini
find the line upload_max_filesize = 2M and change it to 20M or more
restart your server with sudo /etc/init.d/apache2 restart
It worked fine for me !
Install Google Cloud SDK (GCS) https://cloud.google.com/sdk/gcloud/
GCS: Setup you account in Google Cloud SDK Shell gcloud auth login
Get connection string from web console https://console.developers.google.com
YourProject > Compute > Compute Engine > VM instances
On instance line: connect/SSH > popup menu > view gcloud command
Copy gcloud compute command line
GCS: Run it in Google Cloud SDK Shell to open SSH gcloud compute --project "your_project-id" ssh --zone "us-central1-a" "wordpress-your_id"
GCS: Copy php.ini to your localhost: gcloud compute --project "your_project-id" copy-files "wordpress-your_id":/etc/php5/apache2/php.ini php.ini --zone "us-central1-a"
Edit line upload_max_filesize = 2M in php.ini located in your Cloud SDK folder
GCS: Upload back to the host in your home directory:gcloud compute --project "your_project-id" php.ini copy-files "wordpress-your_id":~/php.ini --zone "us-central1-a"
SSH: Change user to root in PuTTY: sudo /bin/bash
SSH: Replace php.ini: cp php.ini /etc/php5/apache2/php.ini
SSH: Restart service: service apache2 restart
I did this steps
In the terminal console you need to edit the correct php.ini, in my case was:
vi /etc/php5/apache2/php.ini
I made the seek and changed the upload_max_filesize and post_max_size variables like this:
post_max_size = 256M
upload_max_filesize = 256M
I restarted the apache server
/etc/init.d/apache2 restart
And work for me.
You must know about how Google products works.
At least, there are two things you can control.
The memory that WP itself will try to use as max: define('WP_MEMORY_LIMIT', '256M');
The value of the "container" you are using (600Mhz/128Mb on the free usage).
Even if it's running PHP, it's using their own infraestructure, based on Python and using it's own config files. So no .htaccess or php.ini will be parsed here. Just the config files that you can read about on the Documentation.
Anyway, im watching people's reports and being know that you can at least run the 128Mb of the minumun instance. Also, i don't recommend you to use AppEngine to host a blog.
I've been trying to increase the php memory_limit in MAMP (Mac OSX). The version of PHP I'm using is 5.4.1.0. I've read about creating a new template for MAMP Pro, but I'm using the standard version of MAMP.
I've tried all of the below, but nothing seems to have worked. Any help would be much appreciated.
Thank you for your time.
I've added the following to my site's htaccess file, which is read by the site and works (ExpressionEngine). But the master PHP limit is still not updating.
php_value memory_limit 128M
I've changed the following from 32M to 128M in the following file:
/Applications/MAMP/conf/php5.4.10
memory_limit = 128M ;
I then quit MAMP entirely and restarted it, but in MAMP phpInfo it still reads:
memory_limit 32M
Virtual Hosts
I am using Virtual Hosts to set my own URLs. I read somewhere that it may be necessary to increase the memory limit here. So I added this to the 'php_value memory_limit 128M':
/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot /Applications/MAMP/htdocs
ServerName localhost
php_value memory_limit 128M
</VirtualHost>
and lower down in the same file in the relevant site's configuration:
<VirtualHost *:80>
DocumentRoot "/Users/Username/Dropbox/Dev/sitename.dev"
ServerName sitename.dev
php_value memory_limit 128M
</VirtualHost>
(By the way, I keep my MAMP folder (Dev) in Dropbox and it works fine)
php.ini
I also added a php.ini file with the following contents in both the root of my site directory and the root of my MAMP directory:
memory_limit = 128M
Managed to solve it ;-)
The correct one is:
/Applications/MAMP/bin/php/php[your_php_version]/conf/php.ini
find 'memory_limit' and increase the number:
memory_limit = [number]M
Thanks!
Make an phpinfo.php and put there the phpinfo(); in the output you can see the loaded configuration files and the values.
Edit the loaded php.ini file and set the memory limit. I think you have edited the wrong php.ini file or your application set the value over memory_limit.
I have been chasing this for a couple hours, trying to scrub through all my php.ini files trying to update the settings with a text editor and saving it. And every time I'd restart MAMP the settings would get changed back and the file would be overwritten. So here's how I did it where I finally didn't get overwritten by MAMP.
In MAMP, use the menu to get to version of PHP you are using. Mine is 7.3.1 at this time.
MAMP > File > Edit Template > PHP(php.ini) > 7.3.1
An editor window will open, then use the search bar to find your setting... memory_limit
Update your setting
Cmd + S then close the editor window OR just close the editor window and click "Save" when you are prompted
MAMP will then automatically re-start the servers with the new settings
In Mamp Pro and PHP version 7.2.8 ,you can find configuration file in this path:
/Applications/MAMP/bin/php/php7.2.8/conf/php.ini
But according to phpinfo(); My loaded configuration file is in different path! It is here:
/Library/Application Support/appsolute/MAMP PRO/conf/php7.2.8.ini
Also don't forget restart Mamp Pro.
Coming here after facing the same problem with PHP v.7.2. To fix this I needed to go to the path /usr/local/etc/php/7.2/conf.d/php-memory-limits.ini and change the following:
; Max memory per instance
memory_limit = 2048M
Anything else I tried would not change it.
Now I don't get this errors when trying to pull packages with composer in my projects (Fatal error: Allowed memory size of 536870912 bytes exhausted...)
I was able to set memory_limit with MAMP PRO 5.5 on MacOS here :
/Applications/MAMP/bin/php/php7.3.8/conf/php.ini
PHP mode is Individual PHP version for every host (CGI mode)