php: mysql_connect() failing with no error message - php

I am running a simple test script from the command line on CentOS 5.6 with the PHP package installed from PHP 5.3 on CentOS/RHEL 5.6.
PHP runs fine in all other cases but when I hit mysql_connect() it fails without error.
If I run
$ php -m
I am not seeing MySQL as an installed module.
However I have added extension=mysql.so to my php.ini and rebooted.
Output of 'rpm -qa | grep php'
php-common-5.3.10-1.w5
php-5.3.10-1.w5
php-cli-5.3.10-1.w5
Output of 'yum install php-mysql'
--> Missing Dependency: php-common = 5.1.6-27.el5_7.5 is needed by package php-mysql-5.1.6-27.el5_7.5.x86_64 (updates)
php-pdo-5.1.6-27.el5_7.5.x86_64 from updates has depsolving problems
--> Missing Dependency: php-common = 5.1.6-27.el5_7.5 is needed by package php-pdo-5.1.6-27.el5_7.5.x86_64 (updates)
Error: Missing Dependency: php-common = 5.1.6-27.el5_7.5 is needed by package php-pdo-5.1.6-27.el5_7.5.x86_64 (updates)
Error: Missing Dependency: php-common = 5.1.6-27.el5_7.5 is needed by package php-mysql-5.1.6-27.el5_7.5.x86_64 (updates)
You could try using --skip-broken to work around the problem
You could try running: package-cleanup --problems
package-cleanup --dupes
rpm -Va --nofiles --nodigest
The program package-cleanup is found in the yum-utils package.

I am not seeing MySQL as an installed module.
Did you install it?
# yum install php-mysql
(from the same repo you installed php from).
EDIT:
run this:
yum --enablerepo=webtatic install php-mysql
this tells yum to get the packages from webtatic repository (in addition to system configured repositories). If you want webtatic among system enabled repositories, run:
yum --enablerepo=webtatic install webtatic-release

First, some advice: stop using mysql libraries and use PDO or at least the mysqli libraries.
Now for some troubleshooting help: the first step is to be 100% sure the mysql is loading. Create a script (web based) with:
phpinfo();
Confirm that somewhere on this page there is a block indicating that the mysql extension is being loaded.
Wherever you are testing an are uncertain of errors, right before you call mysql_connect add these lines:
ini_set('display_errors', 1);
ini_set('log_errors', 1);
error_reporting(E_ALL | E_STRICT);
This will ensure you aren't suppressing the errors somewhere else before the connect. Some frameworks sometimes do this.
If it's indeed the module is loading and with the added error logging code you still don't get a valid error. I'd try connecting in a command line php script. Look in the php.ini file to see what "error_log" is set to. This is the default log it will it will log to--sometime http based settings override logging, so even if errors are thown, you don't see or can't find them. A command line php script factors this out.
Last but not least, you can always post your connection string to this post. Try connecting from the command line on the server as your script using the mysql command with the same credentials as your mysql_connect. You might be able to connecting just fine, but have bad credentials.
If the module is not loading, try to find exactly where the module resides and put the full path into the php.ini. Yum sometimes installs stuff not where php.ini is looking for it. At the end of the Yum install, it sometimes tells you the path, if not, to find it with brute force, do this:
cd /
find . -name 'mysql.so'
so in the php.ini, instead of
extension=mysql.so
put
extension=/path/to/found/mysql.so
Good luck!

Related

PHP 7 on CentOS 7.4

I am trying to set up a web server to host Moodle on and I've been running into problems when trying to install PHP7.
I am currently using VirtualBox to host CentOS 7.4. By default, CentOS comes packaged with PHP 5.4.16. Now, from what I have read, the options for upgrading and installing from scratch are different. I have tried to follow multiple sites that guide towards getting PHP7 but have had no luck. The majority of guides tell you to install two repositories, Remi and EPEL. The main problem I have is that every time I install epel, yum either breaks or prevents me from installing another package.
[root#localhost ~]# yum update
Loaded plugins: fastestmirror, langpacks
Could not retrieve mirrorlist http://mirrorlist.centos.org/?
release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
One of the configured repositories failed (Unknown),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled
yum --disablerepo=<repoid> ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable <repoid>
or
subscription-manager repos --disable=<repoid>
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true
Cannot find a valid baseurl for repo: base/7/x86_64
I have tried many ways of fixing this. Some of the main ways are:
yum clean all
yum --enablerepo=base clean metadata
rm -rf /var/cache/yum
I did get around this once or twice by using
yum --enablerepo=epel clean metadata
and also
sed -i "s/mirrorlist=https/mirrorlist=http/" /etc/yum.repos.d/epel.repo
I know there are more ways that I have tried, but I cannot remember all of them. Moral of the story is that they don't usually help. Sometimes yum works fine and I will run yum clean all, and it stops functioning again.
Method 2:
Another method I tried was installing the rpm packages from their respective websites. I used WinSCP to transfer the files to my VM and then used yum to install them. Everything works well and I got epel and remi to install. But then yum doesn't work properly.
Sometimes it will install packages, but some will not install. I've set the yum timeout value higher and other packages get through, but some still do not. Then I clean up the yum cache and once again I see the message with five options.
Method 3:
I found documentation on installing PHP 7 from https://wiki.centos.org/HowTos/php7 and I thought it must work because this is the supported way.
I followed along right up until the first part.
root # centos7-vm: ~ # yum -y install centos-release-scl.noarch
I will either get the error message stating the package could not be downloaded from a mirror or if yum is already giving me issues, it will show the five options to clean yum.
Method 4:
Building PHP from source was another option I attempted. I navigated to http://php.net/downloads.php and downloaded the tarball and used WinSCP to get it on my machine.
I extracted the files and then navigated into the php directory.
I attempted to get things going by using ./configure, but it stated I needed gcc.
I tried to install gcc with yum install gcc, but could not install all of the packages.
I made a new VM and instantly tried installing gcc, but still not luck.
Summary
Sometimes I understand why yum does not work, other times I'm slamming my head on my desk.
Is there a standardized method of getting PHP 7 on CentOS? Can anyone link an accurate guide?
What is the reason that CentOS comes packaged with PHP 5.4 and not 7?
I feel like I have tried almost everything, but I know there is some webpage that I just haven't found yet. I think I did about all the research I possibly could for today.
I'm sure my question is probably not structured the best and might be a little confusing, but I've been working on this for about 6-7 hours now.
This is my first post, so I apologize if it is not perfect.
in my vps, I just added remi repo,
$ wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
$ rpm -Uvh remi-release-7.rpm
or
$ rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
then you enable on /etc/yum.repos.d/ on remi.repo, and remi-php72.repo files.
later you update, and install php and its libraries.
epel is not necesary, but is in the official repo. you just got to do a
$ yum install epel-release
and enable the file in /etc/yum.repos.d/
have you check some logs files? to see if there's any errors

How do I use php-fpm on RHEL 7.2?

I'm new to configuring Apache and I'm trying to optimize my Apache server. Reading through the documentation, I found that I should be using the Event MPM instead of the Prefork MPM. Everything was straight forward until this point as I only had to comment out Prefork and uncomment Event in 00-mpm.conf. However, when I restarted Apache, I got the following error -
AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration
Digging for some more information, I found out that mod_php should not be used with Event. So, I'm commented out php_value in php.conf and also commented out LoadModule in 10-php.conf.
My webpages wouldn't load anymore and I realized that I should be using php-fpm. However, documentation regarding this is really unclear and I'm not sure how to use it. I tried this -
[root#ip-xxx-xx-xx-xxx ~]# yum install php-fpm
Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
Resolving Dependencies
--> Running transaction check
---> Package php70w-fpm.x86_64 0:7.0.4-1.w7 will be installed
--> Processing Dependency: php70w-common(x86-64) = 7.0.4-1.w7 for package: php70w-fpm-7.0.4-1.w7.x86_64
--> Running transaction check
---> Package php70w-common.x86_64 0:7.0.4-1.w7 will be installed
--> Processing Conflict: php70w-common-7.0.4-1.w7.x86_64 conflicts php-common < 5.5.0
--> Finished Dependency Resolution
Error: php70w-common conflicts with php-common-5.4.16-36.el7_1.x86_64
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
I'm not sure how to proceed and would really appreciate any help with this problem. Thank you!
You will need to remove your current installation of php and php-common will be uninstalled as a dependency.
I can confirm that I have just done this and found that when I uninstalled php a large number of related packages were also removed, so you will need to add the relevant php70w versions of various plugins (such as php70w-fpm, php70w-mysql, etc)
I also found that roundcube was uninstalled, but am now planning to install the latest version of this now that I have PHP 7

Upgraded PHP to 5.6.16 and MySQL Extension not working

I was running a very outdated version of PHP version 5.3.3. So I updated it to 5.6.16. However since I've updated I am getting the following error when I try to view my Wordpress site:
Your PHP installation appears to be missing the MySQL extension which is required by WordPress.
I understand that the reason for this error is because the mysql extension is not being loaded by PHP but I am unsure as to what to do to get this? I've checked my php.ini file and uncommented this line
extension=msql.so
restarted my apache server and no luck!
The Code I am using to check if it is enabled is:
if (extension_loaded('mysql') or extension_loaded('mysqli')) {
echo "Loaded";
}else{
echo "Not Loaded";
}
when I run php -m in my terminal I see mysql is not listed.
Could anyone help me out with getting this to work.
I've also tried running this command yum install php-mysql but I get this error:
Finished Dependency Resolution
Error: php56w-common conflicts with php-common-5.3.3-46.el6_6.i686
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
Thanks
Have you tried yum install php56w-mysql?
That should install the 5.6 version of the MySQL libraries. It looks like yum is trying to install the 5.3 version by default. Out of curiosity, what OS is this you are installing on, it might be a little out of date.

memcached php sessions on heroku

I had noticed that an application I have setup on heroku only shows sessions variables on random requests when I refresh the browser. I put this down to the fact the application is running on 5 dynos.
I followed the following tutorial to solve this with memcached using memcachedcloud.
https://devcenter.heroku.com/articles/php-sessions#storing-sessions-in-memcached
The issue still remains though. I am using the PHP slim framework, is there any further config I need for this? I cant seem to find anything in the slim docs.
EDIT:
I can not produce the required composer.lock file because when running.
composer update
I get the error
The requested PHP extension ext-memcached * is missing from your system.
But it is in fact installed. I can see the version from typing.
memcached -h
But it is not present when typing
composer show --platform
Depending on what platform you're running, you have to make sure you that composer updates. Even if you have memcached installed, it has to match your PHP version. Then, once installed, run composer update
For example:
If you have PHP5.6.15, get memcached with, either, brew install php56/memcached or sudo apt-get install php56/memcached.
Then run composer update.
If you have an issue installing composer on Mac, you have to enable rootless install. More info can be found here:
https://donatstudios.com/OS-X-Mavericks-Memcached-PHP-Extension-Installation
The gist of the steps to take are:
Restart computer and hold Command + R to get into recover mode
Get into the terminal from Utilities
Run csrutil disable and restart
This should be done prior to installing memcached from Homebrew.
Hope this helps.
I had a similar issue, where I was getting the same "ext-memcached * is missing" error and could not see ext-memcached when running composer show --platform.
I noticed that when I originally installed memcached, homebrew showed me various alternatives. So on Mac OSX El Capitan, I ended up installing the one that matched my PHP version:
brew install homebrew/php/php55-memcached
And then I had to add it to php.ini:
extension=/usr/local/Cellar/php55-memcached/2.2.0/memcached.so
You can get the correct version path with:
brew info php55-memcached
And then I restarted Apache:
sudo apachectl restart
It finally showed up in the composer list and I was able to update composer without error.

Running PHP 5.3 on CentOS 5.4 - fatal error Class 'PDO' not found

What is the best way to get PHP 5.3 up and running on CentOS 5.4.
My machine says I have PHP 5.3 installed but running into an issue with my script that says
Fatal error: Class 'PDO' not found in /var/www/html/lib/rb.php on line 45
It fails trying to new up a PDO class in the RedbeanPHP 3.0 lib.
How can I fix this missing PDO problem?
I tried to follow these instructions:
from http://www.computingunplugged.com/issues/issue201102/00002619002
rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
# THIS LINE FAILED FOR ME
rpm -Uvh http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/ius-release-1.0-6.ius.el5.noarch.rpm
yum erase php php-pear php-mysql php-cli php-common
yum install php53u php53u-pear php53u-cli php53u-common php53u-gd
yum install php53u-mbstring php53u-mcrypt php53u-mysql php53u-soap
yum install php53u-xml php53u-xmlrpc php53u-bcmath
UPDATE
Someone removed their answer. It was good. I'm putting it back in with exact steps.
First I had to yum install php53u-devel
To quote "
You need the PDO extension. Usually the best way to install extensions is via PECL.
Before you can install any PECL extensions you need to install the php5-dev package
sudo pecl install pdo
sudo pecl install pdo_mysql
You then need add the following to the end of your php.ini file(s). Depending on which version of PHP you installed they’ll be /etc/php5/apache2/php.ini, /etc/php5/cgi/php.ini and /etc/php/cli/php.ini.
extension=pdo.so
extension=pdo_mysql.so
"
Now I get a mysql_query_missing when trying to run sudo pecl install pdo_mysql
and not sure how to get past this.
You'll have to install the php-pdo package as well.
Edit: Maybe this helps as well: How do I enable PDO using CentOS?
I have been successfully able to install PHP-5.3 on CentOS 5.4 Linux. I needed this to be able to successfully install and run Drupal 7 - which also worked out for me. Here are the details:
This is a copy of the answer I wrote up in ServerFault: https://serverfault.com/a/392168/29205
(...for my question: https://serverfault.com/questions/391772/php-xml-install-complains-of-dependency-php-common-but-this-is-already-installed/392168#392168 )
The solution is based on the accepted answer in:
https://serverfault.com/questions/391839/how-to-force-centos-yum-to-use-a-later-version-of-a-package-dependency-already-i
In summary: move to php5.3.
Reason: support for php5.2 as been removed owing to security issues as explained in that other question's accepted answer. This removal causes mismatch of the versions of the dependencies and therefore the error seen.
Background
I wanted to run Drupal 7 on a CentOS 5.4 machine. So I needed 5.3 version of PHP.
Here are the full working steps to upgrade to PHP 5.3 with working repositories as of May 24 2012 ( I provide comments preceded by # - you don't need these, just for your info)
# Comment: sites like http://www.computingunplugged.com/issues/issue201102/00002619001
# provide a good start for remedying the problem whereby we need 5.3 on CentOS 5.4 to run Drupal 7. But although their packages worked at the time, the links are now outdated, and updates to these are below.
# comment: (as of May 2012 - the following work, the reason for failures was use of 1) older packages no longer on the server and 2) change of address of one of the servers to dl.fedoraproject.org/pub/epel (credit to: http://osdir.com/ml/centos/2012-03/msg00057.html )
rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -Uvh http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/ius-release-1.0-10.ius.el5.noarch.rpm
yum erase php php-pear php-mysql php-cli php-common
yum install php53u php53u-pear php53u-cli php53u-common php53u-gd
yum install php53u-mbstring php53u-mcrypt php53u-mysql php53u-soap
yum install php53u-xml php53u-xmlrpc php53u-bcmath
# After doing the above, php -v shows 5.3.x But on attempting to install Drupal 7 you may get complaint of something "Your PHP installation is too old 5.1.6 Drupal requires at least PHP 5.2.4. See the system requirements page for more information." and php.info shows the same
# The remedy is to simply restart your apache server
service httpd restart
# credit to following for suggesting service httpd restart :-
# https://serverfault.com/a/207806/29205
# https://serverfault.com/questions/207762/centos-updating-php-via-yum-doesnt-change-the-version-apache-uses
# Drupal 7 install on CentOS 5.4 worked after applying the above steps
# If your MySQL server is not running (check by ps -ef | grep mysql ) then you can run:
/etc/init.d/mysqld
# ...to start it, and to make sure it starts when the machine is restarted or cold booted:
chkconfig mysqld on

Categories