Tuesday, November 13, 2012

How to remove IP manually from cpanel

1 Bring down the ip first
for example ifconfig eth0:cp3 xxx.xx.xx.xx netmask 255.255.255.0 down

2. Edit /etc/ips and remove the line with the corresponding ip

3. Run this command /etc/init.d/ipaliases restart

Thursday, October 11, 2012

Some example for httpd.conf



  DocumentRoot /path/to/domainname
  ServerName domainname
  redirect permanent / https://domainname/
 Alias /sandbox /path/to/domainname/sandbox



The above is just an example on how to setup the virtualhost on apache
The Alias is like a subfolder inside the public_html but you can put the folder in parallel to the public_html.

Thursday, September 6, 2012

Wednesday, August 22, 2012

Recover mysql root password

You can recover MySQL database server password with following five easy steps.

Step # 1: Stop the MySQL server process.

Step # 2: Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password.

mysqld_safe --skip-grant-tables

Step # 3: Connect to mysql server as the root user.

Step # 4: Setup new mysql root account password i.e. reset mysql password.


mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit



Step # 5: Exit and restart the MySQL server.


Thursday, August 2, 2012

Mysql grant


mygrants()
{
  mysql -B -N $@ -e "SELECT DISTINCT CONCAT(
    'SHOW GRANTS FOR ''', user, '''@''', host, ''';'
    ) AS query FROM mysql.user" | \
  mysql $@ | \
  sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}'
}

Put the above command to /root/.bashrc and when typing mygrants command, it will show the mysql privilege

Tuesday, July 24, 2012

htaccess redirect to www

To redirect a domain from a non www to a www domain, just add .htaccess


RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


to reverse redirect a domain from a www to a non www


RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]


Another way using the conf

redirect permanent / https://insert-url-of-your-site/

Example of using multiple url to point to the same site

  ServerName domain1.net
  DocumentRoot /opt/rlcache/www/moodle_prod
  Alias /sandbox /opt/rlcache/www/moodle_sand



  ServerName  domain2.net
  Redirect permanent / http://domain1.net/









Wednesday, July 18, 2012

Add column to existing table in mysql


ALTER TABLE contacts ADD email VARCHAR(60);

This first statement will add the email column to the end of the table. To insert the new column after a specific column, such as name, use this statement:

ALTER TABLE contacts ADD email VARCHAR(60) AFTER name;

If you want the new column to be first, use this statement:

ALTER TABLE contacts ADD email VARCHAR(60) FIRST;

To remove a column
ALTER TABLE table_name
DROP COLUMN column_name