Linux – Configuring PHP for existing MySQL installation

apache-2.2centoslinuxMySQLPHP

I am taking over basic administration duties for a former tech employee for my client. On a CentOS server I have the following:

Apache, PHP and MySQL. He had PHP installed but did not configure it with the MySQL extension (I assume because the server was only hosting a rails-based website).

So I need to reconfigure PHP to use the MySQL extension. Here is the current PHP configure (from phphinfo(); ):

'./configure' '--build=i686-redhat-linux-gnu' '--host=i686-redhat-linux-gnu' '--
target=i386-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--
bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--
includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--
localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--
infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib' '--with-config-
file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--
disable-rpath' '--without-pear' '--with-bz2' '--with-curl' '--with-exec-dir=/usr/bin' '--
with-freetype-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' '--
with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-
png' '--with-pspell' '--with-expat-dir=/usr' '--with-pcre-regex=/usr' '--with-zlib' '--
with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' 
'--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-track-vars' '--enable-
trans-sid' '--enable-yp' '--enable-wddx' '--with-kerberos' '--enable-ucd-snmp-hack' '--
with-unixODBC=shared,/usr' '--enable-memory-limit' '--enable-shmop' '--enable-calendar' '--
enable-dbx' '--enable-dio' '--with-mime-magic=/usr/share/file/magic.mime' '--without-
sqlite' '--with-libxml-dir=/usr' '--with-xml' '--with-system-tzdata' '--with-
apxs2=/usr/sbin/apxs' '--without-mysql' '--without-gd' '--without-odbc' '--disable-dom' '--
disable-dba' '--without-unixODBC' '--disable-pdo' '--disable-xmlreader' '--disable-
xmlwriter'

You can see that he has –without-mysql in there.

When you configure PHP to use –with-mysql, you have to specify the path to mysql right? Or the mysql source? Or something like that? Something like this:

--with-mysql=/usr/local/mysql

The problem with this existing setup is that MySQL is already installed, except I don't know where its installed at… I know that there is /etc/init.d/mysqld. I also found the following directories:

/usr/lib/mysql/
/usr/include/mysql/
/usr/share/mysql/

Can anyone point me in the right direction here? I just don't know what directory to use with –with-mysql in the PHP configuration.

UPDATE

Okay so I got PHP reconfigured and remade and installed. Now when I restart Apache I get the following:

[warn] module php5_module is already loaded, skipping

Is this because php was already running on the server before? I looked at the httpd.conf and it only has one instance of php5_module getting loaded…

However, when now view the phpinfo(); it shows the PHP being used in the new updated version that I just configured/installed.

Also, the phpinfo(); shows mysql as being used, however when I attempt to install say, WordPress (which uses MySQL), WordPress is giving this error:

Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

Where should I be looking now?

UPDATE #2

Still no solution so far. I've gone through the configuration of PHP to include Mysql and the phpinfo(); (yes I'm using a file.php to view this) shows –with-mysql=shared,/usr (per another users suggestion below). PHP still isn't recognizing MySQL extension as being in the configuration however.

I just don't understand what is the path that you are supposed to put at the end of –with-mysql= ? I have the following directories I've found:

/usr/bin/ contains:
mysql (executable?)

/usr/lib/mysql/ contains:
libdbug.a    libmyisammrg.a      libmysqlclient_r.so         libmysqlclient.so         libmystrings.a  mysqlbug
libheap.a    libmysqlclient.a    libmysqlclient_r.so.15      libmysqlclient.so.15      libmysys.a      mysql_config
libmyisam.a  libmysqlclient_r.a  libmysqlclient_r.so.15.0.0  libmysqlclient.so.15.0.0  libvio.a

/usr/include/mysql/ contains:
chardefs.h  keymaps.h       my_config.h       my_global.h      mysql_com.h      mysql_time.h     readline.h    sql_common.h       tilde.h
decimal.h   m_ctype.h       my_config_i386.h  my_list.h        mysqld_ername.h  mysql_version.h  rlmbutil.h    sql_state.h        typelib.h
errmsg.h    m_string.h      my_dbug.h         my_net.h         mysqld_error.h   my_sys.h         rlprivate.h   sslopt-case.h      xmalloc.h
history.h   my_alloc.h      my_dir.h          my_no_pthread.h  mysql_embed.h    my_xml.h         rlshell.h     sslopt-longopts.h
keycache.h  my_attribute.h  my_getopt.h       my_pthread.h     mysql.h          raid.h           rltypedefs.h  sslopt-vars.h

/usr/share/mysql/ contains:
charsets  english               french     italian      my-innodb-heavy-4G.cnf  mysql_fix_privilege_tables.sql  norwegian     romanian  spanish
czech     errmsg.txt            german     japanese     my-large.cnf            mysql_system_tables_data.sql    norwegian-ny  russian   swedish
danish    estonian              greek      korean       my-medium.cnf           mysql_system_tables.sql         polish        serbian   ukrainian
dutch     fill_help_tables.sql  hungarian  my-huge.cnf  my-small.cnf            mysql_test_data_timezone.sql    portuguese    slovak

Does any of that help?

UPDATE 3

Yes I'm using virtual hosts. Here is my conf file:

Listen 80
NameVirtualHost *:80

<VirtualHost *:80>
        ServerName thedomain.com
        ServerAlias www.thedomain.com
        DocumentRoot /u1/thedomain.com/public
        RailsEnv production
</VirtualHost>

<VirtualHost *:80>
        ServerName subdomain.thedomain.com
        DocumentRoot /u1/subdomain.thedomain.com/public
</VirtualHost>

I'm attempting to setup a basic WordPress install on the subdomain. I'm getting this error still:

Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

SOLVED

I just added –with-mysql (with no path) to the PHP config and reinstalled it and PHP just found what it needed from MySQL on its own apparently. Thanks for the insight everyone.

Best Answer

Unless mysql is installed in a non standard location you should be able to just specify --with-mysql with no path. you may also want --with-mysqli to get the new improved mysql interface.