php not working with php.ini file on mac os x - php

I'm running a local server on my macbook (os x 10.9.2)
I'm trying to install mcrypt and I've run into a problem that I can't add the extension to my php.ini file, because apparently my php installation doesn't use a php.ini file.
Looking at phpinfo(), I see this:
Configuration File (php.ini) Path: /etc
Loaded Configuration File: (none)
In my /etc folder, a php.ini file doesn't exist. I do have a php.ini.default, but when I make a copy of that and name it php.ini, and restart apache, PHP just stops working entirely (my php code isn't interpreted and shows up when viewing the web site's source).
Is there something in the php.ini.default file I have to change before copying it to php.ini?
Edit: Upon further trial and error, I have found that if I create a blank php.ini file and restart the server, PHP runs just fine. There must be an error in php.ini.default that is killing PHP on my local server. I've tried using php.ini.default~orig too and the same problem happens. Any way to find out what is wrong with the php.ini.default file?
Edit2: Upon further random trial and error, if my php.ini only contains:
[PHP]
short_open_tag = On
PHP works. If it only contains:
[PHP]
short_open_tag = Off
PHP doesn't work. I'm so confused.
Edit3: Oh! The php.ini.default file had short_open_tag = Off, and of course I'm using short open tags everywhere. Edit2 clued me in. Wasted half a day on this. This is so embarrassing. Everything is working now.

In case someone else runs into the missing php.ini problem on OS X 10.9 or 10.10:
I ran into the same problem after trying install the latest php through homebrew. Turns out mac comes with php already installed, but no config file. Homebrew won't overwrite the system php binary, which remains the default.
Try sudo rm /usr/bin/php then brew install homebrew/php/php55.

Related

php_ini_loaded_file not working with PHP 5.5.30, Apache 2.4 in El Capitan

I'm using Apache 2.4 on my El Capitan Mac. I would like to know which php.ini is used by the server.
The output of phpinfo() tells me that that the path for the php.ini file is the etc/ directory.
Unfortunately, there are four such files there :
php.ini-5.2-previous
php.ini.default
php.ini.default-5.2-previous
php.ini.default-5.2-previous~orig
My guess would be that it uses php.ini.default, but I would like to be 100% sure.
So I call php_ini_loaded_file(), which unfortunately returnsbool(false). Does it mean that the PHP module in Apache does not load any php.ini at all ???
Any help appreciated.
If you do not have any "Loaded Configuration File" row in your phpinfo() output, then probably there is no php.ini file loaded at all, as you suspect.
Try to copy one of the existing files to the filename php.ini, and restart the server. If it loads it, find out the differences between the variants and configure your system to your needs.

Windows 10, mamp, composer not installing, but openssl & extension_dir enabled

I have mamp installed and am using windows 10. I have attached an image of the configurations, the error, and some of the things I've done to diagnose why. I don't know why I am continuously getting this composer error. I am updating my php.ini file, which had openssl commented out. I removed the semicolon on extension_dir (was already removed), and on extension=php_openssl.dll. I have noticed that when I type in php -m in my command prompt, I am not seeing open ssl, and I'm not sure how to enable that, if that is the possible issue.
If there can be any light shed on this, let me know, I understand this issue is answered hundreds of times over, but I have done what was required from those answers, and got no where.
Image clarifications: The error
Here is where I am checking the configurations with php -m and it's not showing openssl, correct me if I'm mistaken.
My phpinfo(); with also me doing php -ini, it's showing php isn't set, but it is when I run the phpinfo method, i'm assuming because this method is being run through mamp allowing it to set the correct parameters.
You have to make sure that the command-line PHP loads an ini file somehow. The easiest is probably to copy c:\MAMP\conf\php7.0.0\php.ini to wherever your php.exe is located. To find that out you can use where php which should return you the full path to it. Copy the ini file in that directory and it should find it and load the module (although you might have to adjust the extension_dir depending on how it is set).
See http://php.net/manual/en/configuration.file.php if you want more details on how the ini file is located.
you only need to copy php.ini from the conf directory to your php directory and it will work fine.
just copy php.ini from
MAMP/conf/php(version of your php)/php.ini
to
MAMP/bin/php/php(version of your php)
then try in command line `php composer.phar install'
for install composer and enable openssl extension, copy your php.conf in MAMP\conf\php{php-version} for MAMP\bin\php\php{php-version} and edit php.conf changing ;extension=php_openssl.dll for extension=php_openssl.dll.
Then try installing normally.
Running Windows 10 with MAMP PRO. Copy the version php.ini file to the folder that has the php.exe. In my case, I copied MAMP/conf/php7.2.1/php.ini file to MAMP/bin/php7.2.1/ folder.
Restarted MAMP PRO 4.
Ran the command line, replacing some-dir with my new Drupal 8 project.
composer create-project drupal-composer/drupal-project:8.x-dev some-dir --stability dev --no-interaction
Worked beautifully!

Unable to locate php.ini file or paths to it on mac

I've just starting working on a mac so this is probably very obvious.
I've installed php, pear, and lastly pecl.
My last command was sudo pecl install mongo and am prompted to add the line extension=mongo.so to php.ini configuration.
I am unable to locate the php.ini file. I do a quick php --ini in the CL and am told the path is /etc, /etc/php/apache2/php.ini to be exact. I've tried to unhide files and well as searching via the finder but am told these directories don't exist, even though I believe my installations were done correctly. How can I access this etc directory, as well as others like the php5 folder so I can edit my php.ini file? Thanks. Using Yosemite 10.10.3 and latest php packages.
Just check the phpinfo output to locate the loaded php.ini file (Loaded Configuration File).

Why isn't Php not loading values from php.ini? [duplicate]

I have been trying for two days to increase the max filesize for file uploads via php to 10M from the default 2M. I change the php.ini file that is referenced by phpinfo to no avail.
I saw a few articles stating that there is a syntax error around line 109 of the php.ini file, but I don't know what the syntax error is or how to correct it. users stated that because the upload_max_filesize is AFTER this error in the config file it is being ignored. Please help.
This message helped me:
The newest php version installed on server does not allow global settings (such as execution time, max upload filesize, max post file size, etc.) to be changed.
Folow these steps to resolve the issue:
Eval phpinfo();
Search for 'Scan this dir for additional .ini files' text in phpinfo() output
It will be something like this /etc/php5/apache2/conf.d
Create your user.ini file inside the dir. (/etc/php5/apache2/conf.d/user.ini)
Use this ini file for custom settings.
Restart the server
File /etc/php5/apache2/conf.d/user.ini
post_max_size = 90M
upload_max_filesize = 50M
Update 2018.06
If you are using nginx + php-fpm your path will be something like this (use your php version in path). Create file using:
nano /etc/php/7.0/fpm/conf.d/user.ini
There are a lot of other .ini files in the conf.d directory. If you want your config to be the last included - use prefix.
For example: 30-user.ini.
After file creation don't forget to restart fpm:
sudo service php7.0-fpm restart
If you php.ini resides somewhere like /etc/php/7.*/fpm/php.ini - then modify it as needed and instead of sudo service apache2 restart go with service php7.1-fpm restart
Have you restarted apache2?
sudo service apache2 restart
The new php.ini configuration is only applied when apache starts.
You might also need to increase the maximum size of a post:
post_max_size=10M
Try that.
I had exactly the same problem and solved it using these steps:
When running the following command on my server
php --ini
I got the following path of my php.ini
Loaded Configuration File: /etc/php/7.0/cli/php.ini
I kept on making changes in this php.ini file, but none of the changes took effect. I then created a file called info.php in my /var/www/html directory and added the following code
<?php
phpinfo();
?>
Then I opened the file in my browser http://example.com/info.php, where I saw that the actual loaded php.ini file was in a different directory
Loaded Configuration File /etc/php/7.0/apache2/php.ini
When I made changes to the php.ini file inside of this directory, all the changes took effect. In summary make sure that you run the phpinfo(); function to make sure of the actual php.ini file which php uses.
service apache2 reload needs to be run as root, even if it does not appear to fail without root. Running sudo service apache2 reload works. This is in Ubuntu 14.04.
Maybe you find 2 directories for php.ini files.
If you search where php.ini is using cli like php --ini maybe it show you /etc/php/7.1/cli/php.ini, but thereis another folder to php-fpm found in /etc/php/7.1/fpm/php.ini and you need to create your new ini file under conf.d folder like /etc/php/7.1/fpm/conf.d/30-user.ini and if you need a ini file to cli command line you need to put your ini file under /etc/php/7.1/cli/conf.d/30-user.ini
I had a very strange experience which caused the same symptom like this.
The point is that my php.ini file contained an old-style comment (starting with hashmark) which, as of php 7.0, is not a comment any more. The incorrect comment confused the ini-parser.
The solution was to replace all # comment symbols with semicolon (;) which is the only standard way for writing comments.
For further details, please read my comment here:
https://serverfault.com/a/1012262/494670
After reading great #Jekis's answer, I solved the same issue for Fedora distribution (it's the same thing, just different path):
After evaluting phpinfo(); output I found out that other .ini files are stored in: /etc/php.d directory
In /etc/php.d I created a new file - 40-user.ini. I added upload_max_filesize and other settings that I wanted to change
Then I restarted apache (httpd)
And then changes were picked up.
Changes to Ubuntu php.ini will not take effect.
Steps to resolve this issue in Ubuntu 18.04 with Nginx 1.18.0.
Check the php version you are running: php -v
Check for syntax errors in php.ini: sudo php-fpm7.4 -t (change to the version you are running).
Use your favorite editor to fix syntax errors.
Restart php-fpm: sudo systemctl restart php7.4-fpm (change to the version you are running).
My results:
PHP: syntax error, unexpected END_OF_LINE, expecting '=' in /etc/php/7.4/fpm/php.ini on line 2
In my case it was a "w" before the [PHP] which must have happened when I was using Ctrl w for searching with nano.

Changes to upload_max_filesize in Ubuntu php.ini will not take effect

I have been trying for two days to increase the max filesize for file uploads via php to 10M from the default 2M. I change the php.ini file that is referenced by phpinfo to no avail.
I saw a few articles stating that there is a syntax error around line 109 of the php.ini file, but I don't know what the syntax error is or how to correct it. users stated that because the upload_max_filesize is AFTER this error in the config file it is being ignored. Please help.
This message helped me:
The newest php version installed on server does not allow global settings (such as execution time, max upload filesize, max post file size, etc.) to be changed.
Folow these steps to resolve the issue:
Eval phpinfo();
Search for 'Scan this dir for additional .ini files' text in phpinfo() output
It will be something like this /etc/php5/apache2/conf.d
Create your user.ini file inside the dir. (/etc/php5/apache2/conf.d/user.ini)
Use this ini file for custom settings.
Restart the server
File /etc/php5/apache2/conf.d/user.ini
post_max_size = 90M
upload_max_filesize = 50M
Update 2018.06
If you are using nginx + php-fpm your path will be something like this (use your php version in path). Create file using:
nano /etc/php/7.0/fpm/conf.d/user.ini
There are a lot of other .ini files in the conf.d directory. If you want your config to be the last included - use prefix.
For example: 30-user.ini.
After file creation don't forget to restart fpm:
sudo service php7.0-fpm restart
If you php.ini resides somewhere like /etc/php/7.*/fpm/php.ini - then modify it as needed and instead of sudo service apache2 restart go with service php7.1-fpm restart
Have you restarted apache2?
sudo service apache2 restart
The new php.ini configuration is only applied when apache starts.
You might also need to increase the maximum size of a post:
post_max_size=10M
Try that.
I had exactly the same problem and solved it using these steps:
When running the following command on my server
php --ini
I got the following path of my php.ini
Loaded Configuration File: /etc/php/7.0/cli/php.ini
I kept on making changes in this php.ini file, but none of the changes took effect. I then created a file called info.php in my /var/www/html directory and added the following code
<?php
phpinfo();
?>
Then I opened the file in my browser http://example.com/info.php, where I saw that the actual loaded php.ini file was in a different directory
Loaded Configuration File /etc/php/7.0/apache2/php.ini
When I made changes to the php.ini file inside of this directory, all the changes took effect. In summary make sure that you run the phpinfo(); function to make sure of the actual php.ini file which php uses.
service apache2 reload needs to be run as root, even if it does not appear to fail without root. Running sudo service apache2 reload works. This is in Ubuntu 14.04.
Maybe you find 2 directories for php.ini files.
If you search where php.ini is using cli like php --ini maybe it show you /etc/php/7.1/cli/php.ini, but thereis another folder to php-fpm found in /etc/php/7.1/fpm/php.ini and you need to create your new ini file under conf.d folder like /etc/php/7.1/fpm/conf.d/30-user.ini and if you need a ini file to cli command line you need to put your ini file under /etc/php/7.1/cli/conf.d/30-user.ini
I had a very strange experience which caused the same symptom like this.
The point is that my php.ini file contained an old-style comment (starting with hashmark) which, as of php 7.0, is not a comment any more. The incorrect comment confused the ini-parser.
The solution was to replace all # comment symbols with semicolon (;) which is the only standard way for writing comments.
For further details, please read my comment here:
https://serverfault.com/a/1012262/494670
After reading great #Jekis's answer, I solved the same issue for Fedora distribution (it's the same thing, just different path):
After evaluting phpinfo(); output I found out that other .ini files are stored in: /etc/php.d directory
In /etc/php.d I created a new file - 40-user.ini. I added upload_max_filesize and other settings that I wanted to change
Then I restarted apache (httpd)
And then changes were picked up.
Changes to Ubuntu php.ini will not take effect.
Steps to resolve this issue in Ubuntu 18.04 with Nginx 1.18.0.
Check the php version you are running: php -v
Check for syntax errors in php.ini: sudo php-fpm7.4 -t (change to the version you are running).
Use your favorite editor to fix syntax errors.
Restart php-fpm: sudo systemctl restart php7.4-fpm (change to the version you are running).
My results:
PHP: syntax error, unexpected END_OF_LINE, expecting '=' in /etc/php/7.4/fpm/php.ini on line 2
In my case it was a "w" before the [PHP] which must have happened when I was using Ctrl w for searching with nano.

Categories