securing cpanel website

Here we will learn easy command which will correct permission and ownership of all files and folders from cPanel account.

Below is command to correct ownership and permission of all files and folders of cPanel user. To execute this command you need root user access.

Suppose are securing permission and ownership of cPanel user midnight. Then commands will be.

Correcting ownership of home directory

chown midnight.midnight /home/midnight

Command to set secure permission for home directory of cPanel user midnight

chown 711 /home/midnight

Following command will find all files and set secure permission as 644.

cd /home/midnight/public_html;find ./ -type f -exec chmod 644 "{}" \;

Now find all folders and set secure permission as 755

cd /home/midnight/public_html;find ./ -type d -exec chmod 755 "{}" \;

Above command will set 755 permission to public_html folder as well. But recommended permission for public_html folder is 750

cd /home/midnight/public_html;chmod 750 ../public_html

Now correcting ownership of all files and folders stored in public_html

cd /home/midnight/public_html;chown midnight.midnight ../public_html -R

Then correct ownership of public_html folder using command

cd /home/midnight/public_html;chown midnight.nobody ../public_html

You have set secure permissions and ownership to all files and folders for cPanel account midnight.

Transfer Website from Weebly to WordPress

How to transfer a website from weebly to wordpress ?

Weebly is web designer software which make easy to design web site using weebly. But many advance web developer use wordpress CMS which provide more access to internal code. This is main reason people need to migrate site from weebly to wordpress.

But weebly doesn’t provide feature to export web site. There is a 3rd party tool named as WPBeginner weebly to wordpress site. We will learn in detail how to migrate using this tool.

Install WordPress

Setup new hosting account with your domain name (which is being used by weebly application). In order to install wordpress on the domain you don’t need to point dns of the domain to new hosting account. Instead just edit host file of your local PC and on last line add IP and domain in following format

IP-address-here yoursitename.com

This will point yoursitename.com to new IP (IP of new hosting account). Now install wordpress , and configure it like setting up theme, install required plugins for backup, security etc..and modify primary menu according to your original site requirement.

Migrate Content

Now we are ready to migrate data from weebly site to new wordpress site.

1: Visit url WeeblytoWP.com.

2: Insert your Weebly website URL (starting with HTTP:// or HTTPS://), name, and email account before clicking Export my Weebly Website.

3: Save the Export file.

4: In WordPress, after downloading your Weebly export file, select Tools and Import.

5: Select WordPress to install and activate the WordPress Import Plugin.

6: Select Run Importer at the top of the screen.

7: Browse for your RSS file before selecting Upload file and import.

8: Make any preferred changes on the Import Settings and assign an author to the imported posts. You can create an author or use an existing user.

The imported content should now show in their respective sections in WordPress.

Import Content Manually.

Many text and contents will not available in export file which will need to be copy manually. ie. Create page / post on your wordpress site and then copy text from weebly to wordpress pages/post and publish them.

Now time to Import images.

We recommend to use WordPress plugin. such as Save & Import Image from URL to import directly from Weebly. 

The easiest way to get an image URL:

For browser like Google Chrome: Right-click the image and select Open image in a new tab.

Fix Permalinks:

Now setting up Permalinks so that format of url’s of old website should match to new site’s url so that your user will not get 404 error while accessing urls using bookmarks. Also you will not need to submit urls for indexing. It can be set from WordPress > Wp-admin > Setting > Permalinks

creating database without cpanel user prefix

Creating mysql user and database without cPanel user prefix.

By default cPanel used to create database and DB user with cPanel username _as prefix. But now cPanel version 68 allows you to disable prefixing so you can create single DBs and DB users.

You can enable disable prefix feature from

WHM > Tweak Setting >  Require a username prefix on names of new databases and database user

Example: If you create database with name wp as cPanel user india. It will create database as india_wp but if you disable this then it will allow you to create database with name wp only.

Access webalizer stats without login to cpanel

How to access webalizer stats without login to cpanel.

First login to cPanel > File manager > public_html > edit .htaccess.

Now create symlink for webalizer in public_html folder using following command.

ln -s ../tmp/webalizer webstats

chown username.username webstats

chmod 755 ../tmp/webalizer

Replace webstats with name you want in order to access your website statistics.
Change the owner to account user and permissions to 755.

You will need ssh access to create symlink.

If you don’t have ssh access . Then create php file in public_html and copy paste following code in it.

<?php

$target = ‘/home/cPanelusername/tmp/webalizer’;

$shortcut = ‘webstat’;

symlink($target, $shortcut);

?>

Now, access it using browser. This will create symlink and you will able to access webalizer stats using url  yoursite.com/webstats .

You can remove php you created to generate symlink.

Access Awstats without logging into cPanel

How to access Awstats without logging to cPanel

We will learn how to configure awstats to access without cPanel.

Download awstats-version-number.tar.gz from http://awstats.sourceforge.net > dowmnload on your PC.

Create a folder and extract the contents to it. You will find two folders cgi-bin and iocn you need to upload then using File Manager (in cPanel) or FTP to “public_html” folder.

Then go to public_html/cgi-bin & change the permissions of the awredir.pl and awstats.pl files to 755.

Now go to homedirectory via FTP there you will find folder tmp/awstats/. Search for awstats.mydomain.com.conf. (mydomain.com should be your domain). This is file created by cPanel just download it to your PC.

Edit this file with text editor and alter ‘DirIcons’ line to DirIcons=’/icon/’ and upload it public_html/cgi-bin folder.

Now you shall able to access awstats using url

http://www.mydomain.com/cgi-bin/awstats.pl?config=mydomain

We recommend to password protect cgi-bin folder.

Creating mysql user and database without prefix

Create mysql user and database without prefix.

By default cPanel used to create database and DB user with cPanel username _as prefix. But now cPanel version 68 allows you to disable prefixing so you can create single DBs and DB users.

You can enable disable prefix feature from

WHM > Tweak Setting >  Require a username prefix on names of new databases and database user

Example: If you create database with name wp as cPanel user india. It will create database as india_wp but if you disable this then it will allow you to create database with name wp only.

Automated Backup of mysqlDB on cpanel

Here we will learn how to backup all databases of cPanel server in specified folder say /home/mysqlbackup

First of all we will list all databases in a file using command

  • echo “show databases” | mysql > /home/DB_list.txt

By default first line of the output is DATABASE and rest of lines are name of databases.

Second command will help to get rid of first line.

  • tail -n +2 /home/DB_list.txt > /home/DB_list2.txt

So we have DB_list2.txt with list of all databases.

Here we will use for loop to backup all databases listed in DB_list2.txt

  • for m in `cat /home/DB_list2.txt`;do mysqldump $m > /home/mysqlbackup/$m.sql;done

 

Listing cPanel users UID more than 1000

Listing cPanel users ( UID more than 1000) from hash prompt.

Command to list all cpanel users from hash prompt

awk -F: ‘{if ($3 > 1000) {print $1}}’ /etc/passwd

To execute some shell script we need list of all cPanel users.   On cPanel server default setting is in such way it will create cPanel user with UID more than 1000.  That make very easy to list all cPanel users from /etc/passwd file using awk command.

1st column and 3rd column of /etc/passwd file contain username and UID. Above command checks if UID (3rd column value) is more than 1000 , if yes then print 1st column that is cPanel username.  As all columns are separated by “:” hence we used it as separator in command (-F:).