How To Upgrade or Update CentOS

Introduction

CentOS is a popular fork, or derivative, of the Red Hat Enterprise Linux distribution.

CentOS 7.6 is a minor update and was published in December 2018. It includes updates and changes, including support for newer software and server technology. This guide will walk you through upgrading and updating the current version to the latest CentOS release.

Prerequisites

  • Access to a command line / terminal window (Menu > Applications > Utilities > Terminal)
  • The yum package manager, included by default

Upgrade CentOS to Latest Version: 6 Easy Steps

Step 1: Check current CentOS version

Check the version of your current release with the command:

cat /etc/redhat-release

The system should display the CentOS Linux release version. Make sure the first number is at least 7.x.x.

Step 2: Verify data and backups

Backing up important server data should be done before running a operating system upgrade. Take a moment to verify your system backups.

Step 3: Check for available updates

Check available CentOS updates with the command:

sudo yum check-update

The system will display a list of available updates, including the core operating system updates. Scan through these to make sure everything is in order.
Read More

Resetting Your MYSQL Root Password

  1. The first step to resetting your root MySQL password on a Linux server is to stop MySQL. If you have a monitoring service for MySQL that will restart the service if it is down, make sure that service is also stopped for the time being, such as checkservd and cPanel.
    /etc/init.d/mysql stop
  2. Next, start MySQL in Single User Mode and enter without a password.

    Warning:

    Restarting MySQL this way will allow anyone access to every database. To avoid this, stop eth0 and fuser -k any logged in user and touch /etc/nologin.
    mysqld_safe --skip-grant-tables & mysql

    Note:

    Make sure to add & or the command prompt will not show.
  3. Enter the following commands in the MySQL prompt. The password below is only an example, replace 123456ABCDEF with the password of your choice. Our article Best Practice: Creating a Secure Password provides you with information on secure password best practices.
    UPDATE mysql.user SET password=password("123456ABCDEF") 
    WHERE user='root';
    FLUSH PRIVILEGES;
    exit;
  4. Stop MySQL safe and start MySQL and all other services that kept it from restarting like checkservd and cPanel normally.
    /etc/init.d/mysql stop
    /ect/init.d/mysql start
  5. Test your change by doing a test login, to log into MySQL, type it into the command line.
    mysql
  6. You will be prompted to enter your password. Enter the new password, if you are logged in then you have successfully reset the MySQL root password.

Note:

If the MySQL user has been deleted, run the following query to recreate it:

INSERT INTO `mysql`.`user` ( `Host` , `User` , `Password`
 , `Select_priv` ,`Insert_priv` , `Update_priv` ,`Delete_priv` 
 , `Create_priv` , `Drop_priv` , `Reload_priv` , `Shutdown_priv` 
 , `Process_priv` , `File_priv` , `Grant_priv` , `References_priv` 
 , `Index_priv` , `Alter_priv` , `Show_db_priv` , `Super_priv` 
 ,`Create_tmp_table_priv` , `Lock_tables_priv` , `Execute_priv` 
 , `Repl_slave_priv`, `Repl_client_priv` , `Create_view_priv` 
 , `Show_view_priv` , `Create_routine_priv` , `Alter_routine_priv` 
 , `Create_user_priv` , `max_questions` , `max_updates`
 , `max_connections` , `max_user_connections` ) VALUES ( 'localhost'
 , 'root',PASSWORD('password1234'), 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y'
 , 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y','Y', 'Y', 'Y', 'Y'
 , 'Y', 'Y', 'Y', 'Y', 'Y', '0', '0', '0', '0' );

Troubleshooting

You may encounter an error when trying to change the root password that looks like the example below:

mysql> show warnings; +---------+------+-----------------------------------------------+ 
| Level | Code | Message | +---------+------+-----------------------------------------------+ 
| Warning | 1265 | Data truncated for column 'Password' at row 1 | 
| Warning | 1265 | Data truncated for column 'Password' at row 2 | 
+---------+------+-----------------------------------------------+

 

If MySQL is giving you warnings when changing the password, type the following:
mysql>prompt

 

Then leave MySQL and run:

/usr/bin/mysql_fix_privilege_tables

Once this is complete, try to set the password again. If you have further issues, please contact our Support team and we will be happy to assist you!

How To Install the LAMP Stack on CentOS 7

Pre-flight Checks

To find out which Linux distribution you are running, use this command:
cat /etc/redhat-release
It’s now time to verify that our yum environment is clean and up to date, we’ll do this by cleaning all of the yum cache, and update yum using:
yum clean all
yum update

Installing LAMP

Now that we know what environment we’re working in let’s get started on installing the LAMP stack on CentOS 7:

L – Linux

The first part of the stack is Linux. This is your operating system and since it is already installed there no need to worry about installing it or make any modifications. Installing CentOS 7 is easy to download and install using the image files that are provided from centos.org. CentOS has a helpful installation guide if you need to reference it for additional installation instructions.

A – Apache

Apache is the next piece of the LAMP stack. Apache is the webserver software that is responsible for serving the content to your web browser from the server. It takes the requests that it receives and sends back the HTML code for your browser to interpret.
Install Apache using Yum:
yum -y install httpd

Open ports in the FW:
firewall-cmd --permanent --add-service=http -add-service=https
firewall-cmd --reload

Start and enable apache to run when the server starts:
systemctl start httpd
systemctl enable httpd

Default Apache installation locations:

Some important server locations to remember for Apache are listed below. These are out-of-the-box defaults and can be changed as you see fit:
httpd binary: /sbin/httpd
Apache configuration file: /etc/httpd/conf/httpd.conf
Website files: /var/www/html/
Apache logs: /var/log/httpd/

M – MySQL/MariaDB

MySQL and MariaDB are what handle your website’s database. In most of today’s websites, data is not stored in flat or static files. Instead, the base of the site is coded in PHP which can pull information from your website’s database to deliver more dynamic content. MySQL and MariaDB are popular database servers that help house that information. MariaDB is becoming more widely used, so we’ll use for installation. Both are very similar in setting up and configuring.

Install MariaDB:
yum -y install mariadb-server
systemctl start mariadb

Although securing mysql is optional, it is strongly recommended:
mysql_secure_installation
**Run through the steps on screen to secure your Mysql/MariaDB environment

Enable MariaDB to start when the server starts:
systemctl enable mariadb

Default installation locations:

Some important server locations to remember for MySQL/MariaDB are listed below. These are out-of-the-box defaults and can be changed as you see fit:
MariaDB binary: /bin/mysql
MariaDB Configuration file: /etc/my.cnf
Database location: /var/lib/mysql
MariaDB logs: /var/log/mariadb/mariadb.log

P – PHP

Most websites that exist today are built using PHP coding. PHP provides the programmer with more options for dynamic content compared to flat html code. Several PHP versions are available for use depending on what PHP version the website was built in. We’ll install the latest version of PHP.

In order to install the latest PHP version, we first need to install CentOS’s Software Collection repository (SCL):
yum -y install centos-release-scl.noarch

We’ll now have access to install PHP 7.2 :
yum -y install rh-php72

Now we’ll fix the symbolic link for the binary:
ln -s /opt/rh/rh-php72/root/usr/bin/php /usr/bin/php

Install the updated PHP Module for Mysql/MariaDB:
yum -y install rh-php72-php-mysqlnd

Restart apache to work with the newly installed PHP:
systemctl restart httpd

How To Set or Change Timezone on CentOS 7

Checking the Current Timezone

In CentOS and other modern Linux distros, you can use the timedatectl command to display and set the current system’s time and timezone.

Changing Timezone in CentOS

Before changing the timezone, you’ll need to find out the long name for the timezone you want to use. The timezone naming convention usually uses a “Region/City” format.

To list all available time zones, you can either list the files in the /usr/share/zoneinfo directory or use the timedatectl command.

timedatectl list-timezones
...
America/Tijuana
America/Toronto
America/Tortola
America/Vancouver
America/Whitehorse
America/Winnipeg
...

Once you identify which time zone is accurate to your location, run the following command as sudo user:

sudo timedatectl set-timezone your_time_zone

For example, to change the system’s timezone to America/Toronto:

sudo timedatectl set-timezone America/Toronto

Run the timedatectl command to verify the changes: