I am running this Docker instance of a linux debian:jessie with php 5.6.
This is part of my phpinfo :
As we can see the php.ini should be located at
/usr/local/etc/php
And this is what I have inside /usr/local/etc/
But there is no php.ini inside it.
I the other hand, I have the php.ini inside
So, from where exactly is my php.ini being loaded?
We dont even have a php process running but the php seems to be ok - being displayed phpinfo in the screen.
A little late to the party but since question is still relevant today, let me add a short answer:
Official php:7 images get their settings from /usr/local/etc/php folder.
# First log into the running container
$ docker exec -it «container_name» /bin/bash
# List folder content
$ ls /usr/local/etc/php
# Which outputs following line
conf.d php.ini-development php.ini-production
If needed, modifying settings via conf.d folder seems better alternative, since xdebug uses it. For example, you can change upload size by adding uploads.ini to conf.d folder with the following content:
file_uploads = On
memory_limit = 64M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 600
Complete list of ini directives can be found at https://www.php.net/manual/en/ini.core.php
Let try it as an answer:
It does not exist at all, which means php will run the default options.
Look at your docker file, it starts from a "clean" OS, installs Apache and PHP in it. But it never copies the php.ini file from the PHP installation into /usr/local/etc/php. Actually in lines 31 and 32 it creates the conf.d directory but that is it.
So I would suggest, at the end of your docker file, add code to copy php.ini-production to /usr/local/etc/php.ini, and edits as required. Or use default options.
The default php.ini file that the docker php images look for is:
/usr/local/etc/php/php.ini
You can see this in the output from the phpinfo function (just run "php -a" in the container and then "phpinfo();" at the prompt):
Configuration File (php.ini) Path => /usr/local/etc/php
Loaded Configuration File => /usr/local/etc/php/php.ini
You can always link this file in as a volume to get a custom one when running the container with a -v option like:
docker run -v /local/path/to/php.ini:/usr/local/etc/php/php.ini [OPTIONS] IMAGE [COMMAND] [ARG...]
I typically prefer to use the default ini file that comes with it, with just a few modified options as I need them. If you want your container to do this during build, you can do something like the following in the Dockerfile:
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
The RUN commands above will copy the default production ini file, and then will modify the memory_limit and set it to 4G in the ini file.
I prefer this method because it allows custom configurations to be used so the container always works with defaults when it's pulled, but you still have the option to override the ini file in the container by passing a volume in.
Short answer is you don't need one. If you're missing or want to add extensions, you can do so in your Dockerfile by doing docker-php-ext-install or docker-php-ext-enable.
Most of the common ones, you can simply do enable, such as mbstring for example, but for some less common ones, you might have to run pecl first or something to get the package. Take a look at this Docker documentation page for more information on php extensions
If you are using something like wodby (docker4php or docker4drupal) or lando or trying to find an answer "why php.ini doesn't work" (like me), these tools are using their own way to pass configuration into php
https://github.com/wodby/php#php-and-php-fpm-configuration
Related
I was reading the documentation on Docker hub and came across the:
Configuration
This image ships with the default php.ini-development and php.ini-production configuration files.
It is strongly recommended to use the production config for images used in production environments!
I followed the steps to use them by adding the following in my Dockerfile.dev:
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
Or
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
Now when I start my cluster, all of the environmental variables it uses in the index.php say Undefined Index and the program no longer works.
The fix is to comment out RUN mv... and then everything works again.
Why would it be breaking the Kubernetes environmental variables and how can I get them to work in conjunction?
Seems like switch from fetching environmental variables with $_ENV['<varname>'] to getenv('<varname>') fixed the issue.
I'm using virtphp to have separate environments (different PHP versions, extensions, etc).
When I use symfony's command to run a local development server:
php app/console server:run
It seems that it ignores the php.ini file of my virtual environment (~/.virtenv/envs/myenv/etc/php.ini), e.g.: does not load the extensions definided in that file.
But when I use the php built-in server directly, it works perfectly:
php -S 127.0.0.1:8000 --docroot=web/
What's the difference of those two commands or what does symfony do differently?
This is the output of the php --ini command:
Configuration File (php.ini) Path: /usr/local/etc/php/5.5
Loaded Configuration File: /Users/mjuarez/.virtphp/envs/wowfi/etc/php.ini
Scan for additional .ini files in: /Users/mjuarez/.virtphp/envs/wowfi/etc/php
Additional .ini files parsed: (none)
This is the output of the function phpinfo() in a Symfony controller when using the command php app/console server:run:
Configuration File (php.ini) Path /usr/local/etc/php/5.5
Loaded Configuration File /usr/local/etc/php/5.5/php.ini
Scan this dir for additional .ini files /Users/mjuarez/.virtphp/envs/wowfi/etc/php
Additional .ini files parsed (none)
Note the difference in "Loaded Configuration File"... when I use the php --ini command it replaces the "Loaded Configuration file" with the one in my php virtual environment and when I use the command php app/console server:run it uses the "global" configuration file.
For the record (and for all lost souls who arrive here by Google search like me):
Symfony console is not a program per se. It is just a PHP script. Therefore, when you run Symfony console, it doesn't have its own php.ini or extension directory or other configuration - It uses the same settings as all your other PHP scripts. (Unless overwritten at runtime - which actually might be the case of the original question.)
A workaround for this issue is to move the php.ini file of my virtual environment to a sub-directory called php inside the etc directory. e.g.:
Move the file ~/.virtphp/envs/my-env/etc/php.ini
To ~/.virtphp/envs/my-env/etc/php/php.ini
Yet another piece for the "lost souls" who arrive here - Symfony does overwrite at least the max_execution_time, when Symfony commands are called through the console. Check the console.php file, there's a "set_time_limit(0)" in line #12 or so.
Drop a file in your web directory with inside. Open it with your browser and search for php.ini that will give you the correct file. There could be several files yf you look directy in your configuration directory (cli, fpm, apache and so on)
Does anyone know how to edit the mail setting in the php.ini file by using Vagrant.
so I would ssh in terminal like so:
cd myapp
vagrant ssh
then what>?
Depending on your box, it might be
sudo nano /etc/php5/apache2/php.ini
then adopt you changes and restart with
sudo service apache2 restart
Without knowing what specific setting you want and what you want it changed to, you could try adding a shell script to the end of your Vagrantfile (in the "Local Scripts" area) to do a search and replace on the ini file.
#!/usr/bin/env bash
sed -i.bak s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT_WITH/g /etc/php5/apache2/php.ini
Failing that, you can use ini_set in your project (preferably in a bootstrap) to change mail settings on a per-project basis.
In my case where I'm using scotchbox on vagrant, changing the php.ini file won't reflect changes in phpinfo() function output so I changed /etc/php5/apache2/conf.d/user.ini file which could be a bare file or a file with few lines declaring php error display, I add my configurations here e.g. upload_max_filesize = 64MSave the change and issue sudo service apache2 restart. Viewed the phpinfo page and I can see the updated filesize.
I have both ~/.bash_profile & ~/.profile files.
~/.bash_profile contains one line:
export PATH=/Applications/mamp/bin/php5.5.3/bin:$PATH
~/.profile contains three lines:
# MacPorts Installer addition on 2014-02-02_at_20:54:53: adding an appropriate PATH variable for use with MacPorts.
export PATH=/Applications/MAMP/bin/php5.5.3/bin/:/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
As you can see I am trying to get my default PHP PATH to use MAMPs PHP because I have mcrypt installed on it. For some reason when I type whereis PHP I get the native route: /usr/bin/php, and when I echo $PATH I get:
/Applications/mamp/bin/php5.5.3/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Somewhere I have another file thats really controlling my PATH and I have no clue where it is. What else could be controlling my PATH route?
NOTE: I have Homebrew, MacPorts, Xcode, and Xcode Command-Line Tools installed.
What you're seeing is coming from the system-wide /etc/paths file. It is the source of the base $PATH environment variable before ~/.profile, ~/.bash_profile and others get involved. If you're in a Terminal window, you can edit it with the following command:
sudo open -t /etc/paths
By default it contains the following paths:
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
I wouldn't recommend editing this file, however, because it is system-wide and will affect every user on the system.
If you want complete control over $PATH, so as to affect only your own account you're probably better off just not including $PATH in your .profile's export PATH lines. For example (but not this):
export PATH=/Applications/mamp/bin/php5.5.3/bin:/opt/local/bin:/opt/local/sbin
Are you sure .profile is being loaded? Try a test and add an echo line to it:
echo "test: .profile has loaded"
Now open a new terminal window, do you see your echo? I suspect not as I don't think OSX loads .profile by default, at least today.
If you really want to use .profile you can ask .bash_profile to load it:
if [ -f ~/.profile ]; then
source ~/.profile
fi
Hope this helps.
Edit:
Looks like .profile is loaded, if no .bash_profile or .bash_login exist as suggested in this answer
Brief introduction to the problem:
I need to load pdo_mysql to run command php app/console doctrine:database:create and other commands for Symfony 2.
I found a way to do this by running php -c "path/to/my/php.ini" app/console doctrine:database:create
Problem:
Since I don't want to add the path to my php.ini every time I run commands in PHP CLI, where/how can I set up Windows, so that every time I type php somecommand in console it will load my desired php.ini file?
Create a .CMD file which automatically runs PHP with the required options:
path/to/php.exe -c "path/to/php.ini" %1 %2 %3 % %5 %6 %7 %8 %9
and call it something like phpcli.cmd. Make sure it's on your search path and off you go. The only change you need to make is to run phpcli rather than php.
There are several ways to do it, but if you don't want to mess with an alias or making multiple copies of file php.ini, you can also set the PHPRC environment variable. I would think this is the recommended method to set it more "permanently".
More information in the PHP documentation:
The configuration file
In Windows, an easy way to do this is to go to the "System Properties" dialog; either right-click on "My Computer" and click "Properties", or use the "System" item in Control Panel, then go to "Advanced" settings, click "Environment Variables", and click "Add" for either the system or your user, call it "PHPRC" and copy the path to your .ini file in there ... for example, mine was in C:\MAMP\conf\php5.6.28.
(This was on Windows 7, and they changed some of the UI in different versions, but it's basically the same.)
You can verify it's working by doing php --ini from the command line. The output should be something like:
Configuration File (php.ini) Path: C:\Windows
Loaded Configuration File: C:\MAMP\conf\php5.6.28\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
You can also do echo %PHPRC% from the Windows command prompt, or echo $PHPRC from Cygwin/Bash/MinGW, etc. You will have to restart any existing terminal sessions for this to take effect, but in my experience it works for all three, since the bash environments also inherit the Windows environment variables.
What if you add path/to/your/php.ini to the path environment variable and then just run php -c "php.ini" app/console doctrine:database:create
Could you try that?