#!/bin/bash
rel=$(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release))
if [ $rel == "6" ]; then
    rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
    rpm -ivh http://rpms.remirepo.net/enterprise/remi-release-6.rpm
elif [ $rel == "7" ]; then
    rpm -ivh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
    rpm -ivh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
else
  echo "Only CentOS supported"
  exit
fi

yum  -y update
sed -i 's/enabled=0/enabled=1/g' /etc/yum.repos.d/remi-php73.repo
yum install -y php73-php-mbstring php73-php-mcrypt php73-php-fpm php73-php-gd php73-php-devel php73-php-cli php73-php-pecl-memcached php73-php-pdo php73-php-mysqlnd php73-php-xml php73-php-opcache unzip make wget git gcc-c++ zlib zlib-devel openssl openssl-devel cyrus-sasl2 cyrus-sasl-devel
mkdir /var/log/php/
mv /etc/opt/remi/php73/php-fpm.conf /etc/opt/remi/php73/php-fpm.conf.bak
wget http://list.downsoft.cn/Linux/php7.3/php-fpm.conf -O /etc/opt/remi/php73/php-fpm.conf
#sed -i 's/user = apache/user = nginx/g' /etc/opt/remi/php70/php-fpm.d/www.conf
#sed -i 's/group = apache/group = nginx/g' /etc/opt/remi/php70/php-fpm.d/www.conf
#sed -i 's/listen = 127.0.0.1:9000/listen = 127.0.0.1:9007/g' /etc/opt/remi/php70/php-fpm.d/www.conf
chown -R nginx:nginx /var/opt/remi/php73/lib/php/
mv /etc/opt/remi/php73/php.d/10-opcache.ini /etc/opt/remi/php73/php.d/10-opcache.ini.bak
wget http://list.downsoft.cn/Linux/php7.3/10-opcache.ini -O  /etc/opt/remi/php73/php.d/10-opcache.ini  

mkdir /opt/php7 && cd /opt/php7
git clone https://github.com/phpredis/phpredis.git
cd phpredis/
/opt/remi/php73/root/usr/bin/phpize
./configure -with-php-config=/opt/remi/php73/root/usr/bin/php-config
make && make install
echo 'extension=redis.so' > /etc/opt/remi/php73/php.d/40-redis.ini
/usr/bin/php -m | grep redis

cd /opt/php7
git clone https://github.com/jonnywang/phpssdb.git
cd phpssdb/
git checkout php7 
/opt/remi/php73/root/usr/bin/phpize
./configure -with-php-config=/opt/remi/php73/root/usr/bin/php-config
make && make install
echo 'extension=ssdb.so' > /etc/opt/remi/php73/php.d/40-ssdb.ini
/usr/bin/php -m | grep ssdb

cd /opt/php7
wget https://pecl.php.net/get/yaf-3.0.7.tgz
tar zxvf yaf-3.0.7.tgz
cd yaf-3.0.7
/opt/remi/php73/root/usr/bin/phpize
./configure -with-php-config=/opt/remi/php73/root/usr/bin/php-config
make && make install
echo 'extension=yaf.so' > /etc/opt/remi/php73/php.d/40-yaf.ini
/usr/bin/php -m | grep yaf


cd /opt/php7
git clone https://github.com/edenhill/librdkafka/
cd librdkafka
./configure
make && make install



cd /opt/php7
git clone https://github.com/arnaud-lb/php-rdkafka.git
cd php-rdkafka
git checkout php7
/opt/remi/php73/root/usr/bin/phpize
./configure -with-php-config=/opt/remi/php73/root/usr/bin/php-config
make all -j 5
make install
echo 'extension=rdkafka.so' > /etc/opt/remi/php73/php.d/40-kafka.ini
/usr/bin/php -m | grep kafka

ln -s /usr/bin/php73 /usr/bin/php

if [ $rel == "6" ]; then
    chkconfig php73-php-fpm on
    /etc/init.d/php73-php-fpm start
elif [ $rel == "7" ]; then
    systemctl enable php73-php-fpm.service
    systemctl start php73-php-fpm.service
fi
php -V
