Pages

Friday, May 3, 2013

Setting password for mysql user in .my.cnf

Setting password for mysql user in .my.cnf

Sometimes you want automated access for root on your MySQL database. One way of accomplishing that is by doing this:

# cd /root
# touch .my.cnf
# chmod 640 .my.cnf

And put in it:

[client]
user=root
password=<password of mysql root user>
Once you have done the following steps, the root user can login to mysql as root user without giving password.
root@server [~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 749
Server version: 5.1.68-cll MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

mysql>

Hide Apache, PHP and Bind Versions

Hide Apache, PHP and Bind Versions
To Check Apache Version:

By default, Apache will send version and modules information like mod_php, mod_perl, mod_ssl in every HTTP header.

If you want to view Apache web server version and sofware of a remote server, follow this procedure.

# telnet example.com 80

Trying example.com...
Connected to example.com.
Escape character is ‘^]'.
HEAD / HTTP/1.0 <- after this press 2 times ENTER
HTTP/1.1 200 OK
Date: Sun, 07 Oct 2012 12:57:57 GMT
Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 JRun/4.0
Last-Modified: Tue, 03 Jan 2012 11:41:16 GMT
Connection: close
Content-Type: text/html; charset=UTF-8
Connection closed by foreign host.

In the above example it is showing all the details about your web server and php this is not recommended for security reasons.We need to hide this information with the following procedure.
To Hide Apache Information:
To hide the information, add the following two apache directives in Apache configuration file, (httpd.conf or apache2.conf)

ServerTokens ProductOnly

ServerSignature Off

# /etc/init.d/httpd restart

Now the output for apache header looks like below

Server: Apache
To Hide PHP Version Details

Locate php.ini loaded in the server.

Change the following option in php.ini

expose_php On

to

expose_php Off

# /etc/init.d/httpd restart
To Hide BIND Version
You can check the Bind version of a server by using the following command.

# dig +short @XXX.XXX.XXX.XXX -c CH -t txt version.bind
"9.3.6-P1-RedHat-9.3.6-20.P1.el5_8.4"

To hide your version of bind, change the version value in named.conf as like the following.
You can give any string for the version.

options {
directory "/var/named";
version "We Just Hide It";
};

# dig +short @XXX.XXX.XXX.XXX -c CH -t txt version.bind
"We Just Hide It"

Complile and install PHP from source

Complile and install PHP from source

You can follow the steps shown below to install PHP5.2.x , PHP5.3.x and PHP5.4.x . You can download and install the desired PHP version. Please reade the Important notes before starting the installation.

Here i am using Centos 5.8 64 bit to install PHP. It will work in all the other CentOS 64 bit versions. In the 32 bit OS, there will be corresponding changes in yum install packages. You have to make sure that the installing packages are for 32 bit or not.

I have followed the steps in the following urls to setup LAMP server, i have tested and verified installation by following the steps described in there.

http://linuxadmintips4u.blogspot.in/2012/07/configure-apache.html

http://linuxadmintips4u.blogspot.in/2012/07/configuration-of-mysql.html
PHP
Important Notes:

***If you are using Apache2.4.x with PHP, it is recommanded PHP version above 5.3.x. There some complilation errors in using PHP5.2.x. There are some module mismatches in Apache2.4.x with PHP5.2.x.

***If you are planning to install SUPHP, there some changes in PHP complilation in PHP5.2.x and PHP5.3.x. If you are using PHP5.4.x, you can use the same installation as descripbed below.

***If you are using Apache2.4.x, it is not possible to install SUPHP with any of the PHP versions with the suphp-0.7.1. I am awaiting for the next version of suphp.

***You can follow the below url to install SUPHP in PHP5.2.x , PHP5.3.x and PHP5.4.x .
Installation

[root@vps ~]# cd /usr/local/src/

Download one of the following PHP packages and extract the packges as per the selected packages.

[root@vps src]# wget http://in1.php.net/distributions/php-5.2.17.tar.gz
or
[root@vps src]# wget http://in1.php.net/distributions/php-5.3.24.tar.gz
or
[root@vps src]# wget http://in1.php.net/distributions/php-5.4.14.tar.gz
[root@vps src]# tar -xzf php-5.2.17.tar.gz
[root@vps src]# cd php-5.2.17

Create a script, configure.sh with the following contents. I have tested the following script with all the versions of PHP and it is working fine for me.

#================================================================
#!/bin/bash

"./configure" \
"--prefix=/usr/local/php" \
"--with-apxs2=/usr/local/apache/bin/apxs" \
"--with-config-file-path=/usr/local/apache/conf" \
"--disable-debug" \
"--disable-rpath" \
"--enable-inline-optimization" \
"--enable-sockets" \
"--enable-wddx" \
"--enable-calendar" \
"--enable-ftp" \
"--enable-mbstring=all" \
"--enable-dom" \
"--enable-mbregex" \
"--enable-bcmath" \
"--with-openssl" \
"--with-kerberos" \
"--with-mcrypt" \
"--with-curl" \
"--with-gd" \
"--with-zlib-dir=/usr/lib" \
"--with-jpeg-dir=/usr/lib" \
"--with-png-dir=/usr/lib" \
"--with-freetype-dir=/usr/lib" \
"--with-regex=system" \
"--with-gettext" \
"--with-bz2" \
"--with-iconv" \
"--with-layout=GNU" \
"--with-imap=/usr/local/src/imap-2007f" \
"--with-imap-ssl" \
"--enable-soap" \
"--with-snmp" \
"--with-libdir=lib64" \
"--with-mysql=/usr/local/mysql" \
"--with-pdo-mysql"

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

[root@vps php-5.2.17]# chmod +x configure.sh
[root@vps php-5.2.17]# sh configure.sh

[root@vps php-5.2.17]# make
[root@vps php-5.2.17]# make install

Once the installation completed, create the following link to use the php command directly in terminal.

[root@vps ~]# ln -s /usr/local/php/bin/php /usr/bin/php

Once you done the above steps, check the version of PHP using the following command

[root@vps ~]# php -v
The above compilation command will enable the following modules. You can remove unwanted php modules from the compilation step. You may encounter errors while the compilation. All the errors which i got is added in the 'Possible Error' section at the end of this article. Please check there if you encountered an error during complilation.

Modules Installed During Installation
bcmath bz2 calendar Core ctype curl date dom filter ftp gd gettext hash iconv imap json libxml mbstring mcrypt mime_magic mysql openssl pcre PDO pdo_mysql pdo_sqlite posix Reflection session SimpleXML snmp soap sockets SPL SQLite standard tokenizer wddx xml xmlreader xmlwriter zlib
Possible Errors
I got the following errors while installing php with above modules and the solution i have given fixed those errors.

Compile Time Errors:

Error:
checking libxml2 install dir... no
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.

Solution:
[root@vps php-5.2.17]# yum install libxml2-devel -y

-------------------------------------------------------------------------------------------------------------------------------------------------

Error:
configure: error: Cannot find OpenSSL's <evp.h>

Solution:
[root@vps php-5.2.17]# yum install openssl-devel -y

-------------------------------------------------------------------------------------------------------------------------------------------------

Error:
configure: error: Please reinstall the BZip2 distribution

Solution:
[root@vps php-5.2.17]# yum install bzip2-devel.x86_64 -y

--------------------------------------------------------------------------------------------------------------------------------------------------

Error:
checking for cURL in default path... not found
configure: error: Please reinstall the libcurl distribution

Solution:
[root@vps php-5.2.17]# yum install curl-devel.x86_64 -y

-----------------------------------------------------------------------------------------------------------------------------------------------

Error:
configure: error: libjpeg.(a|so) not found.

Solution:
[root@vps php-5.2.17]# yum install libjpeg-devel.x86_64 -y

------------------------------------------------------------------------------------------------------------------------------------------------

Error:
configure: error: libpng.(a|so) not found.

Solution:
[root@vps php-5.2.17]# yum install libpng-devel.x86_64 -y

----------------------------------------------------------------------------------------------------------------------------------------------

Error:
configure: error: freetype.h not found.

Solution:
[root@vps php-5.2.17]# yum install freetype-devel.x86_64 -y

-----------------------------------------------------------------------------------------------------------------------------------------------

Error:
checking OpenSSL dir for SNMP... no
checking whether to enable UCD SNMP hack... no
checking for net-snmp-config... no
configure: error: snmp.h not found. Check your SNMP installation

Solution:
[root@vps php-5.2.17]# yum install net-snmp-devel -y

-----------------------------------------------------------------------------------------------------------------------------------------------

Error:
configure: error: mcrypt.h not found. Please reinstall libmcrypt

Solution:
[root@vps php-5.2.17]# yum install libmcrypt.x86_64 libmcrypt-devel.x86_64 -y

------------------------------------------------------------------------------------------------------------------------------------------------

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

Solution:

Install imap using the script described in the following url.

http://linuxadmintips4u.blogspot.in/2013/04/error-utf8mime2text-has-new-signature.html

----------------------------------------------------------------------------------------------------------------------------------------

Error:
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:

http://linuxadmintips4u.blogspot.in/2013/04/error-cannot-find-libmysqlclientr-under.html

--------------------------------------------------------------------------------------------------------------------------------------------

Errors in Make
Error:
/usr/bin/ld: cannot find -lltdl
collect2: ld returned 1 exit status
make: *** [libphp5.la] Error 1

Solution:

Here's what you need to do to fix this issue,
1.Verify that the libtool and libtool-ltdl packages are installed.
[root@vps php-5.2.17]# yum install libtool-ltdl.x86_64 libtool.x86_64 -y

2.Symlink libltdl.so to libltdl.so.x.x.x

PHP looks for the libltdl library only at (for x64 at least) /usr/lib64/libltdl.so. The symlink to this file is not included in the libtool packages,you'll have to make it yourself
[root@vps php-5.2.17]# cd /usr/lib64
[root@vps lib64]# ln -s libltdl.so.3.1.4 libltdl.so

Try once again...

------------------------------------------------------------------------------------------------------------------------------------------------

Error:
/usr/local/imap-2007f/lib/libc-client.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [libphp5.la] Error 1
Solution:

Install imap using the script described in the following url.

http://linuxadmintips4u.blogspot.in/2013/04/error-utf8mime2text-has-new-signature.html