Archive for the ‘ Linux techies ’ Category

redirects from www and to www

How to setup redirects for domain.com to www.domain.com and vice versa ?

Create a .htaccess file under the root directory and add the code below

Redirect www.domain.com to domain.com

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

Redirect domain.com to www.domain.com

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

Save the file and exit and give it a try once :-)

How to upgrade mysql on cPanel servers ?

Login to WHM with root user and access the option Server Configuration >> Tweak Settings. Look for MySQL and check the radio button for 5.0 from 4.1 OR login to the server via SSH and open the file /var/cpanel/cpanel.config and find for mysql-version. Change it to 5.0 from 4.1. Save the file and exit. Now execute the commands on the server to upgrade the mysql version.

/scripts/upcp –force

/scripts/mysqlup –force

Wait for mysql to upgrade. Once the process is completed, check the mysql version.

banner114

If you receive such error in the error logs or in the browser please follow the steps below.

For non suexec/suphp servers

Create a .htaccess file under the diretcory and add the code below

php_flag short_open_tag X

For suexec/suphp servers

Copy the server’s php.ini file under the diretcory and find for short_open_tag. Open the php.ini file and change it to

short_open_tag = X

Note :: The solution is valid only if you find the error due to line in your php/html file.
HTML Code:

<?xml version=”1.0″ encoding=”iso-8859-1″?>
OR
<?xml version=”1.0″ encoding=”UTF-8″?>

If you receive such error in the error logs OR in the browser make sure output_buffering is set to On in the php.ini file on the server.

If you are on a su-exec/su-php enabled server, copy the original php.ini from the server under the account and make the changes.

What is output_buffering ?

Output buffering allows you to send header lines (including cookies) even
after you send body content, at the price of slowing PHP’s output layer a
bit.  You can enable output buffering during runtime by calling the output
buffering functions.  You can also enable output buffering for all files by
setting this directive to On.  If you wish to limit the size of the buffer
to a certain size – you can use a maximum number of bytes instead of ‘On’, as
a value for this directive (e.g., output_buffering=4096).

How to disable .htacess access for a particular account/domain ?

You can disable .htaccess for a particular domain by editing the /etc/httpd/conf/httpd.conf file & following the below mentioned steps:

Open the /etc/httpd/conf/httpd.conf file.
Search for the “AllowOverride None” string.

<Directory “/”>
AllowOverride None
</Directory>

Append it by:

<Directory “/home/username/public_html”>
AllowOverride None
</Directory>

Such that it looks like:

<Directory “/”>
AllowOverride None
</Directory>

<Directory “/home/username/public_html”>
AllowOverride None
</Directory>

Restart the httpd/apache service on the server

This would disable the .htaccess for that particular account/domain.

If you are facing any issues while parsing .html, .htm, .jsp, .js and other extension files through php, add the below code in the .htaccess file under the diretcory

AddHandler application/x-httpd-php5 .js .html .htm .jsp >> Server with php5

AddHandler application/x-httpd-php4 .js .html .htm .jsp >> Server with php4

If you want to limit the parsing just for a file add the code below

For php5

<FilesMatch “filename.js”>
AddHandler application/x-httpd-php5 .js
</FilesMatch>

For php4

<FilesMatch “filename.js”>
AddHandler application/x-httpd-php4 .js
</FilesMatch>

728x90-new

Core Files

You may come across core files which gets generated within your accounts . The possible reason for the core files getting generated is when a php process is killed, apache creates core files under your account.

On phpSuexec servers this may cause due to incorrect php.ini file placed in your account and if it is caused due to php/apache then you can get rid off those core files by editing the httpd startup file on the server end.

Follow the steps below to stop the core file creation on the server.

root@server [~]# vi /etc/init.d/httpd

Search for ulimit lines .

For eg : you can see these lines

ulimit -n 1024
ulimit -n 4096
ulimit -n 8192
ulimit -n 16384

You need to add ulimit -c 0 at the end .

Which will look like :

ulimit -n 1024
ulimit -n 4096
ulimit -n 8192
ulimit -n 16384
ulimit -c 0

Save changes and quit.

Now kill / stop apache service and then start apache service on the server .

root@server [~]# service httpd stop

root@server [~]# service httpd startssl

If you have ever wanted to display a message to your users when the log in through ssh, you just need to edit a couple of files.  The first one is:

vi /etc/motd

This file has the text that will be displayed when an authorized user logs in through SSH.  The next change we need to make is to the SSH configuration file, which tell it to display the MOTD (message of the day).  The file can be found here, on a CentOS 5 system:

vi /etc/ssh/sshd_config

Look for the line containing PrintMotd and change the value to yes.  Make sure it is also uncommented.  If you wish to have a custom message for each user, it can be done a couple of different ways, however, I will only show you one.  We will create a new directory, and within that directory, give each user that has SSH access a file to use for a custom message.  Then, we need to edit the login script that the users use, in this case, bashrc, to include the per user file.

mkdir /etc/usermotd  <– makes the directory that we will use

vi /etc/usermotd/username <– this is where you would add the text you wish to display.

vi /etc/bashrc <– edit the bash file to include our new user motd

You need to add the below to the bottom of the bashrc file:

if [ -f /etc/usermotd/${USER} ]; then
cat /etc/usermotd/${USER};
fi

Save & quit

You are done !!!

Below commands can be used to check file and diretcory permissions under the present working diretcory (pwd)

  • Check files with permission 755

root@master [~]# find $x -type f -perm 755

  • Check files with permission 777

root@master [~]# find $x -type f -perm 777

  • Check diretcory with permissions 777

root@master [~]# find $x -type d -perm 777

  • Check diretcory with permissions 000

root@master [~]# find $x -type d -perm 000

You can change the permissions to the value you  you want to search.

If you see the below error in your logs then that means that the script is owned by a user (generally root) instead of the actual user.

SoftException in Application.cpp:303: UID of script “/location/path/.php” is smaller than min_uid

You can receive similar error when you have a wrong group name, in this case instead of UID, you will have GID in the error.

To fix this issue, make sure you have correct user and group ownership for the file that you are trying to access. Ownership can be changed using the below:

chown usernmame:groupname filename.php