Tuesday, July 21, 2015

Restore MySQL database from a backup file

Backing up your MySQL Databases

The following command will dump all databases to an sql file. Replace pass with your root database password and filename with the name of the file you wish to create such as backup.sql
# mysqldump -u<user> -p<pass> -B --all-databases > <filename>
# mysqldump -uroot -pSuperPass -B --all-databases > all.sql
A single database can be backed up also.
# mysqldump -u<user> -p<pass> <database> > <filename>
# mysqldump -uWiki -pBlue wikidb > wikidb.sql

Restore MySQL database from a backup file

There are many reasons you would want to restore a database from a backup file… But you should also test this on a test server just to make sure that your database backups are working correctly. Here’s the syntax:
mysql -h hostname -u username -pthepassword databasename < dumpfile.sql
Here’s an example:
mysql -h localhost -u root -ptgX!2121 < thedumpfile.sql

Monday, July 20, 2015

Linux: Find out serial / model number and vendor information for SATA and IDE hard disk


One of the below command may be used to get the Harddisk information.

1:   smartctl --all /dev/sda 

2:   hdparm -I /dev/sda 

where sda is the drive which need to check.


Sunday, July 19, 2015

How to install NginX on cPanel/WHM Server

NginX is one of the most popular choice open source Web server and a reverse proxy. For those who are not very familiar with Linux & have cPanel/WHM installed in your server or VPS here is the guide on how to install them.

The package comes with Nginx Admin plugins for cPanel. To install execute the following command through SSH client. You have to login as root.

cd /usr/local/src
tar xf nginxadmin.tar
cd publicnginx
./nginxinstaller install

If you are installing Nginx Admin for the first time and there is Python Error while installing you have to execute the following command.



./pythonfix
./nginxinstaller install
If you want to uninstall Nginx Admin, execute the following commands.






cd /usr/local/src
tar xf nginxadmin.tar
cd publicnginx
./nginxinstaller uninstall



Cpanel Enable the slow query log

You would add the following to /etc/my.cnf file to enable the slow query log.
log-slow-queries=/var/lib/mysql/slow.log
After that, then do the following commands to create the file with the right ownership and file permissions:
touch /var/lib/mysql/slow.log
chmod 660 /var/lib/mysql/slow.log
chown mysql:mysql /var/lib/mysql/slow.log


How to Install cPanel/WHM on CentOS VPS

cPanel/WHM installation on your VPS or dedicated server is very easy. Just follow the steps below & you are done. Remember that you need fresh CentOS installation prior to installing cPanel/WHM.

1. Run your preferred SSH client such PuTTY. Connect to your server & login as “root”.
2. Download & install cPanel/WHM by running the following commands one by one.


cd /home
sh latest

The process will take approximately 60 to 90 minutes but it is largely depending on your server internet connection and performance.

If you only want to install cPanel DNSONLY version use the following command instead


cd /home
sh latest-dnsonly

Once the installation complete, login to your WHM as root to configure,

http://yourip:2086    OR
https://yourip:2087

Saturday, July 18, 2015

How to Check mod_rewrite Module in Apache/LiteSpeed is Loaded

To check if mod_rewrite Module is loaded in Apache/LiteSpeed follow the following steps:

1. For system with cPanel, log to SSH in issue the following commands

/usr/local/apache/bin/httpd -D DUMP_MODULES | grep rewrite
If it return the following, then mod_rewrite is loaded
Syntax OK
rewrite_module (static)

2. For system with no cPanel, check “httpd.conf” file. If the following is in the file then it should be loaded.


LoadModule rewrite_module libexec/apache2/mod_rewrite.so


Restart IP Pool

If you have additional IPs added in WHM/Cpanel it may not bring them up after network restart.
In order to fix this behavior run the following command:

  /scripts/restartsrv_ipaliases

to make aliases available on network interface again.

Monday, July 6, 2015

How to change the primary IP addres of a WHM/cPanel server

Steps in WHM:
  • Log into WHM and go to Basic cPanel & WHM Setup
  • Change the Primary IP here with the option that says "The IP address (only one address) that will be used for setting up shared IP virtual hosts"
  • Note: This might not actually be necessary.

Log in to SSH, and do the following:
  • Edit /etc/sysconfig/network-scripts/ifcfg-eth0
    • Change the IPADDR and GATEWAY lines to match the new IP and Gateway for the new ip

  • Edit /etc/sysconfig/network
    • Change the GATEWAY line here if it does not exist in the ifcfg-* file.
  • Edit /etc/ips
    • Remove the new primary IP from this file if it is present
    • Add the old primary IP to this file with the format ::
       
  • Edit /var/cpanel/mainip
    • Replace the old primary IP with the new primary IP
  • Edit /etc/hosts
    • Replace the old primary IP with the new one if needed. The hostname's dns will need to be updated too
  • Restart the network service to make the new IP the primary
    • service network restart
    • Note: You're probably going to be disconnected at this point, and have to log in to ssh using the new primary ip.
  • Restart the ipaliases script to bring up the additional IP
    • service ipaliases restart
       
  • Run ifconfig and make sure all IPs show up correctly
  • Update the cpanel license to the new primary IP 
  • Verify you can still log in to WHM and there is no license warning