Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Tuesday, 25 November 2014

Install Python for a user

Posted by Sarath On Tuesday, November 25, 2014 No comments
Log into server as user via SSH :

Download Python package of required version from : http://www.python.org/getit/releases/

Say, version required is 2.6.6

Code: 
# wget http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
Code: 
# tar -xvf Python-2.6.6.tgz
Code: 
# cd Python-2.6.6

Configure and Install Python for user :
Code: 
#./configure --prefix=/home/user_name/Python-2.6.6
Code: 
# make
Code: 
# make install

Python Binary for the user will be : /home/user_name/Python-2.6.6/bin/python and to check version :
Code: 
# /home/user_name/Python-2.6.6/bin/python --version

That's All..!! 

Monday, 9 September 2013

Extend Xen Disk Space

Posted by Sarath On Monday, September 09, 2013 1 comment
Xen VMs use lvms and extending disk space from SolusVM control panel may not work properly. So, we will need to extend the lvm manually.
Shutdown VM from SolusVM control panel or use the following command on node :
# xm shutdown vm_ID 
(Replace vm_id with the xen ID of the VPS)
Extend LVM :
# lvextend /dev/Xen/vm_ID_img -L +50G 
(This will increase the main disk size for vm by 50G)
Checking File System for errors :
# e2fsck -f /dev/vg0/vm_ID_img 
Resize File System :
# resize2fs /dev/vg0/vm1_ID_img 
(This will increase the disk's filesystem to the maximum new amount)
Boot up the VM:
# xm create vm_ID /home/xen/vm_ID/vm_ID.cfg 

Done..!! Now check the VPS Disk Space using df command.

phpinfo() has been disabled

Posted by Sarath On Monday, September 09, 2013 No comments
If you get the message while browsing php info page, it means that phpinfo function is disabled. To resolve this you will have to :

Remove phpinfo from disable_functions in php.ini

To locate php.ini file, use command :
# php --ini
Check the line Loaded Configuration File: for php.ini location. Remove phpinfo  from disable_functions in php.ini and save it.

Now check the phpinfo page..!!  8)

Saturday, 7 September 2013

Change SolusVM admin password

Posted by Sarath On Saturday, September 07, 2013 No comments
If you forget or lose your SolusVM Admin password, you can change it using SolusVM php script.
Log into SolusVM master server via SSH. Then you can reset the admin password by running the below command :
Code:
php /usr/local/solusvm/scripts/pass.php --type=admin --comm=change 
--username=<ADMINUSERNAME>

For username mention the admin username for SolusVM , the default Admin username is vpsadmin.
You will get an output similar to this:
Code:
New password: Wc7Q0EbVFUasJ4j
Done..!! Now you can log into SolusVM server with the new password.

Enable MySQL slow query log

Posted by Sarath On Saturday, September 07, 2013 No comments
The slow query log consists of SQL statements that took more than long_query_time seconds to execute and required at least min_examined_row_limit rows to be examined. It is very helpful in troubleshooting bad queries.

Add the following to /etc/my.cnf file to enable the slow query log:
Code: 
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:

Code: 
touch /var/lib/mysql/slow.log
Code: 
chmod 660 /var/lib/mysql/slow.log
Code: 
chown mysql:mysql /var/lib/mysql/slow.log

Done..!! I hope that was too easy..  ;)

Iptables problems on VPSes

Posted by Sarath On Saturday, September 07, 2013 No comments
You might have come across issues with csf on VPSes.

CSF requires at least these iptables modules to work properly :
ip_tables
ipt_state
ipt_multiport
iptable_filter
ipt_limit
ipt_LOG
ipt_REJECT
ipt_conntrack
ip_conntrack
ip_conntrack_ftp
iptable_mangle

Other modules for additional functionality:
ipt_owner
ipt_recent
iptable_nat
ipt_REDIRECT

You can check the hosting environment using :

Code: 
/etc/csf/csftest.pl

This should run without any FATAL errors. If any such errors are present, check the module failed and see if it is installed on node. You can use "lsmod" command for that.
Eg :
Code: 
# lsmod | grep ipt_limit

If any of the modules is not present on the node, install it using modprobe command.
Eg :
Code:
# modprobe ipt_limit

Then to enable modules in VPS :

Code:
# vzctl set CT_ID --iptables ip_tbales ipt_multiport --iptables ipt_REJECT 
--iptables ipt_recent --iptables xt_connlimit --iptables ipt_owner --iptables 
ip_conntrack --iptables iptable_nat --iptables iptable_mangle --iptables 
ipt_state --iptables ipt_limit --iptables ipt_LOG --iptables ipt_owner --save 

(Replace CT_ID with container ID)

These changes will be applied after the container restart.

If you get any "memory allocation" errors with iptables on a VPS, make sure that your numiptent setting is set sufficiently high.  Set numiptent  to at least 1000.

Code:
# vzctl set CT_ID --numiptent 1000 --save
(Replace CT_ID with container ID).
The locate command is a very useful command to find the exact path/location of files in Linux if you know the file name. You can install it using yum and the package is mlocate.
Quote
can not open `/var/lib/mlocate/mlocate.db': No such file or directory
It is a common issue while using locate command, and the error is because we haven't created the db for locate. To create db for locate, simply run the command :

Code: 
# updatedb

Wait for it to complete and run the locate command again. It should be working fine this time...!!!  :D
You can use the same command (updatedb)to update recent changes to locate's db.

535 Incorrect Authentication Data

Posted by Sarath On Saturday, September 07, 2013 No comments
The error normally caused due to incorrect permissions. We can fix mail box permissions from WHM on cPanel servers. For that : 

1) Log into WHM as root and click on "Email" section.
2) Select "Repair Mailbox permissions"
3) It will show a message like :

This function will inspect mailbox ownership and permissions and attempt to 
fix any issues that may exist. 
Click "Proceed >>" button.

The error normally occurs when PHP tries to process a big database records or when importing or exporting. To solve the error, there are two fixes. One is to increase PHP memory limit of the account by using a custom php.ini file. But sometimes it won't work.

If it didn't work, then you can fix the error by increasing the memory of the particular PHP script (displayed in error message) by adding an additional line at the top of the script:

Code: 
ini_set(”memory_limit”,”32M”);  
  (Change the value based on the error message).

Now browse the page again, perform the operation again. It will just work fine if you have set correct value based on the error message.

Awststats not working/updating - cPanel

Posted by Sarath On Saturday, September 07, 2013 No comments
It can be caused due to many issues and here I am posting some fixes for that.
First check permission of /usr/local/cpanel/3rdparty/bin/awstats.pl, it should be 755.


Then to update awstats and webalizer run the script :
Code: 
# /scripts/runweblogs user_name
If that didn't work try fixwebalizer script :

Code: 
# /scripts/fixwebalizer

If that doesn’t update stats, then check domlogs of the domain and see if it is up to date. You can use the following script to run statistics :
Code: 
# /scripts/runstatsonce

If none of the above fixes the issue and the awstats page for the domain is still showing the old date for last update, run the following command :
Code: 
# /usr/bin/perl /usr/local/cpanel/3rdparty/bin/awstats.pl -config=/home/user_name/tmp/awstats/awstats.domain.com.conf -LogFile=/usr/local/apache/domlogs/domain.com -update
Replace domain.com with your domain name and replace user_name with your cPanel username.

That will fix the issue...!! :)

Adding and Deleting route

Posted by Sarath On Saturday, September 07, 2013 No comments
Add Route
========
Code: [Select]
# route add default gw GATEWAY_IP eth0

Delete Route
==========
Code: [Select]
# route del default gw GATEWAY_IP

Check Routing Table
===============
Code: [Select]
# route -n
Or
Code: [Select]
# netstat -r -n

Sample Output :

Kernel IP routing table
Destination     Gateway         Genmask          Flags  MSS Window  irtt  Iface
0.0.0.0           192.168.2.1     0.0.0.0             UG         0  0             0  eth0
169.254.0.0    0.0.0.0            255.255.0.0      U           0  0             0  eth0
192.168.2.0    0.0.0.0            255.255.255.0  U            0  0             0  eth0

Destination -- Destination host/network.
Gateway -- Gateway address.
Genmask -- Netmask for the destination net.

Flags :
U - route is up
H - target is a host
G  -use gateway

Hope it helps you while configuring networks.

Saturday, 6 July 2013

You may have come across this error before while trying to restore mysql databases, it can be easily fixed by increasing max_allowed_packet value. Check the current value first. Get into mysql prompt and enter the following query :
select @@max_allowed_packet;
Then you can increase the value either by adding the variable in my.cnf file or executing the query in mysql prompt :
set global max_allowed_packet = 64*1024*1024; (64 MB, change it as per your needs)
Restart mysql if you are setting the value in my.cnf file. Now check the new value using the same query we used above and try restoring the database.

Install rails locally for a user from command line

Posted by Sarath On Saturday, July 06, 2013 No comments
Login to the server via SSH as user, then enter the command :
# gem install rails -v=2.3.5

With -v option you can specify the rails version you want to install, here in this example it is 2.3.5.
Then check the gem list locally,

# gem list --local | grep -i rails
That will show the rails version they installed.

You can also install other Ruby gems like rack, rake, etc. using the same method.

Thursday, 4 July 2013

Test perl script

Posted by Sarath On Thursday, July 04, 2013 No comments
To check if perl is working on a server: Open a test file,
# vi test.pl
And enter the following code :

#!/usr/bin/perl
print "Content-Type: text/html\n\n";
print "<html><body><h1>Perl is working!</h1></body></html>";

Save and browse the file, www.yoursite.com/test.pl (replace yoursite.com with your website name).

Tuesday, 2 July 2013

Testing mod_rewrite

Posted by Sarath On Tuesday, July 02, 2013 No comments
If you face issues in getting rewrite rules of your website to work, first check if mod_rewrite is installed/enabled.
# httpd -l | grep rewrite

If mod_rewrite is installed on the server, you will get the following output :

  mod_rewrite.c

If it is not installed, then you will have to recompile apache with mod_rewrite enabled. In cPanel servers, you can do that using easyapache (/scripts/easyapache). Once installed then comes the testing part. To test mod_rewrite, simply add the following code to .htaccess file of your website:

RewriteEngine on
RewriteRule ^testpage\.html http://google.com [R]
Once the .htaccess file has been updated, enter the following into your browser:
www.yoursite.com/testpage.html replace yoursite.com with your website name. If mod_rewrite is working fine, then the page will get redirected to Google.

That's it.. :)

vBullettin 404 error

Posted by Sarath On Tuesday, July 02, 2013 No comments
It is a common issue with vBulletin. If you get 404 - page not found error in vBulletin, first try enabling RewriteBase within .htaccess file.
In order to do so please find the following line within your .htaccess
#RewriteBase /
and uncomment that line.
If you have installed vBulletin inside a sub folder such as forum you should use the following RewriteBase
RewriteBase /forum/
If this does not resolve your problem please make sure your host supports mod_rewrite and you are allowed to use .htaccess file on your hosting.

Sunday, 30 June 2013

Innodb disabled - MySQL

Posted by Sarath On Sunday, June 30, 2013 No comments
First check for any disable options for innodb in /etc/my.cnf like
skip-innodb and remove them if there is any. Then restart mysql:
If that doesn't work, try
# /etc/init.d/mysql stop
# mv /var/lib/mysql/ib_logfile0 /var/lib/mysql/ib_logfile0.bak
# mv /var/lib/mysql/ib_logfile1 /var/lib/mysql/ib_logfile1.bak
# /etc/init.d/mysql start
 To check, get into mysql prompt and use the command :
> show engines;
InnoDB is enabled by default. But, MySQL seems to disable it automatically if your InnoDB log files get corrupted. When you remove them, they are recreated, allowing InnoDB to start again.

Unblock an IP from IPTABLES

Posted by Sarath On Sunday, June 30, 2013 No comments
To check if an IP is blocked in iptables, use the command :
# iptables -nL | grep IP 
Sample output :

DROP       all  --    x.x.x.x    0.0.0.0/0
If the IP is blocked in iptables, to see the rule :

iptables-save|grep IP
Sample output :
-A LOCALINPUT -s x.x.x.x -i eth0 -j DROP
Take the results and replace "-A" with "-D" and run it with iptables
Eg
: iptables -D
LOCALINPUT -s x.x.x.x -i eth0 -j DROP

Dual PHP Kloxo - CentOS

Posted by Sarath On Sunday, June 30, 2013 No comments
I came across a situation this week where a client wanted to install Zend Optimizer on his VPS as his website needed it. But the default PHP version installed on the server was PHP 5.3 and Zend Optimizer works only with PHP versions upto 5.2. So we had two options in front of us to resolve the issue, either install  5.2 from source or advice the client to recompile his application with Zend guard loader which is the replacement for Zend Optimiser in PHP 5.3 and newer versions. (Applications compiled for Zend Optimiser won't work with Zend guard loader). As he don't wished to recompile his application, we went for the first option. That's to install PHP from source.
Some additional packages will be needed for the installation, so we will install them first :
# yum -y groupinstall "Development Tools"
# yum -y mysql-devel libtool-ltdl-devel bzip2-devel libcurl-devel libxml2-devel libmcrypt-devel curl-devel
Now download PHP package from www.php.net/downloads.php# cd /usr/local/src

# wget http://museum.php.net/php5/php-5.2.17.tar.bz2
# tar -xvzf php-5.2.17.tar.bz2
# cd php-5.2.17
Compile and install PHP

#./configure --prefix=/usr/local/php_52 --enable-cgi --with-config-file-path=/usr/local/php_52 --enable-ftp --enable-mbstring --with-openssl --enable-magic-quotes --with-zlib --with-bz2 --with-curl --with-gd --with-mcrypt --with-mysql --enable-zip --enable-libxml --with-gettext --with-gmp --with-iconv
# make clean
# make
# make install

Now we need to make apache to detect this installation. As its Kloxo we need to perform some additional tasks/modifications. First create a script,

# cd /var/www/cgi-bin
# vi php52-cgi
Add the below code :

#!/bin/sh
PHPRC="
/usr/local/php_52/"
export PHPRC
PHP_FCGI_CHILDREN=4
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
exec
/usr/local/php_52/bin/php-cgi
Then save the file.# chmod +x php52-cgi
# cd ~
# ln -s /usr/local/php_52/bin/php-cgi /usr/local/bin/php52

Now we need to modify apache config
# cp -prf /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf_org
# echo 'Enable PHP5.2 Handlers' >> /etc/httpd/conf/httpd.conf
# echo 'ScriptAlias /php52-cgi /var/www/cgi-bin/php52-cgi' >> /etc/httpd/conf/httpd.conf
# echo 'Action application/x-httpd-php52 /php52-cgi' >> /etc/httpd/conf/httpd.conf

But when we runs fixweb script, the additions to httpd.conf will get deleted. So, we need to modify fixweb script

# cp /script/fixweb /script/fixweb.orig
# vi fixweb
Add the below code :

#!/bin/sh

. /script/fix.inc

. /script/directory
lphp.exe ../bin/fix/fixweb.php $*

#Reinstate php5.2 handlers
echo 'Enable PHP5.2 Handlers' >> /etc/httpd/conf/httpd.conf
# echo 'ScriptAlias /php52-cgi /var/www/cgi-bin/php52-cgi' >> /etc/httpd/conf/httpd.conf
# echo 'Action application/x-httpd-php52 /php52-cgi' >> /etc/httpd/conf/httpd.conf

service httpd restart

Then save the file.
# mv fixweb /script/fixweb
# chmod 700 /script/fixweb

Now add the following code in your website's .htaccess file :

<FilesMatch "\.php">
SetHandler application/x-httpd-php52
</FilesMatch>

That's all.. :)

Restart Tomcat script

Posted by Sarath On Sunday, June 30, 2013 No comments

Here is a simple script that is tested on CentOS and Ubuntu. It will work on all other UNIX like platforms. You can make modifications to this script to restart any other services, for example apache. You can also use pgrep command instead of pidof command.

# vi
script.sh
  ##Restart Tomcat##
pidof java
if [ $? -eq 1 ]
then 
echo "Tomcat is down" ; sh /usr/share/tomcat7/bin/startup.sh
fi
And add a cronjob as follows :

*/2 * * * * /path/to/script.sh >/dev/null 2>&1