Category: Linux

  • How to find MySQL root password in Webuzo

    How to find MySQL root password in Webuzo

    Webuzo Hosting control panel stores MySQL root password in the file /var/webuzo/my.conf

    To find MySQL root password on the Webuzo server, run the command

    cat /var/webuzo/my.conf

    Back to Webuzo

  • Install PHP 5.6 on AlmaLinux 8

    Install PHP 5.6 on AlmaLinux 8

    To install PHP 5.6 on AlmaLinux 8, first enable the epel repository.

    dnf install -y epel-release

    install remi repository with the command

    dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm

    Now you can install PHP 5.6 with

    dnf install php56

    You can execute PHP with the command

    php56

    If you want PHP 5.6 to work with the command “php”, then edit

    vi ~/.bashrc

    At end of the file, add

    source /opt/remi/php56/enable

    Log off and login to the server or run command

    source /opt/remi/php56/enable

    Or you can create a symlink

    ln -s /opt/remi/php56/root/usr/bin/php /usr/bin/php

    If you need PHP work with Apache, run install Apache with

    dnf install httpd

    Install php-fpm with

    dnf install php56-php-fpm

    Enable and restart Apache

    systemctl enable php56-php-fpm
    systemctl enable httpd
    systemctl restart httpd
    systemctl restart php56-php-fpm

    php-fpm pool config file available at

    /etc/opt/remi/php56/php-fpm.d/www.conf
  • How to find if Log4J is installed in my server

    How to find if Log4J is installed in my server

    A critical vulnerability (CVE-2021-44228) was identified on the popular log4j logger library used by a lot of popular Java applications. The remote code execution (RCE) vulnerability allows attackers to gain access to the server by getting the application to log a special string.

    Apache Log4j versions 2.0-beta9 to 2.14.1 are affected by this critical vulnerability.

    To find if Log4J is installed on your server, run

    find / -type f -name log4j*
    

    This will list all available log4j files on your server.

    Example

    root@server:~# find / -type f -name log4j*
    /opt/SoapUI-5.4.0/licenses/log4j-LICENSE.txt
    /opt/SoapUI-5.4.0/lib/log4j-1.2.14.jar
    root@server:~# 
    

    In the above result, the server has an application SoapUI-5.4.0, that use Log4J. But the version is older than 2.0, so not affected by this vulnerability.

    If your server has any application, that uses Log4J and it uses a vulnerable version, you need to upgrade it to the latest version.

    how to check apache log4j version

    Usually, the jar file has names like

    log4j-1.2.14.jar
    

    File name format is log4j-VERSION.jar, in this case, version of log4j is 1.2.14

  • How to Install MySQL 5.7 on Oracle Linux 7

    How to Install MySQL 5.7 on Oracle Linux 7

    Oracle Linux 7 comes with MySQL yum repository pre-installed. By Default MySQL 8 repository is enabled. You can disable MySQL 8 repository and enable MySQL 5.7 repository to install MySQL 5.7.

    You can find enabled repositories with command

    yum repolist all |  grep -i mysql
    

    Example

    [root@sql2 ~]# yum repolist all |  grep -i mysql
    ol7_MySQL55/x86_64                      MySQL 5.5 for Oracle Lin disabled
    ol7_MySQL56/x86_64                      MySQL 5.6 for Oracle Lin disabled
    ol7_MySQL57/x86_64                      MySQL 5.7 for Oracle Lin disabled
    ol7_MySQL80/x86_64                      MySQL 8.0 for Oracle Lin enabled:    281
    ol7_MySQL80_connectors_community/x86_64 MySQL 8.0 Connectors Com enabled:     56
    ol7_MySQL80_tools_community/x86_64      MySQL 8.0 Tools Communit enabled:     15
    [root@sql2 ~]#
    

    Let’s disable MySQL 8 repo and enable MySQL 5.7 repository.

    yum install -y yum-utils
    yum-config-manager --disable ol7_MySQL80 ol7_MySQL80_connectors_community ol7_MySQL80_tools_community
    yum-config-manager --enable ol7_MySQL57
    

    Before you can install MySQL 5.7, if your server has any MySQL 8 related packages installed, you need to uninstall them.

    On my server, I had the following packages installed.

    [root@mysql1 ~]# rpm -qa | grep mysql
    mysql-community-client-plugins-8.0.26-1.el7.x86_64
    mysql-community-common-8.0.26-1.el7.x86_64
    mysql-community-libs-8.0.26-1.el7.x86_64
    mysql-release-el7-1.0-5.el7.x86_64
    mysql-community-libs-compat-8.0.26-1.el7.x86_64
    [root@mysql1 ~]# 
    

    These are installed as dependency for the postfix mail server, so if you remove the packages with yum, postfix also get removed, so I removed it with command

    rpm -e --nodeps mysql-community-client-plugins-8.0.26-1.el7.x86_64
    rpm -e --nodeps mysql-community-common-8.0.26-1.el7.x86_64
    rpm -e --nodeps mysql-community-libs-8.0.26-1.el7.x86_64
    rpm -e --nodeps mysql-community-libs-compat-8.0.26-1.el7.x86_64
    

    –nodeps option will remove packages without removing dependent packages. Make sure you don’t remove the package mysql-release-el7-1.0-5.

    Now you can install MySQL server with command

    yum install mysql-community-server
    

    Enable and start MySQL server

    systemctl enable mysqld --now
    

    To find MySQL initial password, use

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

    Login to MySQL server using the temporary password and set a password

    mysql -u root -p
    

    Enter the MySQL server temporary password, then execute the following SQL to change the MySQL root password.

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

    NEW_MYSQL_ROOT_PW – replace with your new secure MySQL root password.

    You can secure MySQL installation by running

    mysql_secure_installation
    
  • sudo: command not found

    sudo: command not found

    On a Debian server, when running a command with sudo, I got the error

    sudo: command not found
    

    To fix this, you need to install “sudo” package. If you are logged in as non-root user, then you need to become root, for this, you can use the command

    su -
    

    Enter the root password when it prompt for the password.

    Once logged in as user root, you can install sudo with the command

    apt install sudo
    

    To add a user to sudo group, run the command

    usermod -aG sudo USER_NAME
    

    Or

    adduser USER_NAME sudo
    

    adding user to sudo group

    If you don’t have a user, you can create a user with the command

    useradd -m --shell /bin/bash USER_NAME
    

    To verify if the user has sudo rights, you can use the command “sudo -v”. You can also use “id” or “groups” command, which lists all groups the current user is in, you can verify if the user is part of sudo group.

  • Convert image to WebP format in Ubuntu

    Convert image to WebP format in Ubuntu

    WebP is an image format for web by Google. The size of webp images are much smaller compared with other image formats, so better to use webp images on websites for faster site load speed.

    To install webp on Ubuntu/Debian, run

    sudo apt install webp
    

    To convert an image to webp format, run

    cwebp image.png -o image.webp
    

    With the above command, image.png file gets converted to image.webp

    You can specify quality with -q option

    -q  ............. quality factor (0:small..100:big), default=75
    

    To view a webp image, run

    vwebp image.webp
    
  • bash: /usr/bin/man: No such file or directory

    bash: /usr/bin/man: No such file or directory

    On Ubuntu, I get the following error

    root@vps1:~# man
    bash: /usr/bin/man: No such file or directory
    root@vps1:~#
    

    This is fixed by installing man with apt-get

    apt-get install man
    
  • How to Migrate CentOS to Oracle Linux

    How to Migrate CentOS to Oracle Linux

    Oracle Linux is Free 100% binary-compatible with Red Hat Enterprise Linux, same as CentOS. Unlike RHEL, Oracle Linux is free even for commercial use. Oracle only charges if you need support.

    Oracle provides a script to convert CentOS to Oracle Linux

    https://github.com/oracle/centos2ol

    This script support CentOS 6, CentOS 7 and CentOS 8.

    Before you can run the convert script, make sure you have updated the system to the latest version with yum or dnf and take a backup in case anything goes wrong.

    yum update
    

    Download update centos2ol script

    wget https://raw.githubusercontent.com/oracle/centos2ol/main/centos2ol.sh
    

    Convert your CentOS installation to Oracle Linux with the command

    bash centos2ol.sh -V
    

    Reboot the server

    reboot
    
  • How to delete an mdadm RAID Array

    How to delete an mdadm RAID Array

    Deleting a software RAID array will result in all data stored in the devices being lost. So be careful when you remove a RAID array, take backups in case needed.

    Before you can remove the software RAID array, you need to unmount it.

    umount /dev/mdX

    Where /dev/mdX is the device name for the RAID device you need to remove.

    Find the disk used to create the RAID with the command

    mdadm --detail /dev/mdX

    Stop the RAID device with the command

    mdadm --stop /dev/mdX

    Now you need to run the following commands for each storage device that are part of the RAID device.

    mdadm --zero-superblock /dev/sdXY

    IMPORTANT: you need to run this for each member of the RAID device.

    Finally, edit /etc/mdadm/mdadm.conf, and remove the entry for the RAID array.

  • RAID getting created as /dev/md127

    RAID getting created as /dev/md127

    When I create software RAID with mdadm, it gets created as /dev/md127, instead of /dev/md0 I specified while creating RAID.

    RAID /dev/md127

    To fix this, you need to add RAID definition in /etc/mdadm/mdadm.conf, this can be done with

    mdadm --detail --scan >> /etc/mdadm/mdadm.conf
    

    Now run command

    update-initramfs -u
    

    Reboot the server, after reboot, RAID device will be named properly.

  • How to disable GUI in Ubuntu

    How to disable GUI in Ubuntu

    If you have installed Ubuntu with GUI and don’t want GUI, you can disable GUI from starting on boot with command

    systemctl set-default multi-user
    

    If you need to GUI auto-start on boot, run

    systemctl set-default graphical.target
    
  • How to  Setup Software RAID 0 on Linux Server

    How to Setup Software RAID 0 on Linux Server

    RAID 0 allows you to combine multiple disks into one large disk. Only use RAID 0 if the data is not important to you, for example, a backup server. If one disk fails in a RAID 0 array, all the data will be lost.

    To create a software RAID 0 with 2 or more disks, first, we need to prepare the disks to be used as RAID members. Run the following commands on each of the disks we will be adding to the RAID 0 array.

    parted /dev/sdX mklabel gpt
    parted /dev/sdX mkpart primary ext4 0% 100%
    parted /dev/sdX set 1 raid on

    Replace /dev/sdX with actual device names and run the commands for all devices you will be adding to the RAID 0.

    Create RAID 0

    To create RAID 0, run the following command

    mdadm --create --verbose /dev/md0 --raid-devices=2 --level=0 /dev/sdc1 /dev/sdd1

    In the above command,

    –raid-devices=2 = number of disks in the RAID. In this case, we have 2 disks. If you have more than 2 disks, change the number accordingly.

    /dev/sdc1 /dev/sdd1 = device names, change it with your actual device names. If you have more devices, add them.

    /dev/md0 = raid device name, it can be md0, md1, md2 etc..

    Format RAID device

    Before you can use RAID device, you need to format it.

    mkfs.ext4 /dev/mdX

    Replace /dev/mdX with your actual device name.

    Updating mdadm.conf

    Run

    mdadm --detail --scan

    It will print RAID definitions like the following example

    root@grml ~ # mdadm --detail --scan
    ARRAY /dev/md0 metadata=1.2 name=grml:0 UUID=44f0ec6b:f8311a0c:382295f8:d41fa0fe
    root@grml ~ #  

    You need to edit the file

    vi /etc/mdadm/mdadm.conf 

    Add the ARRAY definitions at end of the file. If any definitions are already there, don’t repeat them.

    Mounting New RAID Device

    Before you can mount RAID device, you need to find UUID for the raid device, this can be done with command

    blkid
    

    Example

    root@grml ~ # blkid
    /dev/loop0: TYPE="squashfs"
    /dev/sda2: UUID="feacd62e-d23f-483d-8971-aa3f110fea05" TYPE="swap" PARTUUID="3019f70f-516a-493f-97cf-2aa001e1c574"
    /dev/sda3: UUID="f162656d-bde9-4b14-8823-21e2a1618a2d" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="1fd4e63f-33a4-4c52-bc00-915c9d7965b8"
    /dev/sda4: UUID="52ceb7c4-f065-4cc7-9c19-276a98be29a8" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="b8f92699-2892-482c-8abe-b90ca91b5fc0"
    /dev/sdb1: UUID="44f0ec6b-f831-1a0c-3822-95f8d41fa0fe" UUID_SUB="65fd2c84-1217-2df7-2a2c-83046458805a" LABEL="grml:0" TYPE="linux_raid_member" PARTLABEL="primary" PARTUUID="b197077b-4a34-4459-8230-5c2a3b1c7085"
    /dev/sdc1: UUID="44f0ec6b-f831-1a0c-3822-95f8d41fa0fe" UUID_SUB="fedb9e98-dd9f-daed-fc63-4f6a86ebfc9e" LABEL="grml:0" TYPE="linux_raid_member" PARTLABEL="primary" PARTUUID="807fda4f-d22b-4fa7-8810-839e68ae917e"
    /dev/sdd1: UUID="44f0ec6b-f831-1a0c-3822-95f8d41fa0fe" UUID_SUB="071de57a-6d12-70e8-ed6d-cefe8371e915" LABEL="grml:0" TYPE="linux_raid_member" PARTLABEL="primary" PARTUUID="76f0cbbe-858a-4153-87dd-5665d1ac9939"
    /dev/sda1: PARTUUID="9034a389-a6b2-424e-bd19-ce7e55561eba"
    /dev/md0: UUID="9bd3d3ee-cc6b-43d5-91ed-627440cc9154" BLOCK_SIZE="4096" TYPE="ext4"
    root@grml ~ # 

    In this cause UUID for /dev/md0 is

    UUID="9bd3d3ee-cc6b-43d5-91ed-627440cc9154"

    Edit /etc/fstab

    vi /etc/fstab

    Add

    UUID="9bd3d3ee-cc6b-43d5-91ed-627440cc9154"   /home  ext4    defaults  0       1

    In the above

    /home = is the mount point. If you need to mount the new RAID device as another folder, you need to create an empty directory first.

    UUID=”9bd3d3ee-cc6b-43d5-91ed-627440cc9154″ = replace with your actual UUID.

    Check status of raid

    To see the status of the RAID, use the command

    cat /proc/mdstat
    

    Find RAID details

    To find RAID details, use the following command

    mdadm --detail /dev/mdX

    Back to RAID