Corrupted php.ini (wordpress) - php

I have been working on a Wordpress site that hasn't had any updates in many years and preparing it for a theme change as well.
After updating all plugins/Wordpress 5.2/PHP 7.2 everything seemed to be going well however the site has been experiencing intermittent crashing (it will work for awhile then it will crash for 5-10 minutes) [edit: The site crashing was probably not directly caused by the php.ini issue in retrospect]
Looking at the cpanel in the error logs I get the error:
PHP: syntax error, unexpected TC_LABEL, expecting '=' in /home/website/public_html/php.ini on line 1 //sometimes it includes a referer
Running php -i | grep php.ini:
Configuration File (php.ini) Path => /opt/imh/imh-php72/root/usr/lib/php
Loaded Configuration File => /opt/imh/imh-php72/root/usr/lib/php/php.ini
The php.ini (in public_html) contains the same repeated path many times (78,886 times according to my find and replace):
/opt/imh/imh-php72/root/usr/lib/php/extensions/no-debug-non-zts-20170718
Line 1:
/opt/imh/imh-php72/root/usr/lib/php/extensions/no-debug-non-zts-20170718[/opt/imh/imh-php72/root/usr/lib/php/extensions/no-debug-non-zts-20170718P/opt/imh/imh-php72/root/usr/lib/php/extensions/no-debug-non-zts-20170718H/opt/imh/imh-php72/root/usr/lib/php/extensions/no-debug-non-zts-20170718P/opt/imh/imh-php72/root/usr/lib/php/extensions/no-debug-non-zts-20170718]/opt/imh/imh-php72/root/usr/lib/php/extensions/no-debug-non-zts-20170718
I noticed that there was sometimes an extra character after 20170718. I downloaded a local copy and did a find and replace and removed all instances of the path and what was left is a 'normal' php.ini (ie it's as if every character in the file was replaced with path + character)
[edit: Changing the public_html php.ini to php.ini_bk removes the error from cpanel logs]
Personal PS: Please note I am not a PHP nor Wordpress developer (typically I work in the MERN stack)

public_html is not the right place for php.ini
Can you do a
php -i | grep php.ini
You have several options ... make a backup of your "old" php.ini first
rebuild your PHP configuration
download latest PHP
Download PHP source and just copy php.ini template out of that
Sometimes it is better to do a clean install & import than updating a very old WordPress.
Regards Tom

Related

PHP version 5.5 doesn't recognize custom include_path set in php.ini file. Lower PHP version does

My website currently runs on PHP 5.2 on an Apache Linux server (according to my hosting providers info). I want to upgrade to at least PHP 5.5 since there is a feature I need available from that version and above. I am open to also use higher versions like 7, but every version above 5.2 brings the following problem:
When running in PHP 5.2 I successfully added a custom include_path additionally to the default one in the php.ini
php.ini:
[PHP]
include_path = ".:/usr/local/lib/php:/custom/include/path"
register_globals = Off
In the above php.ini code the default path which was already set is
/usr/local/lib/php
and the one I added is
/custom/include/path
(I removed personal information by changing path and file names).
I should mention that the additional include_path is not in the same folder structure. In fact, it is on a different domain. Still the same server, but a different domain, so for the additional path I have to go through the root path of my providers users/... path.
(The domains share the same website content, just in different languages. That is why I want both to be able to access and process a common main include_path since they use the same scripts).
In my website I include php files commonly just like this:
website.php:
<?php
require_once 'external_script_file.php';
?>
As I said, in PHP 5.2 everything runs smoothly. The file is loaded and processed. But as soon as I switch the PHP version up to let's say 5.5 I get this error:
Error in browser:
Warning: require_once(external_script_file.php): failed to open stream: No such file or directory in /[server_path]/website.php on line 7
Fatal error: require_once(): Failed opening required 'external_script_file.php' (include_path='.:/usr/local/lib/php') in /[server_path]/website.php on line 7
(I removed personal information by changing path and file names).
As you see in the error message, he seems to only be able to see the default include path, but not the added custom one.
Do I have to manage something differently regarding the php.ini settings file when operating in a higher PHP version? Or what else could be the issue?
Thanks a lot!
​
You can try using set_include_path() function in your code.
set_include_path('/usr/lib/pear');
Or ini_set()
ini_set('include_path', '/usr/lib/pear');
You didn't mentioned any information about the system you are trying to run PHP on (i.e. what OS, web server, etc), so this is a shot in the dark. If you have multiple PHP versions installed, it's possible that each version has its own php.ini file.
On the page you are trying to load, stick phpinfo();die; at the top of the file. Run the site in PHP 5.2, and see what the "Loaded Configuration File" value is. Then, switch to a newer PHP version, refresh the page, and check if the "Loaded Configuration File" value is the same or not.
Just an accident!
Either the php.ini generator I used, or just me copying back and forth created a space at the beginning of the php.ini file, right before the title [PHP]. Apparently PHP versions higher than 5.2 can't handle that.
So just make sure to not create any unneccessary spaces within, or especially at the beginning of the php.ini file.

Can't run PHP after a new installation of XAMPP

I have been a happy user of XAMPP for years,
but today I have updated to the latest Windows 32 bit version on a Windows 10 machine.
I couldn't see a 64 bit version.
Anyway, all went well,
and once I changed some settings, I was able to see all my old databases under the new phpMyAdmin.
But my PHP scripts are bombing out before they start.
Even phpinfo gives the same error message, which is...
"Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
Fatal error: Unknown: Failed opening required 'F:/My Documents/OneDrive/Webs/htdocs/index.php'
(include_path='.;C:/xampp/php/pear/PEAR') in Unknown on line 0"
The test script of index.php is nothing more than
<?php echo "HELLO"; ?>
The statement in php.ini is
include_path = ".;C:/xampp/php/pear/PEAR"
and there are no other include_path statements.
The directory C:/xampp/php/pear/PEAR does exist.
The index.php file is there.
I don't know why there's a PEAR folder inside a pear folder - that's how Xampp installed it.
I have tried all variations of that include_path statement to no avail.
I have left out one of the pears.
Leaving out the include_path statement altogether just results in the PHP default which is a folder which is definitely not there, so that's no good.
My localhost is inside the OneDrive folder as you can see from the error message, but I have been doing it that way for years.
Now I cannot run any PHP scripts. Pure HTML is no problem.
The new installation of Xampp has totally replaced the old one, and its Control Panel v3.2.2 looks to be working perfectly.
phpMyAdmin seems to be working fine, but not phpinfo, as said.
I have scanned the web for answers to this, and there is plenty of forum Q&A's, but they all tell me to do what I have done.
The computer is Windows 10 Pro, and is fully up to date. Apache 2.4.33.
PHP 5.6.35. Database server is 10.1.31 MariaDB.
I've run out of ideas. Any help will be appreciated.
Thanks Mike.
You need to fix your include_path system variable to point to the correct location.
To fix it edit the php.ini file. In that file you will find a line that says, "include_path = ...". (You can find out what the location of php.ini by running phpinfo() on a page.) Fix the part of the line that says, "\xampplite\php\pear\PEAR" to read "C:\xampplite\php\pear". Make sure to leave the semi-colons before and/or after the line in place.
Restart PHP and you should be good to go. To restart PHP in IIS you can restart the application pool assigned to your site or, better yet, restart IIS all together.
first: check all the paths in the php. ini ( use a search or a grep to check them)
second: check that you don't have any extensions added twice (one in the beginning and one in the end of the file)

my "phpinfo.php" file loads a completely blank page in both firefox and safari [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 7 years ago.
Background: I want to learn PHP and in the tutorial that I'm doing, one of the first things it has you do after getting PHP and mySQL going is to to test it by making a phpinfo.php file and opening it.
Problem: In FireFox, the file loads a blank page. In Safari it only shows the code that I wrote: <?php phpinfo(); ?>.
Steps so far (not necessarily in order):
I followed the steps at http://coolestguidesontheplanet.com/how-to-install-php-mysql-apache-on-os-x-10-6/
I have made a phpinfo.php file using text editor in plain text mode (as opposed to rich text) and saved that in my "sites" folder. This is the only line in that file:
<?php phpinfo(); ?>
In system preferences, I have web sharing turned on and mySQL server running. I have removed the # from in front of the load php 5 module line in the httpd.conf file as per the tutorial I mentioned. I've tried restarting the web server using "sudo apachectl restart" and then restarting Firefox.
I looked for a php.ini file in my etc folder. There wasn't one but I did find a php.ini.default. I duplicated that file and renamed the duplicate to php.ini. I'm not sure this step was a correct step to take but from the little I could find on the internet it looks like somebody else has done this and I thought, why not?. (phpinfo.php loaded a blank page before and after this step)
I typed php -i | grep php.ini into terminal and got the following:
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /private/etc/php.ini
and a timezone warning
So I decided to look for a php.ini in the /private/etc folder and there is one there. ( The one I created was in the /etc folder not the /private/etc folder.)
I have searched the internet including this website for answers.
System info:
When typing php -v into terminal it tells me that I am using PHP 5.3.28
When typing mysql -v into terminal it tells me that I am using mySQL 5.6.10
I am running Mac OS 10.7.5 on a Macbook Pro.
FireFox version: 40.0.3
Safari version: 6.1.6
Questions:
1) Did I correctly create the php.ini file?
2) What am I missing? Why is the phpinfo file not loading in my browser?
3) Is the timezone warning important?
Make sure that your source code file has the .php extension in the end.
If you can see the code of your php file in your browser, probably your apache server is not started or it is not working properly. To set your development environment quickly, I recommend that you download an "all in one package" such as XAMPP server or WAMP server. It comes with everything that you need to get your php project working and it is very easy and quick to install.
Take a look at: https://www.apachefriends.org/index.html
Once you have installed the package, create a folder for your project and put your php file inside it. So, copy your project folder to "htdocs" folder, inside the WAMP or XAMPP path, open your browser and type the URL:
http://localhost/yourProjectFolder/phpinfo.php
You shall see your php file working on.
Good luck!

Fatal error: Call to undefined function mysql_connect() cannot solve

I have searched this error in Google and tried everything I found, but it still does not work.
I have set in my php.ini
extension_dir ="C:\php\ext\"
uncommented
extension=php_mysql.dll
extension=php_mysqli.dll
these files are present in the extension path, and I restarted Apache.
But phpinfo(); still does not show anything about MySQL. So do you have any suggestions to load these modules?
note: I am using Windows 7 (64 bit), MySQL 5.5, Apache 2.0.49 and PHP 5.3.16
Finally, I solved the same problem, so, here is my solution. I guess the last slash in the line
extension_dir ="C:\php\ext\
could make troubles. Just let it as
extension_dir ="C:\php\ext
Moreover, try to approach the problem the following way:
*My PC is running Windows 7 (Apache 2.2 & PHP 5.2.17 & MySQL 5.0.51a), the syntax in the file "httpd.conf" (C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf) was sensitive to slashes.
You can check if "php.ini" is read from the right directory. Just type in your browser "localhost/index.php". The code of index.php is the following:
<?php
echo phpinfo();
?>
There is the row (not far from the top) called "Loaded Configuration File". So, if there is nothing added, then the problem could be that your "php.ini" is not read, even you uncommented (extension=php_mysql.dll and extension=php_mysqli.dll). So, in order to make it work I did the following step. I needed to change from
PHPIniDir 'c:\PHP\'
to
PHPIniDir 'c:\PHP'
Pay the attention that the last slash disturbed everything!
Now the row "Loaded Configuration File" gets "C:\PHP\php.ini" after refreshing "localhost/index.php" (before I restarted Apache2.2) as well as mysql block is there. MySQL and PHP are working together!*
I have been having the exact same problem as you. And I (literally) solved it 2 minutes ago.
I am running Apache 2.4 64 bit on Win 7.
The version of php I downloaded gave me two php.ini files:
1)php.ini-production and
2)php.ini-development
I thought that was all gravy and every time I made a change to one, I did the exact same thing to the other.
When I first encountered the problem I loaded index.php (on my local server) and looked at the sixth box from the top called "Loaded configuration file". It simple said "nothing."
I then referenced this page and found how PHP (once started) goes about looking for the php.ini file. I tried putting both the development and production (referenced above) files in all the directories that the above link specified. Nothing.
Then I thought, what the hell it's worth a shot, and changed the php.ini-production to just "php.ini".
Bam. It started working. Such a simplistic fix but I suppose it makes sense as to why Apache wasn't able to find "php.ini." The file didn't exist verbatim.
I really hope this helps, running into this problem sure sucked.
And I'm sorry if any of this seems patronizing because it is so simple. I always troubleshoot from this site and so many of the answers require more than a fundamental understanding of a subject, and since this seems like a problem(and a solution) that beginners will struggle with, I thought I would spell it out in a way that I would have appreciated 6 months ago.

How do I get php curl to run on my apache2.x Development server?

Before I begin, I will add that I've spent much time googling this and have attempted several solutions none of which have worked.
System Info:
Windows 7 Professional (x86, 32 bit )
Apache2 up and running C:\Program Files\Apache Software Foundation\Apache2.2\
PHP 5.3.8 C:\Program Files\PHP Also works.
manually configured httpd.conf to enable php, note that php is working, except for curl.
I have enabled curl in my php.ini C:\Program Files\PHP\php.ini
This is near the end of my php.ini
[PHP]
extension_dir = "ext"
[PHP_CURL]
extension=php_curl.dll
Note also that the file C:\Program Files\PHP\ext\php_curl.dll exists!
I have restarted the apache server and yet curl still does not function.
a quick test.php file:
<?php
$curl_conn = curl_init();
?>
note that I have both php start and end tags correct stackoverflow just isn't showing the start php tag.
puts out:
Fatal error: Call to undefined function curl_init() in E:\path\to_project\test.php on line 3
I have now spent 3 hours trying to get curl to work, google has no helped, most of the solutions seem to involve making sure that the extension=module line in php.ini is not commented out, and as you can see above it is not commented out so that advice doesn't seem to help me.
Any ideas would be appreciated as this is rather frustrating.
Thanks!
You should add "C:\PHP" to the server's PATH environment variable:
Right-click on My Computer, choose Properties
Flip to the Advanced tab
Click the Environment Variables button
Double-click the Path variable in the list of System variables.
Either add "C:\PHP;" to the beginning or ";C:\PHP" to the end (sans quotes, not both).
Restart your computer for it to take effect.
Thanks to:
http://www.webcheatsheet.com/PHP/install_and_configure.php
I know this thread has long been closed, but for anyone like myself who encounters this problem subsequently, for me, the answer turned out to be a DIFFERENT copy of the php.ini file was being loaded than what I thought. I was editing the php.ini file in my PHP 5.4.3 directory, and there is another copy of the php.ini file that resides in the Apache directory - identical as far as I could tell from a quick glance.
De-commenting the extension=php_curl.dll line IN THE RIGHT FILE, the Apache folder, enabled the curl function for me.
Jeff S.
Have you copied cURL dependency files:
libeay32.dll
ssleay32.dll
to C:\Windows\System32 folder?
It could be that PHP cannot find these two files to run cURL extension.

Categories