Fixing a PHP database connection failure with updated MySQL library - php

I spent some hours trying to solve a migration from CentOS 5.5 to 7 in which everything worked except PHP-based sites connecting to the MySQL server for a Web site. Perl worked fine. CLI commands worked fine. I tried every solution listed on Stack Overflow and elsewhere:
Make sure /etc/hosts contains localhost as the first entry for 127.0.0.1
Check that PHP is correctly pointing to the right socket
Try swapping localhost and 127.0.0.1 in the connection setup
Checked php.ini for any settings that differed between my functional CentOS 5.5 setup and the new stock CentOS 7 installation.
Annoyingly, I couldn't get PHP to dump errors, whether via Apache or elsewhere. It was all maddening.

After checking for the fifth time that I had the right drivers installed, I realized that there are two CentOS/yum packages: one is php-mysql; the other is php-mysqlnd, a native driver.
Uninstalling php-mysql, which is apparently outdated, but which is what I used in CentOS 5.5, and installed php-mysqlnd instantly fixed the problem.
I have been unable to find any other answers of this sort, so perhaps my situation is unique. But I wanted to document it in case someone else came across the same migration issue.

Related

Php version differs between homebrew and localhost

I try to update my php to 8.0 using homebrew. The update worked fine. The “php -v” shows that the actual version is 8.0.14. However when I open my localhost and go to “phpinfo.php” it shows the old version 7.4.22. Obviously my server still uses the old one. How to fix this? How to update the server version. I saw several post about similar problem, but the solutions offered didn’t work for me… I’m using Mac.
Thanks
So after long searching I finally found this step-by-step tutorial.
https://getgrav.org/blog/macos-monterey-apache-multiple-php-versions
What I did:
I added apache to my server;
I added php to my server (now I no longer need XAMPP);
I followed the step by step configuration to connect apache to php (through updates in httpd.conf file).

PHP postgres enable ssl support

Sorry to get back to you for a question that has been asked many years ago. But I am really stuck with this.
I have a legacy application which is very old, running PHP 5.2.17.
I followed this guide to setup my docker container
https://andrewscaya.net/blog/bringing-php-52-back-life
I have everything setup correctly. I made a downloaded and compiled a PHP installation and configured this with Apache. And its working fine with php.
However, it is essential that I have SSL support (in PHP) for the POSTGRES connection.
Which is now default not enabled according to PHPINFO
I have basically the very same problem somebody else had many years ago. SSL support of Pgsql
See:
Enable SSL support for pgsql
So from what I am understanding is that I need to recompile PHP again, but with a package called libpg ?
Where do I get this package and how can I compile this with the PHP source code?
After 2 days of searching I finally found LAPP stack which has some older versions available with pgsql ssl support
https://community.bitnami.com/t/can-i-get-the-installers-for-wapp-and-lapp-stacks-for-5-4-45/38548
In the long-run I would recommend upgrading PHP versions, but I understand that this can be a lot of work. There are many good guides on upgrading versions. I recommend going through the version upgrades one-by-one, dealing with deprecated features and other potential problems one-at-a-time and testing each script.
In the short-term, I'm not sure if this would work, but PDO is supported in 5.2 (actually in 5.1 even) and as it simply passes info to the PostgreSQL library, I would expect SSL support to work. I have used it in 5.4, and I am not aware of any changes made between those two versions.
There is a solution here, by IMSoP, that explains how to get this working and points you to more official documentation if you need more info: Connecting to PGSQL over SSL via PHP PDO
If this fails, a second approach that I would try would be to create an SSH tunnel to connect to a local port. An example would be:
ssh -L 127.0.0.1:5443:127.0.0.1:5432 username#remoteboxaddress
Then you can initiate what looks to PHP like a local connection on port 5433, but it will actually be a (secure) SSH tunnel to the remote box. This will also require that the remote box is configured to accept (non-encrypted) local connections, and that you have SSH access to it. Then, if you test it out and it works, you can make a script to start the tunnel on boot, or better yet, when the webserver is started; this necessitates using an authentication method like keys stored in a file, that doesn't require the entering of a password. So...there are a lot of "if's" here, in terms of whether or not you will be able to get this solution to work, but it can be done if you have root access on both servers, and occasionally if you do not, depending on how they are configured.
Hopefully, one of these two solutions will work for you.

MAMP Unable to Connect to MySQL on localhost (10061) - 2017

I'm trying to create a dynamic drop down list by requesting data from my database using MAMP.
One of the tutorials I have tried has been talked about already and my version of the code is the same. Dynamic dropdown list with PHP & MYSQL
Although I am under the impression MAMP has a SQL server, I thought the problem was because I didn't have MySQL installed on my computer so I downloaded it, to no avail.
I went into my Task Manager and tried looking for "MySQL service" although I couldn't find the exact tag I did see MySQL Writer is running, but the Browser and Agent INFLOW is not and refuse to start.
I went here into my computer ( c://windows/system32/drivers/etc.host ) and took off the #s that were before
127.0.0.1 localhost
::1 localhost
making sure each remained on a separate line, I restarted my computer but I still can't seem to connect.
Any suggestions on how I may be able to fix this? I am extremely new to PHP and even newer to MySQL so, if possible, please try to keep any solutions simplified so I can follow along.
Not sure what the issue actually was but I ditched MAMP and installed XAMPP and everything seems to be working now.

Running PHP and MySQL with XAMPP in Ubuntu (laravel)

I'm quite new to Linux and still trying to adapt my self. I've setup my working environment all good, installed XAMPP, node, sublime, etc. But when I tried running a laravel app, the first thing that caught me was I couldn't run php.
I was confused because i had already installed XAMPP (which i thought would've done it all for me), but then I simply created a symlink in my /usr/bin to the /opt/lampp/bin/php and it all worked well (I'm not sure if that was all correct, but it worked).
Then when I tried opening the app in my browser, it couldn't find the sql driver, so I asked my self, what exactly am I doing wrong? XAMPP should have taken care of all those things (as its name suggests), but it didn't setup php and mysql as i thought it would.
Am I missing something here? Should I install MySQL driver and PHP apart from XAMPP? Because that makes no sense at all for me. I really need some basic guidance here about this whole thing, what makes it so different from Windows where I simply install XAMPP and start programming?
I need to understand that so I can have a better understanding of the system it self and fix these kind of problems my self in the future.
PS: I'm using Ubuntu 16.04 and instaled XAMPP with PHP 7.0, downloaded from official website.
Thanks everyone!
I never used xampp on linux myself so i dont know how does it work here but I can tell you what really got me good start at understanding of linux was installing whole LAMP stack myself. So i would recommend googling 'How To Install LAMP' and try to figure it out from countless tutorials.
Basically you install apache, then mysql and php, restart server and check if 'It works'.
try two things
In the folder /etc/php/php.ini
uncheck the line extension=pdo_mysql.so
or in the folder of lampp (/opt/lampp/etc/php.ini)
And to start Laravel you need start with ~/php artisan serve
in the browser localhost:8000

NewRelic install on centos and cpanel

I'm trying to install NewRelic on my website, I use PHP, cPanel(VPS/dedicated) and Centos (64bit) for my server, I've installed the server monitoring part right on my server but when I try to install the 'app' part on my server I can't get that to install, I followed the instruction links http://newrelic.com/docs/php/new-relic-for-php
but to no success, has anyone got any ideas as to why this maybe? I have restared httpd and appache multiple times and given it some time to propogate etc..
The problem of this is having WHM installed and many PHP services installed, you should try this guide I found:
New Relic for PHP w/cPanel
We have few dedicated servers on HostGator. Few months back we had installed "NewRelic" on our server for monitoring, later we started having issues and here is what HostGator Tech Team said
"While it's possible to configure a cPanel server to use a non-cPanel
PHP version, it's complicated to configure and we will not support it
or set it up. PHP gets compiled from source by cPanel normally and it
should be left this way, as it interacts with a number of other
components on the server in complicated ways, as you found out today.
We recommend completely removing the custom "Newrelic" repository as
well as the packages it installed in order to avoid further
compatibility problems."
and here is what "NewRelic" team said
"I wasn't trying to suggest that Hostgator's assertion was wrong. I
was just trying to figure out which instructions to go over with you."
Make sure to check compatibility before installing it. Installation instruction can be found at http://www.networkredux.com/answers/view/Hosting/Control_Panels/WHM/cPanel/162
New Relic Needs to document this cpanel compatibility better, I know it's my fault for not researching but while using a hostgator dedicated server with cpanel/whm I got new relic up and running. . then my server became a huge mess if improperly configured files and a few days of reading and learning to get it straightened out - I understand my fault entirely but a big ass CPANEL/WHM <- CAREFULL sign might have helped :P

Categories