Pages

Thursday, October 31, 2019

How to block an IP?

If you want to stop someone from visiting your website, you can use the IP Blocker interface within cPanel which allows you to block access to your site for one or more IP addresses or fully qualified domain names (FQDNs).

You can easily block an IP in cPanel by following these steps:

1) Log into cPanel.
2) Look for the “SECURITY” section and click on “IP Blocker” icon.
3) You can add a single IP, an IP range or a domain name to the block list, click the “Add” button to set the block.
4) If you scroll down on the same page, you’ll see a list of all the blocked IPs, from here you can also delete an IP from the block list.

Rock on.

How to ban any IP Address via .htaccess

If someone is trying to hack your website or you want to block their IP Address, you can add this line to your .htaccess file.

order allow,deny
deny from IP-ADDRESS
allow from all


Replace “IP-ADDRESS” with the IP Address you want to block.

Rock on.

Set Password or SSH Key for CentOS Cloud Images using virt-sysprep

Step 1: Install virt-sysprep

Type the following apt-get command/apt command to install virt-sysprep on a Debian or Ubuntu Linux:

$ sudo apt install libguestfs-tools


If you are using a CentOS/RHEL/Oracle/Scientific Linux, type the following yum command:

$ sudo yum install libguestfs-tools


If you are using a Fedora Linux, type the following dnf command to install the same:

Saturday, October 26, 2019

How to Install MySQL on CentOS 7

This guide will outlined how to install MySQL on CentOS 7. MySQL is a widely used database management platform used by various applications. Many applications such as WordPress, Joomla and others rely on MySQL databases to function. MySQL however, must be installed with a few different steps since it’s no longer the default in the CentOS repositories.

All commands without sudo

yum update -y
yum install -y wget
wget http://repo.mysql.com/mysql-community-release-el7-7.noarch.rpm
rpm -ivh mysql-community-release-el7-7.noarch.rpm
yum update -y
yum install -y mysql-server
systemctl start mysqld
systemctl enable mysqld
mysql_secure_installation


All commands with sudo

How to Disable SSH Login for the Root User

In this document, we will show you to disable the SSH root login to your server.

A major security hole is to allow direct root access without any restrictions. This is an open door for hackers. They can attempt to brute force your root password and potentially get access to your server if the password can be guessed.

Quick Steps:

Login to the server via SSH.
Open the file “/etc/ssh/sshd_config” in any of your favorite text editors.
Find the section in the file containing the line with “#PermitRootLogin yes” in it.
Uncomment and change it to “PermitRootLogin no”.
Save the file and exit.
Restart the sshd service.


Disabling SSH Login for Root

The first step is to login to the server. Please note that you need to get more than one terminal access to the server because in case we lost one connection you can recover and get access to the server with the other one.

Open the SSH configuration file with your text editor.

How do I create a custom php.ini file

A custom php.ini file can be constructed and placed in your web account. For instance, using a text editor such as Notepad, you can create a php.ini file with the following custom setting which would override our default server setting:

file_uploads=off

The php.ini file should only contain the custom settings - each on it's own line (such as the above example). When completed, save the file and upload it to an area (folder) on your web account where the rest of your php files are located.

NOTE: The php.ini file should be uploaded into every folder and/or subfolder where the settings need to take place.  Be sure to rename your php.txt file to php.ini before you upload it to your server.

Cron jobs

A 'cron job' is an automated task that can be set up within your cPanel. This will typically be used to automate the running of a reminder script each day for example, or perhaps to run your own daily backup script. Any server task or script that needs regular scheduling is the perfect opportunity to use a cron job.

We would ask that you be sparing with your use of cron jobs however, as a resource-intensive script executing every five minutes for example would clearly breach our acceptable use policy. Our recommendation would be to schedule cron jobs to run only as and when they are needed.

Your online cPanel allows for the creation of cron jobs via a simple web interface. This is presented in plain english, and requires little understanding to operate.

If you decide to use the "Advanced" option however, the following information may assist you in understanding how the system works.

Understanding the format

How to host the Primary Domain from a subfolder (.htaccess)

Your main domain will use the public_html directory for all of its website files by default. Addon domains use sub directories inside the public_html directory.

In order to also set up your main domain to use a subdirectory on your hosting account you will need to set up a redirect in the .htaccess file in the public_html folder so that the server knows that any request for your main domain will be redirected to a subdirectory on public_html.

Modifying the .htaccess

The following code will need to be added to the .htaccess file in the public_html folder of your hosting account. You will need to insert the following code block and make modifications as noted in the (#) comments.

You will need to change the two instances of example.com to your domain, and the three instances of subdirectory to the folder where you want your site.

# Hostingname.com (Your Hosting Name)
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /subdirectory/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ subdirectory/index.html [L]


Visitors to your website will not be able to tell that your main domain is using a subdirectory.

Note:  This method is not guaranteed to work with every script or software and can be used at your own discretion.

How to change the date.timezone value in PHP?

If your PHP scripts do not show the correct time, the reason is that most probably your hosting server is in a different timezone.

This can be easily resolved by changing a setting in PHP called date.timezone.
Depending on your location you can set a specific date.timezone value in PHP using the following option which should be added to your local php.ini file:
date.timezone = "US/Central" 

The above example assumes you'd like to set the timezone for your PHP scripts to US/Central. The full list of supported time zones is available here and you should simply replace "US/Central" with the desired timezone.

Cron PHP | How To Run PHP Scripts From Cron Jobs?

This article describes how to run PHP scripts from cron jobs.

Running PHP scripts from cron jobs

A common method for running PHP scripts from a cron job is to use a command-line program such as curl or wget. For example, the cron job runs a command similar to the following command:

curl http://example.com/script.php

In this command, curl retrieves the web page, which then runs the PHP script.

However, there is a better way to run PHP scripts on your web site from cron jobs. You can run the script directly by using the PHP command-line interpreter. This method is just as effective, and usually faster. The following command shows how to run a script using the PHP command-line interpreter: