error: Cannot find libmysqlclient_r under /usr/local/mysql - PHP Compile Error




Error:

In a x86_64 OS,
While configuring PHP using:

--with-mysql=/usr/local/mysql

checking for specified location of the MySQL UNIX socket... no
checking for MySQL UNIX socket location... no
configure: error: Cannot find libmysqlclient_r under /usr/local/mysql.
Note that the MySQL client library is not bundled anymore!

Solution:

When configuring PHP for x86_64, it is necessary to use:
--with-libdir=lib64

When you compile MySQL from source, it does not place its files in lib64, but rather lib.

Here in my case i have configured MySQL using:
--prefix=/usr/local/mysql

When you entered the /usr/local/mysql directory, you can find 'lib' in there, but in the 64 bit os, PHP compilation forced to check for 'lib64' directory in mysql home directory to compile php with mysql.

ie,
When PHP is configured using --with-mysql=/usr/local/mysql and --with-libdir=lib64, it should search for /usr/local/mysql/lib64, since there is no such directory there encountered an error in PHP compile.

Since MYSQL is compiled from source, there will not be a 'lib64', the following steps will solve this problem.

[root@vps ~]# cd /usr/local/mysql  #Change directory to mysql's home directory
[root@vps mysql]# ln -s lib lib64    #Create a link for lib to lib64


That's it...

error: utf8_mime2text() has new signature - PHP Compilation error





Error:

error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.


Solution:

If you get the above error message when trying to compile php with imap module, you need to install the imap-2007f package first. You can use the following script to install imap-2007f package.
Once you installed imap using the following script, you can compile php with imap by using the following options.

--with-imap=/usr/local/src/imap-2007f --with-imap-ssl

***If you are using php5.1 or earlier versions, you have to use, the following package
ftp://ftp.cac.washington.edu/imap/old/imap-2004g.tar.Z

Copy the following script in imap-php.sh file, then

[root@vps [~]# chmod +x imap-php.sh

[root@vps [~]# sh imap-php.sh

======================================================================================================

#!/bin/sh

CWD=`pwd`
OS=`uname`

#To check if it is 64bit or not.
B64=0

B64COUNT=`uname -m | grep -c 64`
if [ "$B64COUNT" -eq 1 ]; then
B64=1
LD_LIBRARY_PATH=/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib
export LD_LIBRARY_PATH
fi

if [ ! -e /usr/include/krb5.h ] && [ -e /etc/redhat-release ]; then
echo "Installing krb5-devel"
yum -y install krb5-devel
fi


URL="wget ftp://ftp.cac.washington.edu/imap/imap-2007f.tar.gz"
FILENAME=imap-2007f
TARBALL=${FILENAME}.tar.gz

cd /usr/local/src
echo "Downloading ${TARBALL}..."
wget -O ${TARBALL} ${URL}
tar -xzf ${TARBALL}
cd ${FILENAME}

echo "Installing ${FILENAME}..."

if [ ${OS} = "FreeBSD" ]; then
if [ ${B64} -eq 0 ]; then
make bsf
else
make bsf EXTRACFLAGS=-fPIC
fi
else
sed -i  's/SSLDIR=\/usr\/local\/ssl/SSLDIR=\/etc\/pki\/tls/g' src/osdep/unix/Makefile
sed -i 's/SSLINCLUDE=$(SSLDIR)\/include/SSLINCLUDE=\/usr\/include\/openssl/g' src/osdep/unix/Makefile
sed -i 's/SSLLIB=$(SSLDIR)\/lib/SSLLIB=\/usr\/lib\/openssl/g' src/osdep/unix/Makefile

if [ ${B64} -eq 0 ]; then
make slx
else
make slx EXTRACFLAGS=-fPIC
fi
fi


mkdir include lib
chmod -R 077 ./
cp -f c-client/*.h include/
cp -f c-client/*.c lib/
cp -f c-client/c-client.a lib/libc-client.a

echo -e "\n\n\nUse the following options to compile php to enable imap.."
echo " --with-imap=/usr/local/src/imap-2007f --with-imap-ssl"

exit 0;
==========================================================================================

Hope this script helped you to install imap. If you have any problems with this script let me know. Thank you.

Install rkhunter (Rootkit Hunter) in Linux


Install rkhunter (Rootkit Hunter) in Linux


Rootkit Hunter

Rootkit scanner is scanning tool to ensure you for about 99.9%* you're clean of nasty tools. This tool scans for rootkits, backdoors and local exploits by running tests like:

- MD5 hash compare
- Look for default files used by rootkits
- Wrong file permissions for binaries
- Look for suspected strings in LKM and KLD modules
- Look for hidden files
- Optional scan within plaintext and binary files


Installation:


root@server [~]# cd /usr/local/src
root@server [/usr/local/src]# wget http://ncu.dl.sourceforge.net/project/rkhunter/rkhunter/1.4.0/rkhunter-1.4.0.tar.gz
root@server [/usr/local/src]# tar -xzf rkhunter-1.4.0.tar.gz
root@server [/usr/local/src]# cd rkhunter-1.4.0
root@server [/usr/local/src/rkhunter-1.4.0]# ./installer.sh --install

Update rkhunter after installation.

root@server [~]# rkhunter --update

Scanning:

You can run a scan using the following command

root@server [~]# rkhunter -c

You can view all the available options with rkhunter using the following command

root@server [~]# rkhunter --help

If you want to skip the interactive prompts, add the -sk option at the end:

root@server [~]# rkhunter -c -sk


Setup Daily Scan Report:

You can setup a daily scan report by using a cron as like follows.

create a file named /etc/cron.daily/rkhunter.sh with the following script.

==========================================================

#!/bin/sh

( /usr/local/bin/rkhunter --versioncheck
/usr/local/bin/rkhunter --update
/usr/local/bin/rkhunter --cronjob --report-warnings-only
) | /usr/bin/mail -s "rkhunter output" admin@yourdomain.com

==========================================================
root@server [~]# chmod 750 /etc/cron.daily/rkhunter.sh


That's it...

Uploading files using PHP script showing 600 permissions


Wrong Permissions While Uploading via PHP Script



                             I had an issue in one of my webserver in which, when uploading files using any PHP script, it is showing permissions other that default.
By default, files have 644 and directories have 755 permissions.
Here in my case it is showing 600 permission when uploading. When i checked the uploading permissions using ftp client like filezilla, there is no issues in it. The permissions are correct when uploading via FTP client.

There are options in FTP server to set upload permissions. You can set UMASK in those FTP servers if there are issues in FTP client too.

But here in this case it is something related with the PHP settings. There are options to force the permissions in the PHP upload script it self.

It is a suphp server. There are options to set the permissions in suphp server.

You can check the UMASK value using the following command.

[root@webserver ~]# cat /etc/suphp.conf | grep -i umask
umask=0077

I have found that umask set in my server is 0077. which will force permission to 600. I have changed the value to 0022 to fix the PHP upload permission issue.

[root@webserver ~]# cat /etc/suphp.conf | grep -i umask
;umask=0077
umask=0022

Also restart httpd to make it effect in the server.

[root@webserver ~]# /etc/init.d/httpd restart

===============================================================================

Note:-

Here is a sample PHP upload script to check the above issue.

This script will allow you to upload files from your browser to your hosting, using PHP. The first thing we need to do is create an HTML form that allows people to choose the file they want to upload.

create a file named testupload.php with the following HTML code in it.




Please choose a file:







This form sends data to the file "upload.php", which is what we will be creating next to actually upload the file.
Create a upload.php in the same document root in whcih testupload.php contains with the following php script.

<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>



You have to create a directory named upload in the same location.
# mkdir upload

Test the upload and verify the result.
http://domain.com/testupload.php


That's it...

Cisco - Make a backup of running configuration and copy it to a FTP server periodically





Use an FTP Server to Backup the Configuration

1. At the Router> prompt, issue the enable command, and provide the required password when prompted.
   The prompt changes to Router#, which indicates that the router is now in privileged mode.
2. Configure the FTP username and password.
 
Switch#config terminal
Switch(config)#ip ftp username test
Switch(config)#ip ftp password test123
Switch(config)#end
Switch#

3. Create a backup and copy the running-configuration into a ftp server. If you have correctly set the ftp user and password, you will get an output as follows.

Switch#copy running-config ftp://xxx.xxx.xxx.xxx/running-config.txt
Address or name of remote host [xxx.xxx.xxx.xxx]?
Destination filename [running-config.txt]?
Writing running-confix.txt !
3267 bytes copied in 1.484 secs (2201 bytes/sec)
Switch#

4. You have to use Kron to backup the configuration periodically. Here in this case, backup process must not be interactive.
   You can use the following command to create backup and copy it to FTP server automatically witout any interactive session.

Switch#show running-config | redirect ftp://xxx.xxx.xxx.xxx/running-config.txt
Switch#

5. Create a new backup policy for the backup job.

Switch (config)#kron policy-list Backup
Switch (config-kron-policy)#cli show running-config | redirect ftp://xxx.xxx.xxx.xxx/running-config.txt
Switch (config-kron-policy)#end

6. Create a Kron occurrence named 'Daily-Backup' to run on daily at 00:00. Also add the kron policy in this kron job.

Switch (config)#kron occurrence Daily-Backup at 00:00 recurring
Switch (config-kron-occurrence)#policy-list Backup
Switch (config-kron-occurrence)#end
Switch #

You can check the status of Kron using the following command.

Switch #sh kron schedule
Kron Occurrence Schedule
Backup inactive, will run again in 0 days 03:18:44 at 0 :00 on


You can check the current running configuration using  the following command. You can find the Kron job settings in the running configuration.
You can find a portion of kron as like follows when running the following command.

Switch #show running-config
.
.
.

kron occurrence Daily-Backup at 0:00 recurring
 policy-list Backup
!
kron policy-list Backup
 cli show
 cli show running-config | redirect ftp://xxx.xxx.xxx.xxx/running-config.txt
!
kron policy-list backup
!
.
.
.


Verify if the Kron job successfull copied the back in the remote server.

Note:-

You can modify the cronjob to run on different time.
To remove commands from the policy-list,

Switch(config)#kron policy-list Backup
Switch(config-kron-policy)#no  cli show running-config | redirect ftp://xxx.xxx.xxx.xxx/running-config.txt
Switch(config-kron-policy)#end


Reference:
http://www.cisco.com/en/US/products/sw/iosswrel/ps1835/products_tech_note09186a008020260d.shtml

cPanel - Script to fix permissions/ownership under a reseller


Fix permissions/ownership under a reseller


                             I recently had an issue with incorrect ownership and permissions  of all files under a reseller in cpanel after the manual migration from a Kloxo and plesk server.
I created the following script to fix permissions under a reseller.

You just copy the following script in a file fixperm.sh, then

# chmod +x fixperm.sh

Give the reseller user name in the <reseller> field when running the fixperm.sh. If no parameter is given, it will fix permissions/ownership of all accounts in the server.

# sh fixperm.sh <reseller>


#====================================================================


reseller=$1
echo -e "Fixing Permissions of account under $reseller \n"
for i in `grep -rl "OWNER=$reseller" /var/cpanel/users | cut -d/ -f5`
do
if [ "$i" != "root" ]; then
chown -R $i:$i /home/$i
chown $i:nobody /home/$i/public_html
chown $i:mail /home/$i/etc 
find /home/$i/public_html/ -type d -exec chmod 755 "{}" \;
find /home/$i/public_html/ -type f -exec chmod 644 "{}" \;
chmod 750 /home/$i/etc /home/$i/public_html
echo $i
fi
done


#====================================================================


That's it...

cut command examples in Unix/Linux - Bash


cut command examples in Unix/Linux - Bash


                             Cut command in unix (or linux) is used to select sections of text from each line of files. You can use the cut command to select fields or columns from a line by specifying a delimiter or you can select a portion of text by specifying the range or characters. Basically the cut command slices a line and extracts the text.

In cut command -d stand for specifying delimiter -f will help to specify the column. You can specify delimiter as like follows,
-d" " --> space as delimiter
-d"." --> dot as delimiter
-d":" --> colon as delimiter
You can give any single character as delimiter, even alphabets and nummbers.

Please note the following variety of cut command samples. Here i am using dot as delimiter to give you some samples.

cut and print 2 to rest of all columns.
# echo www.domain.com | cut -d"." -f2-
domain.com

cut and print 2nd column.
# echo www.domain.com | cut -d"." -f2
domain

cut and print first to 2nd column.
# echo www.domain.com | cut -d"." -f-2
www.domain

cut and print 1st,3rd columns.
# echo www.domain.com | cut -d"." -f1,3
www.com

cut and print 1st and 4 to rest of all columns.
# echo a.b.c.d.e | cut -d"." -f4-,1
a.d.e

cut and print 1 to 3 and 5th columns.
# echo a.b.c.d.e | cut -d"." -f1-3,5
a.b.c.e

cut and print 3rd character.
# echo abcde | cut -c3
c

cut and print 3-rest of characters.
# echo abcde | cut -c3-
cde

cut and print first-3 of all characters.
# echo abcde | cut -c-3
abc

That's it...