Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This file allow us to use native client instead of mysqlnd so that php can use custom mariadb authentication like pam_unix or pam_gssapi
#!/bin/bash
#preparing mariadb client
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,arm64,i386,ppc64el] http://download.nus.edu.sg/mirror/mariadb/repo/10.3/ubuntu xenial main'
# install basic package, ensure basic function of php/apache/mysql is working properly
sudo apt install apache2 libapache2-mod-php7.2 php7.2 php7.2-cli php7.2-mysql git libmysqlclient20 libmysqlclient-dev php7.2-dev
# install mariadb client and some library
sudo apt install mariadb-client-10.3 mariadb-plugin-gssapi-client libmariadb-dev libmariadbclient18
# due to at mariadb_config not included mariadb/server header file, work arround is copy all into mariadb folder
sudo cp -a /usr/include/mariadb/server/*.h /usr/include/mariadb
sudo cp -a /usr/include/mariadb/server/mysql/* /usr/include/mariadb/mysql
# 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.2.10
#start compiling mysqli, override php's mysqli connection library
cd ext/mysqli # or pdo_mysql depends which connector, u can do both
sed -i 's/mysqlclient/mariadbclient/g' config.m4
phpize
./configure --with-mysqli=/usr/bin/mariadb_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/mariadb_config
make
sudo cp modules/pdo_mysql.so.so /usr/lib/php/20151012
echo "now, test create a php file, use command line try connect to any mariadb server"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.