General Archives - CloudMinister

How to install WordPress with LEMP stack on CentOS 7 VPS (Part1).

WordPress is one of the most popular and widely used content management system, blogging platform in the world. It is popularly used as a Blog, Portfolio Website,  etc.

In this tutorial, you are going to learn how to install WordPress with LEMP(Linux,Nginx,MySQL,and PHP)  on CentOS 7 Linux VPS.


Table of Content

  1. Prerequisites
  2. Install MySQL 8.0
  3. Configure Database in MySQL
  4. Install & Configure PHP 7.2
  5. Install Nginx
  6. Configure Firewall
  7. Configure Nginx File
  8. Install WordPress File
  9. Test WordPress

1. Prerequisites


Before you start the installation of WordPress with (LEMP) stack on Centos 7 VPS, you must have one Centos 7 VPS with root privileges on it or you can use sudo for non-root user.  

 You should also run basis command on server to check the following things-:

# df -h (To check the disk space on the system.)

 

# cat /etc/os-release (To verify the version of the VPS.)

 

# yum -y update (To update all the packages of the VPS)

2. Install MySQL 8.0

WordPress uses a MySQL database for storage, MySQL is used in stack for storing user details in database.

For installing MySQL on Centos 7 first you need to enable MySQL repository and then you can install MySQL.

# yum localinstall    -y https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

The command used for installing MySQL in CentOS 7 VPS is as follows:

# yum install mysql-server -y

Then check the MySQL version by typing following command:

# mysql -V(‘V’ is in uppercase)

After the installation is completed MySQL will start automatically and you can check it’s status by typing:

# systemctl status mysqld

If MySQL is not start automatically you can write the following command:

# systemctl start mysqld

Before going for the next step you should generate a temporary password to access MySQL root user with the following command:

# grep ‘temporary password’ /var/log/mysqld.log
Now configure the MySQL secure installation to improve the security by typing the following commands.
#
mysql_secure_installation

Login with the temporary password and assign new password, after that in this configuration it ask several questions you can give Y or N according to your requirement.

Change the password for root ? N

Remove anonymous users? Y

Disallow root login remotely? Y

Remove test database and access to it? Y

                  Reload privilege tables now? Y

 

3. Configure Database in MySQL

Now create database for WordPress in MySQL for that first login with MySQL server by using the following command:

# mysql -u root -p

And give its password, after that create database in it with the command:
mysql> CREATE DATABASE wordpress;

You can also check that database is created or not with the command:

mysql> SHOW  DATABASES;

Now create user and assign him password by using command:

mysql> CREATE USER ‘wordpress’@’localhost’ IDENTIFIED 

BY ‘Password’;

After that grant all privileges to the user created under that database with the command:

mysql> GRANT ALL ON  wordpress.* TO ‘wordpress’@’localhost’;       

Then flush all privileges on MySQL server with the command:

mysql> FLUSH PRIVILEGES;

Now exit from the MySQL server you can use commands:

mysql> exit;

mysql> \q;

Note-: In MySQL you must end each command with a semicolon(;).

4. Install & Configure PHP 7.2

PHP is used by WordPress to do various functions done by PHP like calling plugin, calling theme, validating user permissions, checking option, grab from database, etc.

In this Blog we are using PHP 7.2 versionand install it with epel-release with remi repository.

Firstly, install yum-utils packages using the following command:

    # yum -y install yum-utils

After that, install epel-release package by using command:

# yum -y install epel-release

Then import remi repository from the command:

# yum -y install  http://rpms.remirepo.net/enterprise/

remi-release-7.rpm

Enable the remi repository by typing:
# yum-config-manager –enable remi-php72

After that install PHP and all required modules by using command:

# yum -y install php-fpm php-mysql php-mbstring php-xml      php-gd php-cli php-json php-opcache php-curl
Now after the installation completed you can check the PHP version with the command:
# php -v (‘v’ is in smallcase)

 

To be Continued………

How to install Joomla with LEMP stack on CentOS 7 VPS (Part 2)

5. Install Nginx

Nginx, pronounced as “Engine X” and is a very fast and lightweight web server, that can be used to support static files, used as a reverse proxy and also for load balancing.

Firstlly, update all the software packages by typing the following command:

# yum -y update
After that install EPEL repository that is required for Nginx packages by using command:

    # yum -y install epel-release 

Now install  Nginx by typing the command:

    # yum -y install nginx

 After the installation is completed you must Enable and Start Nginx server by typing command:

    # systemctl start nginx

And enable it with the command:

    # systemctl enable nginx

Also check its status with

    # systemctl status nginx

6.Configure Firewall

After completed with installation part, configure the firewall settings with the following command:

Open HTTP port by typing command with:

    # firewall-cmd –permanent –zone=public –add-service=http

If firewalld package is not available then you can install it with command:

    # yum -y install firewalld

And start firewalld service with command:

    # systemctl start firewalld

Now reload firewall configuration file by typing:

    # firewall-cmd –reload

Now verify your installation of Nginx by visiting the following URL on any browser you like with http://ip_address

7. Configure Nginx File

An Nginx server configuration file plays an important role, So you should be more careful when setting up this file.

For configuring Nginx file go inside the following path with the following command:

# cd /etc/nginx/conf.d

# vi default.conf (Creating new file)

And write the following code in the above file i.e. default.conf.    

Also change your domain in place of   ip_address       

server {

        listen       80;

        server_name  3.95.30.147;

root /usr/share/nginx/html/joomla;

        index index.php index.html index.htm;

location / {

          try_files $uri $uri/ =404;

       }

error_page 404 /404.html;

            location = /40x.html {

        root /usr/share/nginx/html/joomla;

     }

        error_page 500 502 503 504 /50x.html;

            location = /50x.html {

        root /usr/share/nginx/html/joomla;

}

        location ~* \.php$ {

        try_files $uri =404;

        fastcgi_pass unix: /var/run/php-fpm/php-fpm.sock;

        fastcgi_index index.php;

        include fastcgi_params;       

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

   

        }

}

And save it with :wq command, after that edit the configuration file of php-fpm with the following command:

    # vi /etc/php-fpm.d/www.conf

Open the file with above command and edit the following lines i.e.

user = nginx

group = nginx

Add new listen under listen  = 127.0.0.1:9000

listen = /var/run/php-fpm/php-fpm.sock

And also add 

listen.owner = nginx 

listen.group = nginx

Remove comment (;) from the above two lines and save it with :wq.

8. Install Joomla File

     You can easily download Joomla archive file from the link I provided in this blog.

First go inside /tmp directory by typing below command:

    # cd /usr/share/nginx/html

Make one directory i.e. joomla,

# mkdir joomla

Come inside the joomla directory:

    # cd joomla/

Download the latest Joomla setup by using wget command:

    # wget https://downloads.joomla.org/cms/joomla3/3-7-5/Joomla_3-7.5-Stable-Full_Package.zip  ?format=zip

And if wget command not work then you can download it with the following command:

    # yum -y install wget

Now unzip the downloaded file using below command:

    # unzip Joomla_3-7.5-Stable-Full_Package.zip

If unzip command is not work then install it first with the following command:

# yum -y install unzip

Also change the ownership of /var/www/html directory by using the following command:

    # chown -R nginx: /usr/share/nginx/html

# chmod -R 755 /usr/share/nginx/html

Note: Also change the ownership of group of /var/lib/php/session i.e. by default it is set as apache, so now change it’s ownership with:

ls -al /var/lib/php/session (It is used to check the ownership)

    chown root:nginx /var/lib/php/session (It is used to change the ownership)

9. Test Joomla

     Now for testing the server of Joomla you should restart the server for that follow the command:

    # nginx -t (If the command shows ‘successfully’ message then the changes in file are correct and else the changes are wrong in the nginx configuration file.)

    # systemctl restart php-fpm

# systemctl restart nginx

Then open any browser and type inside URL i.e http://ip_address/

After then configuration page i.e. http://ip_address/installation/ is open and then configure the following settings

CONCLUSION 

After the above installation, you will be able to manage your website by Joomla CMS in Centos VPS by using Nginx web server.

Note-: All commands are highlighted with the green color.
All links are highlighted with the blue color.
All files are highlighted with the yellow color.
All notes are highlighted with the red color.

How to install Joomla with LEMP stack on CentOS 7 VPS (Part 1)

Joomla is a popular open source Content Management System(CMS), which is used to build websites and online application. It is separated into front-end and back-end templates.

In Joomla CMS the more focused on portal-like websites.

In this tutorial, you are going to learn how to install Joomla with LEMP(Linux,Nginx,MySQL,and PHP)  on CentOS 7 VPS.


Table of Content

  1. Prerequisites
  2. Install MySQL 8.0
  3. Configure Database in MySQL
  4. Install & Configure PHP 7.2
  5. Install Nginx
  6. Configure Firewall
  7. Configure Nginx File
  8. Install Joomla File
  9. Test Joomla

     1. Prerequisites

Before you start the installation of Joomla with (LEMP) stack on Centos 7 VPS, you must have one Centos 7 VPS with root privileges on it or you can use sudo for non-root user.  

 You should also run basis command on server to check the following things-:

# df -h (To check the disk space on the system.)

# cat /etc/os-release (To verify the version of the VPS.)

# yum -y update (To update all the packages of the VPS)

  1. Install MySQL 8.0

    Joomla uses a MySQL database for storage, MySQL is used in stack for storing user details in database.

For installing MySQL on Centos 7 first you need to enable MySQL repository and then you can install MySQL.

    # yum localinstall  -y https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

The command used for installing MySQL in CentOS 7 VPS is as follows:

    # yum install mysql-server -y

Then check the MySQL version by typing following command:

    # mysql -V(‘V’ is in uppercase)

After the installation is completed MySQL will start automatically and you can check it’s status by typing:

    # systemctl status mysqld

If MySQL is not start automatically you can write the following command:

    # systemctl start mysqld

Before going for the next step you should generate a temporary password to access MySQL root user with the following command:

    # grep ‘temporary password’ /var/log/mysqld.log

Now configure the MySQL secure installation to improve the security by typing the following commands.

# mysql_secure_installation

Login with the temporary password and assign new password, after that in this configuration it ask several questions you can give Y or N according to your requirement.

Change the password for root ? N

Remove anonymous users? Y

Disallow root login remotely? Y

Remove test database and access to it? Y

Reload privilege tables now? Y

  1. Configure Database in MySQL

     Now create database for Joomla in MySQL for that first login with MySQL server by using the following command:

    # mysql -u root -p

And give its password, after that create database in it with the command:

mysql> CREATE DATABASE joomla;

You can also check that database is created or not with the command:

mysql> SHOW  DATABASES;

Now create user and assign him password by using command:

    mysql> CREATE USER ‘joomla’@’localhost’ IDENTIFIED 

BY ‘Password’;

After that grant all privileges to the user created under that database with the command:

mysql> GRANT ALL ON  joomla.* TO ‘joomla’@’localhost’;       

Then flush all privileges on MySQL server with the command:

    mysql> FLUSH PRIVILEGES;

Now exit from the MySQL server you can use commands:

    mysql> exit;

    mysql> \q;

Note-: In MySQL you must end each command with a semicolon(;).

   4. Install & Configure PHP 7.2

    PHP is used by Joomla to do various functions done by PHP like calling plugin, calling theme, validating user permissions, checking option, grab from database, etc.

In this Blog we are using PHP 7.2 versionand install it with epel-release with remi repository.

Firstly, install yum-utils packages using the following command:

    # yum -y install yum-utils

After that, install epel-release package by using command:

    # yum -y install epel-release

Then import remi repository from the command:

    # yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Enable the remi repository by typing:

    # yum-config-manager –enable remi-php72

After that install PHP and all required modules by using command:

    # yum -y install php-fpm php-mysql php-mbstring php-xml      php-gd php-cli php-json php-opcache php-curl

Now after the installation completed you can check the PHP version with the command:

# php -v (‘v’ is in smallcase)

 

To be Continued…….

How to create Automated Backup for website files with shell script?

Backup

With the help of shell script and crontab you can take automated backup in server with the help of following the document.

Archive the content

Backing up your files using tar is very simple using the following command: 

# tar -cvpzf /backup/backupfilename.tar.gz /data/directory

A real example would be backing up the HTML folder for your website, my case:

# tar -cvpzf /backup/file_name.tar.gz /var/www/html

Tar command explained

tar = Tape archive

c = Create

v = Verbose mode will print all files that are archived.

p = Preserving files and directory permissions.

z = This will tell tar that to compress the files.

f = It allows tar to get the file name.

Now create backup script with the help of vi editor.

Create Backup Script

Now let’s add tar command in a bash script to make this backup process automatic. Also it is good to add some dynamic value in the name to make sure there is no overwriting of backup files. 

E.g. Create the file using the vi editor and paste below script.

# vi /backup.sh

Paste the following script and change your details.

#!/bin/bash

TIME=`date +%b-%d-%y`                                                # This Command will read the date.

BK_FILENAME=backup-domainname.com-$TIME.tar.gz    # The filename including the date.

SOURCE=/var/www/html                                                 # Source backup folder.

DESCT=/backup                                                           # Destination of backup file.

tar -czf $DESCT/$BK_FILENAME $SOURCE

Note: The only risk that can occur is to get out of disk memory if the source folder is big, but you can configure it by removing file after 30 days or any number of days with the help of the find command.

find /backup -type f -name ‘*.gz’ -mtime +15 -exec rm {} \;

Automation

In Linux, we can easily use the cron jobs in order to schedule task and perform the above backup task easily.                The cron jobs line has 6 parts see below explanation: Minutes Hours Day of Month Month Day of Week Command 0 to 59 0 to 23 1 to 31 1 to 12 0 to 6 Shell Command Open crontab editor utility:
#
crontab -e 

Note: the edit rules are similar with vi editor.
Paste the following text in the editor:
# M H DOM M DOW CMND
00 04 * * * /bin/bash /backup.sh
This will run the script every day at 04:00:00.
Check the rules of crontab with the help of the following command:
#
Crontab -l 

CONCLUSION

After the above configuration, you can take backup automatically and remove it in some specific period of time.

How to improve GTMetrix score of websites?

GTMetrix

It is a tool that is used to get more and more detailed reports about our site’s performance. It is a free tool that analyzes your page’s speed performance using Google Page Speed and YSlow. 

 

In addition, Google uses page speed in their ranking algorithms. Therefore, a faster performing site may rank higher in search engine results.

Earlier Report

 

To improve your score here, the first thing you must purchase a server from the VPS server provider who provides compression on their server like CloudMinister Technologies. Without server compression, you won’t be able to get a good score.

 

Few more steps you need to consider to get a good score from GTMetrix like Optimize images, Enable caching, Minify HTML, JavaScript code, activate CDN.

 

  • Enable Compression From server-side

 

 

It mostly happens that most of the server providers don’t enable compression by default, so we need to find those server providers who provide compression with the server.

 

 

  • Optimize Images

 

To get more score from GTMetrix we need to optimize all those images that we put on the websites because in large size images it takes more time to load, follow these steps to optimize images.

> Name your images descriptively and in plain language.

> Optimize your alt attributes carefully.

> Choose your image dimensions and product angles wisely.

> Reduce the file size of your images.

> Choose the right file type.

> Optimize your thumbnails.

> Use image sitemaps.

> Beware of decorative images.

> Use caution when using content delivery networks (CDN’s).

> Test your images.

 

 

  • Minify HTML , JavaScript code & CSS code

 

We need to Minify HTML & JavaScript as well as CSS code with this content will read fast by the browser and help your viewers to see the website more quickly. Cloudflare provides this feature to enhance the score on GTMetrix.

 

 

  • Activate CDN

 

A content delivery network (CDN) is a system of servers spread over multiple data centers located around the world. When a user visits your site they will be served content from the server closest to them.

The most popular CDN is Cloudflare – to activate you will need to sign up and add your site to a free plan. Once this is done you will need to change your nameservers so the domain looks towards Cloudflare. This can take up to 24 hours for the DNS to update but is usually much quicker.

After covering all the above points you will be able to get a better score over GTMetrix.

Conclusion – The above configuration shows how to achieve a better score on the GTMetrix, by following all these points your viewer will be able to visit your website more quickly. 

How to create FTP user in CWP panel ?

In CWP panel today I will show you how to create an FTP user so let’s start now. Please do follow my given instructions

Step1- Open CWP login panel
Step2-  Open file manager to create FTP account
Step3-  Check to transfer file

panel

After login into CWP panel go-ahead for further steps -:
Click on File Manager –> FTP Manager V2 –> add user  here I create a user name gulfam@kazakhculturalcentre.com, please keep in your mind password or FTP port 21

ftp_manager

To verify FTP working or not first you already have Filezilla file transfer software in your system. Here you see snapshot how to login into Filezilla. There are two ways to login first via the IP address of the server and second via the domain name.

filezilla cwp

Conclusion: Now you see easily your FTP user login in Filezilla hope you will get benefits from this document.

File compression in Linux

Here you will learn about the file compression and the full overview of types of file compression

File compression used to contain two or more file & directory in smaller size rather than original. Compression means reduce size of file.

In linux have many types of file compression
1. gzip

2. bzip2
3. xz
4. zip

 

# du -sh filename/or/path (This command use to check the size of file)

# yes “string” > file_name (This command use to copy string into file)

Alert :- immediately press (ctrl + c) after use yes command.If you not press (ctrl +c) immediately file size increase every second.

example :- 

  1. gzip :-

gzip is used to compress file but gzip not reduce more  size as compared to others. gzip extension is .gz.   

# gzip file_name (This command used for compress the file in .gz extension)


Uncompress gzip command

# gunzip  file_name.gz (This command used to unzip .gz file)

Example:- 


Create compress and tar file simultaneously 

#tar cvzf destination\path/file_name.tar.gz /source/path/ (This command used to compress in gz format and convert in tar file)

Example:- 


Uncompress and untar  file simultaneously

# tar xvzf file_name.tar.gz (This command used for uncompressing and untar file those extensions have .tar.gz or .tgz)

Example:- 

  1. bzip2

bzip2 is used to compress file bzip2 to reduce the size as compared to gzip. Bzip2 takes time to compress. Bzip2 extension is .bz2

# bzip2 file_name (This command used to compress the file with extension .bz2)

Uncompress bzip2 command

# bunzip2  file_name.bz2 (This command used to unzip .bz2      file)

Example:- 


Create compress and tar file simultaneously using bzip2 

#tar -cvjf destination\path/file_name.tar.bz2 /source/path/ (This command used to compress in bzip2 format and convert in tar file)

Example:- 

Uncompress and untar  file simultaneously using bzip2

# tar -xvf file_name.tar.gz (This command use for uncompress and untar file those extensions have .tar.bz2 or .tbz or .tb2)

Example:- 

  1. Xz

xz is used to compress file xz reduce more size as compared to other compression method.xz  extension is .xz.

# xz file_name (This command used to compress file with extension .xz)

Example:- 

Uncompress xz command

# unxz  file_name.bz2 (This command used to unzip .xz  file)

Example:- 


  1. Zip

Zip is used to compress the file or folder so that reduce the size of that package.
zip is available in linux,windows and unix. Many other software available that work same as zip. example:- WinRAR, 7zip etc.

 

Note: before use zip command first install zip package.

In centos installation :- # yum install zip -y

In ubuntu installation :- # apt-get install zip -y

Zip current all directory and file

# zip file_name.zip * (This command use to zip all current working directory and file) 

Recursively zip all directory file

# zip -r file_name.zip directory\path (This command use to recursively zip all file in a directory)

Exclude some file in zip 

# zip -r file_name.zip directory\path –exclude “*.extension”

(This command use to zip all file in directory but exclude some files using exclude option)

Extract zip file 

# unzip file_name.zip (This command use to extract zip file)

Extract zip file into directory 

# unzip file_name.zip -d directory\path (This command use to extract zip file into a directory)

Ports numbers those are used in Hosting 

These are the commonly port no. that are used in different type odf panels

Panel Port Numbers

Cpanel

Way of establishing an unencrypted connection to the server through http 

opens a connection to the port number 80

2082

Cpanel-SSL

It is the way of establishing an encrypted connection to the server through a secure socket layer through https  opens a connection to the port number 443

2083

Webmail

2095

Webmail-SSL

2096

WHM  (Web Host Manager)

It is a powerful program that allows administrative access to the back end of cPanel.

2086

WHM-SSL

2087

plesk  -: Web hosting platform with a control panel that allows a server administrator to set up new websites, reseller accounts, e-mail accounts and DNS entries

8880

plesk-SSL

8443

CWP ADMIN ( Centos Web Panel)

2030,2086

CWP ADMIN-SSL

2031,2087

CWP User-SSL

2083

CWP User

2082

Protocols Port Numbers

These are the commonly port no that are used in the below protocols

POP 3

110

POP 3-SSL

995

SMTP ( Simple Mail Transfer Protocol)

SMTP is a set of communication guidelines that allow software to transmit an electronic mail over the internet is called Simple Mail Transfer Protocol.

25

SMTP_SSL

465

SMTP alternate

26,587

IMAP (Internet Message Access Protocol)

 The Internet Message Access Protocol is an Internet standard protocol used by email clients to retrieve email messages from a mail server over a TCP/IP connection

143

IMAP-SSL

993

MYSQL  -MySQL is an open-source relational database management system.

3306

RDP (Remote Desktop Protocol)

Remote Desktop Protocol is a proprietary protocol developed by Microsoft which provides a user with a graphical interface to connect to another computer over a network connection

4489

MSSQL

1433

SSH  (Secure Shell)

Secure Shell is a cryptographic network protocol for operating network services securely over an unsecured network

22

FTP (File Transfer Protocol)

21

FTPs

990

SFTP – : SSH File Transfer Protocolthe

SSH File Transfer Protocol is a network protocol that provides file access, file transfer, and file management over any reliable data stream

22

MongoDB -:MongoDB is a cross-platform document-oriented database program. Classified as a NoSQL database program

27017

Postgresql

5432

DNS

53

MTA

25

Conclusion: By using this port no you will be able work on panel and use the protocols easily.

What is a HOSTS file and How do you modify the HOSTS file in different operating system?

–>HOSTS File

HOSTS file is found inside an operating system, that helps to resolve hostname with an IP address before checking in DNS.

In your system, you want to access www.yourdomain.com hostname your system first actually resolve the hostname with IP address of the server.

 

To resolve the IP address it will first check inside HOSTS file which is a simple text file that store entries of hostname with the IP address, and if not found then it goes to your Internet Service Provider(ISP) or DNS server

It is helpful in case of troubleshooting or publishing a website for testing purposes by giving entry in the HOSTS file which resolve hostname with IP address locally before checking in DNS.

 

To modify your HOSTS file in Linux
In Linux the HOSTS file is found inside the /etc directory in the form of simple text file that can be modified by using text editors like:

 1) nano

 2)vi

Open file using the nano editor:

# nano /etc/hosts

 Open file using the vi editor:

# vi /etc/hosts

Image

Note: Use sudo before the following command if you don’t have root privileges:

 After the file is open, give entries of IP address and hostname in the desired manner:

 IP_address        Hostname

 For example:

 111.222.111.222        www.yourdomain.com

 And after that safe file with:

1) Press ctrl + o to save file and ctrl + x to exit from a file if you are  using a nano editor.

2) Press Esc button and write :wq if you are using vi editor.

Image

To modify your HOSTS file in Windows 10

 In windows operating system the hosts file is found inside the c:\\windows\System32\drivers\etc folder to configure it follow the steps:

1) Press Win + r button and search for notepad and should be open with run as administrator

the other entry will not get saved .

image

2) Click on File and select open option, after that goes inside the above specified folder.

image

3) Select All files and now select the hosts file.

image

image

4) After file is open give entry in the last block i.e. localhost name resolution:

#    IP_Address    Hostname

 For example:

#    111.222.111.222        www.yourdomain.com

image

5) Now save the file with the ctrl + s button.

image

To modify your HOSTS file in Mac os

In Mac os  HOSTS file is found under the following path i.e

/private/etc/hosts, you can easily edit it with nano editor by follows the steps:

  1. On your system, select Application > Utilities > Terminal to open a terminal window.

Image

  1. Now open the HOSTS file by using the following command:

# sudo vi /private/etc/hosts

Note: use sudo if you don’t have root privileges.

Image

  1. Now edit the hosts file.

Add your new mapping after the default mapping i.e. (12.0.0.1 – localhost).

  1. To save and exits the HOSTS file, press :wq.

Image

  1. Now ping with the same domain name to check the connection is established or not.

Image

CONCLUSION- The above configuration shows how you can troubleshoot and publish websites for testing purposes by modifying the HOSTS file.

Get started with CloudMinister Today