Skip to content

Instantly share code, notes, and snippets.

@kstan79
Last active March 18, 2023 09:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kstan79/367ef928e44523904fb36b67a92decdd to your computer and use it in GitHub Desktop.
Save kstan79/367ef928e44523904fb36b67a92decdd to your computer and use it in GitHub Desktop.
Allow Ubuntu PHP application connect to Percona/MariaDB PAM Authenticate Backend
#!/bin/bash
# install basic package, ensure basic function of php/apache/mysql is working properly
sudo apt install apache2 libapache2-mod-php7.0 php7.0 php7.0-cli php7.0-mysql git libmysqlclient20 libmysqlclient-dev php7.0-dev
# to support PAM, we need to use percona server/client
wget https://repo.percona.com/apt/percona-release_0.1-4.$(lsb_release -sc)_all.deb
sudo dpkg -i percona-release_0.1-4.$(lsb_release -sc)_all.deb
sudo apt-get update
#install database server application, it will install database client too. If you not required database server, you can install later on apt remove package
#percona-server-server-5.7 after you backup /usr/lib/mysql, cause inside consist required library for pam authentication
sudo apt-get install percona-server-server-5.7
# we wish to use ubuntu default php, cause it is much easier to maintain, however, we need to recompile extension mysql related extension to use unix libmysqlclient20-dev.
# according to php, it is not recommended. But, we need to do that since they wont plan to support external mysql authentication
git clone https://github.com/php/php-src.git
cd php-src
git checkout PHP-7.0.25
#start compiling mysqli, override php's mysqli connection library
cd ext/mysqli # or pdo_mysql depends which connector, u can do both
phpize
./configure --with-mysqli=/usr/bin/mysql_config
make
sudo cp modules/mysqli.so /usr/lib/php/20151012
#start comiling pdo_mysql, override php's pdo_mysql connection library
cd ext/pdo_mysql # or pdo_mysql depends which connector, u can do both
phpize
./configure --with-pdo-mysql=/usr/bin/mysql_config
make
sudo cp modules/pdo_mysql.so.so /usr/lib/php/20151012
#if you to not required database server can do following
# sudo cp -a /usr/lib/mysql /usr/lib/mysql2
# sudo apt remove percona-server-server-5.7
# sudo cp -a /usr/lib/mysql2 /usr/lib/mysql
echo "now, test create a php file connect to any mysql server "
@kstan79
Copy link
Author

kstan79 commented Feb 8, 2018

Hope above script can help everybody who headache with pam authentication, I'm headache for this quite long time.

@adikusdianto
Copy link

Dear kstan79,

trying to compile it on centos 7, with php 7.0.31 latest, but i am stuck on error
line no 24

configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing libtool commands
configure: WARNING: unrecognized options: --with-pdo-mysql

on line 31, i have no problem

Thank you for your kind assist.

@kstan79
Copy link
Author

kstan79 commented Feb 10, 2019

sorry not aware your message, can you try use 7.0.25? I never try 7.0.31, i think it should work but not sure whats wrong.

@kstan79
Copy link
Author

kstan79 commented Feb 10, 2019

try install php7.0-dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment