Category: CentOS

  • Install memcached on CentOS 7

    To install memcached on CentOS 7, run

    yum -y install memcached

    Set memcached to start on boot

    systemctl enable memcached

    Start memcached with

    systemctl start memcached

    Installing PHP Module

    You need remi repository installed, which provide a memcached module for all versions of php they support.

    For PHP 5.6, run

    yum install php-memcache

    Now phpinfo() will show

    centos 7 php memcache

    See memcached

  • Adding IP Range in CentOS 6

    To add an IP range in CentOS 6 server, create file

    vi /etc/sysconfig/network-scripts/ifcfg-eth0-range0
    

    Add

    IPADDR_START=67.198.150.171
    IPADDR_END=67.198.150.174
    CLONENUM_START=0
    

    Replace IP with your actual start and end IP.

    Restart network service with

    service network restart
    
  • Install MySQL 8 on CentOS, RHEL 6/7

    Install MySQL 8 on CentOS, RHEL 6/7

    To Add MySQL yum repository to your server, go to

    https://dev.mysql.com/downloads/repo/yum/

    Download the rpm file available.

    For RHEL/CentOS 7

    wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
    rpm -ivh mysql80-community-release-el7-3.noarch.rpm
    

    For RHEL/CentOS 6

    wget https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm
    rpm -ivh mysql80-community-release-el6-1.noarch.rpm
    

    Installing MySQL Server

    yum install mysql-community-server
    

    Stop/Start MySQL

    To stop/start MySQL, use service name “mysqld”.

    systemctl start mysqld
    systemctl stop mysqld
    systemctl restart mysqld
    

    MySQL 8 root Password

    When MySQL first starts, it create a random password and store in MySQL log file. To find the MySQL root password, run

    grep 'temporary password' /var/log/mysqld.log
    

    This default password don’t allow you to do anything, so login to MySQL with this password and set a secure password for root.

    ALTER USER 'root'@'localhost' IDENTIFIED  BY 'MYSQL_ROOT_PASSOWRD';
    

    MYSQL_ROOT_PASSOWRD – replace it with you secure new MySQL root password.

    Installing Older Version of MySQL

    When you add MySQL repository, it activate latest version by default. If you want older version, say 5.7, you need to activate it.

    To see available repository, run

    yum repolist all | grep mysql
    

    To disable MySQL 8 repository, run

    yum-config-manager --disable mysql80-community
    

    To enable MySQL 5.7 repository, run

    yum-config-manager --enable mysql57-community
    

    Now installing MySQL server will install MySQL 5.7 instead of latest version.

    MySQL CentOS

  • chkconfig

    chkconfig is a command available in CentOS 6 to set a service start on boot.

    To start lighttpd on boot run.

    chkconfig --levels 235 lighttpd on
    

    chkconfig command list all services and its run levels.

    [root@server12 ~]# chkconfig
    acpid          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    atd            	0:off	1:off	2:off	3:on	4:on	5:on	6:off
    auditd         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    blk-availability	0:off	1:on	2:on	3:on	4:on	5:on	6:off
    cgconfig       	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    cgred          	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    crond          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    csf            	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    dnsmasq        	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    docker         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    ebtables       	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    exim           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    haldaemon      	0:off	1:off	2:off	3:on	4:on	5:on	6:off
    htcacheclean   	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    ip6tables      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    iptables       	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    iscsi          	0:off	1:off	2:off	3:on	4:on	5:on	6:off
    iscsid         	0:off	1:off	2:off	3:on	4:on	5:on	6:off
    lfd            	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    lvm2-monitor   	0:off	1:on	2:on	3:on	4:on	5:on	6:off
    lxc            	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    mdmonitor      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    messagebus     	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    netcf-transaction	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    netconsole     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    netfs          	0:off	1:off	2:off	3:on	4:on	5:on	6:off
    network        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    newrelic-sysmond	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    nginx          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    ntpd           	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    ntpdate        	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    numad          	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    pure-ftpd      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    radvd          	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    rdisc          	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    redmine        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    restorecond    	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    rsyslog        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    saslauthd      	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    smartd         	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    sshd           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    svnserve       	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    sysstat        	0:off	1:on	2:on	3:on	4:on	5:on	6:off
    udev-post      	0:off	1:on	2:on	3:on	4:on	5:on	6:off
    vnstat         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    yum-cron       	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    [root@server12 ~]# 
    
  • Install FFmpeg on CentOS using yum

    Install epel repository using

    yum install epel-release -y

    Method 1

    Install rpmfusion for your distro

    https://rpmfusion.org/Configuration

    For CentOS 8

    rpm -ivh https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm

    For CentOS 7

    rpm -ivh https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm

    Install ffmpeg with

    yum install ffmpeg

    2023-02-20 On CentOS 7, repo provided ffmpeg version 3.4.12. scrpms repo had a newer version.

    Method 2

    Install scrpms repo

    On CentOS 7

    wget http://scrpms.net/pub/RPMS/el7/x86_64/scrpms-repo-22-3.el7.x86_64.rpm
    rpm -ivh scrpms-repo-22-3.el7.x86_64.rpm

    Install ffmpeg with

    yum install ffmpeg ffmpeg-devel

    NOTE:

    2019-12-11 i tested it on CentOS 7. ffmpeg worked. Version is 4.2.1. mplayer/mencoder install failed with dependency error.

    2023-02-20 CentOS 7 ffmpeg version 5.1.2

    Method 3

    http://li.nux.ro/repos.html

    On CentOS 7

    rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm

    Install ffmpeg with

    yum install ffmpeg ffmpeg-devel

    NOTE: On 2019-12-11 i tested it on CentOS 7. ffmpeg and mencoder install worked. But version is very old. ffmpeg version 2.8.15. MPlayer SVN-r37391-4.8.3

    See ffmpeg

  • Install PHP 7.2 in CentOS ISPConfig Server

    First you need to install EPEL repo and REMI repo.

    To install EPEL, run

    yum install epel-release
    

    To Install REMI repo, download RPM file for your OS from https://rpms.remirepo.net

    For CentOS 6, run

    rpm -ivh https://rpms.remirepo.net/enterprise/remi-release-6.rpm
    

    For CentOS 7

    rpm -ivh https://rpms.remirepo.net/enterprise/remi-release-7.rpm
    

    Install PHP 7.2 with

    yum install php72-php-bcmath php72-php-cli php72-php-common php72-php-fpm php72-php-gd php72-php-intl php72-php-json php72-php-mbstring php72-php-mcrypt php72-php-mysqlnd php72-php-opcache php72-php-pdo php72-php-pear php72-php-pecl-uploadprogress php72-php-pecl-zip php72-php-soap php72-php-xml php72-php-xmlrpc
    

    Configure PHP-FPM

    vi /etc/opt/remi/php72/php-fpm.d/www.conf
    

    Find

    listen = 127.0.0.1:9000
    

    Replace 9000 with unused port, i used

    listen = 127.0.0.1:9072
    

    Restart/Enable PHP-FPM

    For CentOS 7

    systemctl start php72-php-fpm
    systemctl enable php72-php-fpm
    

    For CentOS 6

    service php72-php-fpm start
    chkconfig php72-php-fpm on
    

    Add PHP Version in ISPConfig

    Login to ISPConfig, go to

    System > Additional PHP Versions > Add new PHP version

    ISPConfig Add New PHP Version

    On Next Page, enter name.

    Name: PHP7.2
    

    In “FastCGI Settings” tab, fill following details

    Path to the PHP FastCGI binary = /opt/remi/php72/root/usr/bin/php-cgi
    Path to the php.ini directory = /etc/opt/remi/php72
    

    In “PHP-FPM Settings” tab, add

    Path to the PHP-FPM init script =  /etc/init.d/php72-php-fpm
    Path to the php.ini directory = /etc/opt/remi/php72
    Path to the PHP-FPM pool directory = /etc/opt/remi/php72/php-fpm.d
    

    Changing a Sites PHP Version in ISPConfig

    Go to sites, click on site you need to change PHP version.

    On this page, you need to select value for “PHP” and “PHP Version”. Once changed, you need to wait a minute for the version change to happen. This is done by cronjob, that run every one minute.

    * * * * * /usr/local/ispconfig/server/server.sh &> /dev/null
    

    You can manually execute the script if you want.

    ispconfig

  • Install ionCube Loader on CentOS 7

    Go to

    https://www.ioncube.com/loaders.php

    Download latest version of ionCube Loader

    cd /usr/local/src
    wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
    tar xvf ioncube_loaders_lin_x86-64.tar.gz
    cd ioncube
    

    Find out PHP version you are using with command

    php -v
    

    ioncube php version

    Here we have PHP version 5.6, now you need to find the available loaders for PHP 5.6 with command

    ls -l | grep 5.6
    

    The one we needed is ioncube_loader_lin_5.6.so

    You need to copy it to PHP extension_dir directory.

    To find location of extension_dir, run

    php -i | grep extension_dir
    

    For default php installation, it will be /usr/lib64/php/modules

    So copy it the loader with command

    cp ioncube_loader_lin_5.6.so /usr/lib64/php/modules
    

    Edit php.ini

    vi /etc/php.ini
    

    Add

    zend_extension = ioncube_loader_lin_5.6.so
    

    At this point, php -m will show ionCube loader.

    ioncube php module

    Now restart web server with

    service httpd restart
    

    ioncube

  • Install PHP 7 on CentOS 6

    Install EPEP repo with command

    yum install -y epel-release
    

    Next you need REMI repo, you can get it form

    https://rpms.remirepo.net/

    Install it with

    rpm -ivh https://rpms.remirepo.net/enterprise/remi-release-6.rpm
    

    You can search for PHP versions with command

    yum search php
    

    Select PHP version

    First install yum-utils

    yum install yum-utils
    

    Now you can select required PHP version with command

    yum-config-manager --enable remi-php72
    

    Use remi-php70 for PHP 7.0, remi-php71 for PHP 7.1

    Install PHP

    To install PHP 7.2, run

    yum install php72 -y
    

    PHP binary will be installed as php72, you can create a synlink if you need.

    ln -s /usr/bin/php72 /usr/bin/php
    

    Enable PHP in Apache

    yum install php72-php
    

    Now restart apache

    service httpd restart
    

    php
    CentOS 6

  • Install GeoIP Apache Module in CentOS

    To install GeoIP Apache module on CentOS 7, run

    yum -y install GeoIP GeoIP-devel GeoIP-data
    yum -y install mod_geoip 
    

    Now you need to configure Apache VirtualHost.

    To block traffic, add following to your VirtualHost entry

    RewriteEngine On
    RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(CN|RU|A1)$
    RewriteRule ^(.*)$ https://serverok.in [L]
    

    In this example, traffic from CN, RU and A1 (stands for proxy IP) get redirected to specified URL.

    geoip

  • Install fail2ban on CentOS

    To install fail2ban on CentOS, first, enable the epel repo by running

    yum install epel-release -y

    Now install fail2ban with

    yum install fail2ban -y

    Enable fail2ban with

    systemctl enable fail2ban

    Basck to fail2ban