Sunday, May 8, 2016

Auto Updating phpMyAdmin without hassle

You can use below bash code on CentOS/Fedora and RedHat to auto update phpMyAdmin:

GitHub Code: https://github.com/mason-chase/phpMyAdmin-auto-update

Edit two options: PHPMYADMIN_FULL_PATH=/var/www/ and PHPMYADMIN_FOLDER_NAME=phpmyadmin

install.sh
#!/bin/bash  
# Copyright Mason Chase (sid@moontius.com)
# DISCLAIMER: install.sh SCRIPT AND ITS CONTENT ARE DESIGNED AND TESTED UNDER CENTOS/FEDORA/REDHAT AND YOU MAY USE IT AT YOUR RISK ONLY.

# Download latest rpmforge to get 7zip in our system
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm -O /usr/src/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

# install yum reposity
rpm -ivh  rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm

# install 7zip with yum
yum install p7zip -y

# append some cron entry 
crontab -l | { cat; echo "
# Auto Update phpMyAdmin everyday at 4AM
0 4 * * * /usr/bin/phpmyadmin_update.sh"; } | crontab -

# 
cat >/usr/bin/phpmyadmin_auto_update.sh << 
EOL
#!/bin/bash  

# Copyright Mason Chase (sid@moontius.com)
# DISCLAIMER: install.sh SCRIPT AND ITS CONTENT ARE DESIGNED AND TESTED UNDER CENTOS/FEDORA/REDHAT AND YOU MAY USE IT AT YOUR RISK ONLY.

#echo on
set -x


# must have beginning slash and trailing slash
PHPMYADMIN_FULL_PATH=/var/www/

# must not have beginning or trailing slash
PHPMYADMIN_FOLDER_NAME=phpmyadmin

#  Download phpmyadmin download page
/usr/bin/wget https://www.phpmyadmin.net/downloads/ -O /tmp/phpmyadmin-download.html
# Map Latest phpmyadmin English with 7-zip format using regex
MYSQL_URL=\$(cat /tmp/phpmyadmin-download.html|grep -e "

Then:
sudo ./install.sh

Thursday, May 5, 2016

Upgrade/Update PHP 5.5 or PHP 5.6 to PHP 7.0

Install latest remi (6.6)
Below is the series of yum commands to easily upgrade php 5.5 or PHP 5.6 to PHP 7.0
# install latest remi (6.6)
rpm -Uvh http://rpms.famillecollet.com/store/remi/release/6.6/remi-release-6.6-2.el6.remi.noarch.rpm
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

# Install yum-config-manager
yum install yum-utils  yum-plugin-replace -y

# Disable PHP 5.5 or 5.6 repository
yum-config-manager --disable remi-php56 
yum-config-manager --disable remi-php55

# Enable PHP 7.0
yum-config-manager --enable remi-php70

# Upgrade to PHP 7.0 and all dependencies
yum upgrade php php-common php-*


Verify the last step and press "Y"
---> Package php-pdo.x86_64 0:7.0.6-3.el6.remi will be an update
---> Package php-pecl-amqp.x86_64 0:1.7.0-1.el6.remi.5.5 will be updated
---> Package php-pecl-amqp.x86_64 0:1.7.0-1.el6.remi.7.0 will be an update
---> Package php-pecl-apfd.x86_64 0:1.0.1-1.el6.remi.5.5 will be updated
---> Package php-pecl-apfd.x86_64 0:1.0.1-5.el6.remi.7.0 will be an update
---> Package php-pecl-http.x86_64 0:2.5.6-1.el6.remi.5.5 will be updated
---> Package php-pecl-http.x86_64 0:3.0.1-1.el6.remi.7.0 will be an update
---> Package php-pecl-json-post.x86_64 0:1.0.1-1.el6.remi.5.5 will be updated
---> Package php-pecl-json-post.x86_64 0:1.0.1-3.el6.remi.7.0 will be an update
---> Package php-pecl-jsonc.x86_64 0:1.3.9-1.el6.remi.5.5 will be obsoleted
---> Package php-pecl-jsonc-devel.x86_64 0:1.3.9-1.el6.remi.5.5 will be obsoleted
---> Package php-pecl-propro.x86_64 0:1.0.2-1.el6.remi.5.5 will be updated
---> Package php-pecl-propro.x86_64 0:2.0.0-1.el6.remi.7.0 will be an update
---> Package php-pecl-raphf.x86_64 0:1.1.2-1.el6.remi.5.5 will be updated
---> Package php-pecl-raphf.x86_64 0:2.0.0-1.el6.remi.7.0 will be an update
---> Package php-pecl-zip.x86_64 0:1.13.2-1.el6.remi.5.5 will be updated
---> Package php-pecl-zip.x86_64 0:1.13.2-1.el6.remi.7.0 will be an update
---> Package php-process.x86_64 0:5.5.35-1.el6.remi will be updated
---> Package php-process.x86_64 0:7.0.6-3.el6.remi will be an update
---> Package php-soap.x86_64 0:5.5.35-1.el6.remi will be updated
---> Package php-soap.x86_64 0:7.0.6-3.el6.remi will be an update
---> Package php-xml.x86_64 0:5.5.35-1.el6.remi will be updated
---> Package php-xml.x86_64 0:7.0.6-3.el6.remi will be an update
---> Package php-xmlrpc.x86_64 0:5.5.35-1.el6.remi will be updated
---> Package php-xmlrpc.x86_64 0:7.0.6-3.el6.remi will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================
 Package                     Arch            Version                         Repository           Size
=======================================================================================================
Installing:
 php-devel                   x86_64          7.0.6-3.el6.remi                remi-php70          1.3 M
     replacing  php-pecl-jsonc-devel.x86_64 1.3.9-1.el6.remi.5.5
 php-json                    x86_64          7.0.6-3.el6.remi                remi-php70           50 k
     replacing  php-pecl-jsonc.x86_64 1.3.9-1.el6.remi.5.5
Updating:
 php                         x86_64          7.0.6-3.el6.remi                remi-php70          2.7 M
 php-cli                     x86_64          7.0.6-3.el6.remi                remi-php70          4.0 M
 php-common                  x86_64          7.0.6-3.el6.remi                remi-php70          976 k
 php-gd                      x86_64          7.0.6-3.el6.remi                remi-php70           62 k
 php-mbstring                x86_64          7.0.6-3.el6.remi                remi-php70          971 k
 php-mcrypt                  x86_64          7.0.6-3.el6.remi                remi-php70           47 k
 php-mysqlnd                 x86_64          7.0.6-3.el6.remi                remi-php70          209 k
 php-opcache                 x86_64          7.0.6-3.el6.remi                remi-php70          138 k
 php-pdo                     x86_64          7.0.6-3.el6.remi                remi-php70          103 k
 php-pecl-amqp               x86_64          1.7.0-1.el6.remi.7.0            remi-php70           69 k
 php-pecl-apfd               x86_64          1.0.1-5.el6.remi.7.0            remi-php70           10 k
 php-pecl-http               x86_64          3.0.1-1.el6.remi.7.0            remi-php70          194 k
 php-pecl-json-post          x86_64          1.0.1-3.el6.remi.7.0            remi-php70           11 k
 php-pecl-propro             x86_64          2.0.0-1.el6.remi.7.0            remi-php70           19 k
 php-pecl-raphf              x86_64          2.0.0-1.el6.remi.7.0            remi-php70           22 k
 php-pecl-zip                x86_64          1.13.2-1.el6.remi.7.0           remi-php70           45 k
 php-process                 x86_64          7.0.6-3.el6.remi                remi-php70           60 k
 php-soap                    x86_64          7.0.6-3.el6.remi                remi-php70          182 k
 php-xml                     x86_64          7.0.6-3.el6.remi                remi-php70          169 k
 php-xmlrpc                  x86_64          7.0.6-3.el6.remi                remi-php70           64 k

Transaction Summary
=======================================================================================================
Install       2 Package(s)
Upgrade      20 Package(s)

Total download size: 11 M
Is this ok [y/N]:



Verify php installation by issuing php -v
Installed:
  php-devel.x86_64 0:7.0.6-3.el6.remi                php-json.x86_64 0:7.0.6-3.el6.remi

Updated:
  php.x86_64 0:7.0.6-3.el6.remi                       php-cli.x86_64 0:7.0.6-3.el6.remi
  php-common.x86_64 0:7.0.6-3.el6.remi                php-gd.x86_64 0:7.0.6-3.el6.remi
  php-mbstring.x86_64 0:7.0.6-3.el6.remi              php-mcrypt.x86_64 0:7.0.6-3.el6.remi
  php-mysqlnd.x86_64 0:7.0.6-3.el6.remi               php-opcache.x86_64 0:7.0.6-3.el6.remi
  php-pdo.x86_64 0:7.0.6-3.el6.remi                   php-pecl-amqp.x86_64 0:1.7.0-1.el6.remi.7.0
  php-pecl-apfd.x86_64 0:1.0.1-5.el6.remi.7.0         php-pecl-http.x86_64 0:3.0.1-1.el6.remi.7.0
  php-pecl-json-post.x86_64 0:1.0.1-3.el6.remi.7.0    php-pecl-propro.x86_64 0:2.0.0-1.el6.remi.7.0
  php-pecl-raphf.x86_64 0:2.0.0-1.el6.remi.7.0        php-pecl-zip.x86_64 0:1.13.2-1.el6.remi.7.0
  php-process.x86_64 0:7.0.6-3.el6.remi               php-soap.x86_64 0:7.0.6-3.el6.remi
  php-xml.x86_64 0:7.0.6-3.el6.remi                   php-xmlrpc.x86_64 0:7.0.6-3.el6.remi

Replaced:
  php-pecl-jsonc.x86_64 0:1.3.9-1.el6.remi.5.5    php-pecl-jsonc-devel.x86_64 0:1.3.9-1.el6.remi.5.5

Complete!
[user@server folder]#php -v
Failed loading /usr/lib64/php/modules/ioncube_loader_lin_5.5.so:  /usr/lib64/php/modules/ioncube_loader_lin_5.5.so: undefined symbol: zval_update_constant_inline_change
PHP 7.0.6 (cli) (built: Apr 28 2016 22:35:28) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies


Notice that we have ioncube not matching the latest PHP and we must disable this extension by:
[user@server folder]# rm /etc/php.d/ioncube.ini


Error-free PHP output
[user@server folder]# php -v
PHP 7.0.6 (cli) (built: Apr 28 2016 22:35:28) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
[user@server folder]#

Fatal error: Uncaught --> Smarty Compiler: Syntax error in template {php}{/php} tags not allowed. Use SmartyBC to enable them

To fix php error:

PHP ERROR:

Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "file:XXXXXX.tpl" on line 18 "

change:
$smarty = new Smarty();

to:
$smarty = new SmartyBC();

Tuesday, February 2, 2016

Kamailio 4.3.x Error: mod_destroy(): ERROR: ctl: could not delete unix socket /var/run/kamailio//kamailio_ctl: Permission denied


Kamailio 4.3.x spit below error:
145(29867) INFO:  [main.c:798]: sig_usr(): signal 15 received
43(29765) INFO:  [main.c:798]: sig_usr(): signal 15 received
 2(29724) INFO:  [main.c:798]: sig_usr(): signal 15 received
39(29761) INFO:  [main.c:798]: sig_usr(): signal 15 received
 0(29722) ERROR: ctl [ctl.c:372]: mod_destroy(): ERROR: ctl: could not delete unix socket /var/run/kamailio//kamailio_ctl: Permission denied (13)
 0(29722) DEBUG:  [db_pool.c:100]: pool_remove(): removing connection from the pool
 0(29722) DEBUG: tm [t_funcs.c:86]: tm_shutdown(): DEBUG: tm_shutdown : start
 0(29722) DEBUG: tm [t_funcs.c:89]: tm_shutdown(): DEBUG: tm_shutdown : emptying hash table
 0(29722) DEBUG: tm [t_funcs.c:91]: tm_shutdown(): DEBUG: tm_shutdown : removing semaphores
 0(29722) DEBUG: tm [t_funcs.c:93]: tm_shutdown(): DEBUG: tm_shutdown : destroying tmcb lists
 0(29722) DEBUG: tm [t_funcs.c:96]: tm_shutdown(): DEBUG: tm_shutdown : done
 0(29722) ERROR: mi_fifo [mi_fifo.c:294]: mi_destroy(): FIFO stat failed: Permission denied
 0(29722) INFO:  [sctp_core.c:53]: sctp_core_destroy(): SCTP API not initialized
 0(29722) DEBUG:  [mem/shm_mem.c:232]: shm_mem_destroy(): shm_mem_destroy
 0(29722) DEBUG:  [mem/shm_mem.c:235]: shm_mem_destroy(): destroying the shared memory lock

Solution that worked for me:
chown -R kamailio:kamailio /var/run/kamailio

Thursday, January 28, 2016

Percona XtraDB Cluster : [ERROR] WSREP: Could not open state file for writing: '/var/lib/mysql//grastate.dat'. Check permissions and/or disk space.: 13 (Permission denied)

After transfer snapshot of Percona XtraDB Cluster I received below error:
2016-01-29 06:57:18 20161 [Warning] WSREP: Could not open state file for reading: '/var/lib/mysql//grastate.dat'
2016-01-29 06:57:18 20161 [ERROR] WSREP: Could not open state file for writing: '/var/lib/mysql//grastate.dat'. Check permissions and/or disk space.: 13 (Permission denied)
         at galera/src/saved_state.cpp:SavedState():49
2016-01-29 06:57:18 20161 [ERROR] WSREP: wsrep::init() failed: 7, must shutdown
2016-01-29 06:57:18 20161 [ERROR] Aborting
turns out chxmod 660 or 666 or 777 didn't help and the reason was the mysql folder ownership was root instead of mysql, so to fix it:
chown -R mysql:mysql /var/lib/mysql/

Wednesday, January 27, 2016

Erase Replication and Slave Settings and Data on MySQL slave

To erase all replication data on MySQL you can do: MySQL 5.0 and 5.1:
STOP SLAVE;
CHANGE MASTER TO MASTER_HOST='';
MySQL 5.5 and 5.6:
STOP SLAVE;
RESET SLAVE ALL;
example:
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: SOMEHOST
                  Master_User: MASTER_USER
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File:
          Read_Master_Log_Pos: 4
               Relay_Log_File: mysql-relay-bin.000004
                Relay_Log_Pos: 2949
        Relay_Master_Log_File:
             Slave_IO_Running: No
            Slave_SQL_Running: No
              Replicate_Do_DB: 
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 0
              Relay_Log_Space: 0
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 0
                  Master_UUID: 0b505dc2-c3e3-11e5-8adf-000c292bd8a9
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State:
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set: c042d2a4-3ba4-ee1a-69aa-b4b5a00d8fe3:1-2027
                Auto_Position: 0
1 row in set (0.00 sec)

mysql> reset slave all;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status;
Empty set (0.00 sec)
Remember that "RESET SLAVE" only reset the replication "Exec_Master_Log_Pos", " Read_Master_Log_Pos" and "binlog".

Sunday, January 24, 2016

Disable Apache Folder Listing (for all website) or Enable listing for specified Download folder (as exception)

Default setting in Apache allows folder listing, which is not safe or secure and you may want to take below approach to change this setting.
A) "The best" approach is insert or change default tag within /etc/httpd/conf/httpd.conf as below:
<Directory />
    Options -Indexes
    AllowOverride All
</Directory>

B) It can be enabled or disabled by inserting below tag in .htaccess file at the website root or specified folder for example for Download and repository folder which user can select which file he/she wishes to download.
echo 'Options -Indexes' > /var/www/html/.htaccess

C) To do it website specific httpd.conf settings:
<VirtualHost *:80>
 Options -Indexes
 ServerName somewebsite.com
 ServerAlias www.somewebsite.com
 DocumentRoot /var/www/somewebsite.com
</VirtualHost>

Compress File or Folder using tar and xz tool (Multi threaded)

To compress a folder, first navigate to subfolder using "cd" and isue below command the new 5.X version support multi-threading thus multi cpu by "-T number_of_cpu" syntax
tar -cf - src_folder/ | xz -T 6 -9 -c - > /tmp/src_folder.tar.xz 

Saturday, January 23, 2016

Percona Server 5.6 to MYSQL 5.6 Replication Error: 1677 - Column 1 of table 'XXXXX.XXXXX' cannot be converted from type 'timestamp' to type 'timestamp'

You may get below error when replicating from Percona 5.6 to Mysql 5.6


mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.1.2.230
                  Master_User: ut_user
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 7640733
               Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 279
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: No
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 1677
                   Last_Error: Column 1 of table 'XXXXX.XXXXX' cannot be converted from type 'timestamp' to type 'timestamp'
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 120
              Relay_Log_Space: 1885
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 1677
               Last_SQL_Error: Column 1 of table 'XXXXX.XXXXX' cannot be converted from type 'timestamp' to type 'timestamp'
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 130
                  Master_UUID: e1d58117-750e-11e3-ae17-XXXXXXXXXXXXX
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State:
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp: 140105 03:11:27
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
1 row in set (0.00 sec)

My solution: Uninstall MySQL 5.6 and install XtraDB standalone or Percona Server using the same my.cnf and data directory

MySQL error on Grant: ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES


When doing below grant:
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, FILE ON ut_sipreg.* TO 'voip04my_sipreg'@'localhost' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;

I received below error:
ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES

To fix it, I had to take out "FILE" from permission list:
mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON ut_sipreg.* TO 'voip04my_sipreg'@'localhost' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
Query OK, 0 rows affected (0.01 sec)