Tricks and Tips about Systems/Network

October 14, 2010

How do I enable apc php extension on Centos

Filed under: admins,Apache,General — Liju Mathew @ 5:58 am

There is 2 ways to install.

1. Download the apc source code from the pear library and install.
2. Using pear to install apc (easy way)

Ensure that pear is there, if not execute
#yum install php-pear
pear will be installed along with the php installation from the source.

#pecl install apc
echo “extension=apc.so” > /etc/php.ini

Verified it by,
#php -m | grep “apc” or you may choose phpinfo page to verify that
apc

Restart apache to make this working over the web
# service httpd restart

October 11, 2010

SSL received a record that exceeded the maximum permissible length

Filed under: admins,Apache,Godaddy,Webserver — Liju Mathew @ 5:17 pm

I got the following error during Godaddy ssl setup on one of my client server. I refers Godaddy’s ssl documentation for creating CSR and installing SSL. I can easily able to generate and complete the SSL certificates to be issued. But it seems than Godaddy ssl installation steps missed a step which shooting me an error like this “SSL received a record that exceeded the maximum permissible length”

After googling caused me to check various factors and I got confusing .. Changed the name based virtualhost to ip based virtualhost () and re-configuring Apache to listen (Listen 7.6.2.3:443) on new purchased ip in order to tunnel the ssl traffic to new ip. Everything is seems to ok but I’m getting same error even I have re-key the ssl certificate.

Finally I found that neither of SSL engine (SSLEngine on) wasn’t declared any where in virtual host which causing to throw such errors.

<VirtualHost 7.6.2.3:443>
ServerName secureddomain.com
ServerAlias www.secureddomain.com
ErrorLog /var/log/httpd/sd_error.log
TransferLog /var/log/httpd/cd_trasfer.log
DocumentRoot /home/securedd/public_html
DirectoryIndex index.php index.html
SSLEngine on
SSLCertificateFile /home/sysadmin/ssl/secureddomain.com.crt
SSLCertificateKeyFile /home/sysadmin/ssl/secureddomain.com.key
SSLCertificateChainFile /home/sysadmin/ssl/gd_bundle.crt
<Directory /home/securedd/public_html>
Options -Indexes IncludesNOEXEC FollowSymLinks
allow from all
AllowOverride All
</Directory>
</VirtualHost>

-njy

September 18, 2010

Enabling IMAP extension in PHP

Filed under: admins,Apache,PHP — Liju Mathew @ 6:50 am

My server configuration is,

Centos 5.4 with PHP 5.2.12 (compiled manually)

The steps you need to do is go through the source tree which has compiled previously
#yum install libc-client-devel
#cd /home/installation/php-5.2.12/ext/imap
#phpize
# ./configure --with-imap --with-kerberos --with-imap-ssl

If you haven’t installed the libc-client library before, you will get a similar error as below,

checking for IMAP SSL support... yes
checking for utf8_mime2text signature... new
checking for U8T_CANONICAL... no
configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.

Which can be solved by installling the following yompackage

  • #yum install libc-client-devel
  • You may also use this config parameter during the php compilation time.
    “–with-imap –with-kerberos –with-imap-ssl”

    Verifying by
    #php -m | grep “imap” will returns
    imap

    July 16, 2010

    PMA : The server is not responding (or local MySQL server’s socket is not correctly configured

    Filed under: admins,Apache — Liju Mathew @ 1:17 am

    The server is not responding (or local MySQL server’s socket is not correctly configured

    I got PhpMyAdmin error during the login time. I used custom “my.cf” for pointing the Data directory and socket path to listing.

    [mysqld]
    datadir= /home/MYSQL/
    socket= “/home/MYSQL/mysql.sock”
    max_connections = 500

    After that I have edited the conf.inc.php file inside the phpmyadmin folder. Ensure that following variable are difined on the config. file,

    $cfg['Servers'][$i]['host'] = '192.168.20.213'; changed localhost to my server ip
    $cfg['Servers'][$i]['connect_type'] = 'tcp';
    $cfg['Servers'][$i]['compress'] = false;
    $cfg['Servers'][$i]['port'] = '3306';
    $cfg['Servers'][$i]['socket'] = '/home/MYSQL/mysql.sock'; modified custom mysql socket file

    After that it’s work normally.

    cheers

    June 24, 2010

    Mod_security: Denying access to specific url

    Filed under: admins,Apache — Liju Mathew @ 6:48 am

    I have a WHM/Cpanel installed server and create a  user  account for new hosting. But I won't wish the developers have the cpanel access and able to work with the development process.  I have installed a "PhpnyAdmin' on the hosting space. During the querry execution I hit by the following error messages,

    "Wed Jun 23 13:07:14 2010] [error] [client 111.62.2.21] ModSecurity: Access denied with code 500 (phase 2). Pattern match "(insert[[:space:]]+into.+values|select.*from.+[a-z|A-Z|0-9]|select.+from|bulk[[:space:]]+insert|union.+select|convert.+\\(.*from)" at ARGS:sql_query. [file "/usr/local/apache/conf/modsec2.user.conf"] [line "355"] [id "300016"] [rev "2"] [msg "Generic SQL injection protection"] [severity "CRITICAL"] [hostname "domain.com"] [uri "/expodb/import.php"] [unique_id "kcSXD0WnrkAAABr6MJ8AAAAF"]

    #vi /tail -f /usr/local/apache/logs/error_log

    Wed Jun 23 13:07:14 2010] [error] [client 116.68.92.21] ModSecurity: Access denied with code 500 (phase 2). Pattern match "(insert[[:space:]]+into.+values|select.*from.+[a-z|A-Z|0-9]|select.+from|bulk[[:space:]]+insert|union.+select|convert.+\\(.*from)" at ARGS:sql_query. [file "/usr/local/apache/conf/modsec2.user.conf"] [line "355"] [id "300016"] [rev "2"] [msg "Generic SQL injection protection"] [severity "CRITICAL"] [hostname "domain.com"] [uri "/expodb/import.php"] [unique_id "kcSXD0WnrkAAABr6MJ8AAAAF"]

    Where "expodb is the folder name  where PMA renamed and limited the ip access  configured.

    I found mod_security  causing the issue and I  need to add exception in.

    a. open the apache config file ( /usr/local/apache/conf/httpd.conf) and  add the following entry under the respective virtual host entry

    <LocationMatch "/expodb/">
    SecRuleRemoveById 300016
    </LocationMatch>
    You can see the  SecRuleRemoveById is from the  apache  mod-security error messages.
    Now it's the turn to restart the apache and save the custom 'http.conf' entry to make permement.
    [root@host.domain.com] ~ >>  #/usr/local/cpanel/bin/apache_conf_distiller --update
    Distilled successfully
    # /usr/local/apache/bin/apachectl restart

    May 20, 2010

    How do I enable MSSQL extension on php

    Filed under: admins,Apache,CentOS,Linux — Liju Mathew @ 10:57 pm

    I have a requirement to enable MSSQL extension on php and need to access remote MSSQL server from the server. I think this requirement is very rare in case and need a dedicated hosting for this. Technically accessing database from different network will affect the application performance badly during the peak hours time. I will add the tutorial for how to enable the remote access on MSSQL server on another session.

    OS : Centos
    PHP build : Custom compilation, php-5.2.9

    1. Download ODBC driver for Linux and install. You can find it from here
    [root@rc-157 installation]# wget : http://www.unixodbc.org/unixODBC-2.3.0.tar.gz
    [root@rc-157 installation]# tar -zxvf unixODBC-2.3.0.tar.gz
    [root@rc-157 installation]# cd unixODBC-2.3.0
    [root@rc-157 installation]# sh configure && make && make install

    2. Download the freedts library
    [root@rc-157 installation]##wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
    [root@rc-157 installation]# tar -zxvf freetds-stable.tgz
    [root@rc-157 installation]# cd freetds-0.82/
    [root@rc-157 installation]# ./configure --prefix=/usr/local --sysconfdir=/usr/local/ --with-tdsver=8.0 --with-unixodbc=/usr/local --enable-msdblib
    [root@rc-157 installation]# make && make install

    Sometimes you get a error during the 'freetds' compilation time when you are using Fedora. Best option to skip this error is use "./configure –with-tdsver=8.0 –with-unixODBC=/usr/local”  on the configuration time.

    Next steps is to build the mssql extension against the php build that already created. Go to php source directory which is used for the previous compilation. Here I uses the source folder under “/home/installation/php-5.2.9″

    [root@rc-129 mssql]# cd /home/installation/php-5.2.9
    [root@rc-129 php-5.2.9]# cd ext/mssql/
    [root@rc-129 mssql]# pwd
    /home/installation/php-5.2.9/ext/mssql
    [root@rc-129 mssql]#phpize
    [root@rc-129 mssql]#./configure –with-mssql
    [root@rc-129 mssql]#make
    [root@rc-129 mssql]#make install

    [root@rc-129 mssql]# make install
    Installing shared extensions: /usr/lib/extensions/no-debug-non-zts-20060613/

    [root@rc-129 mssql]# vi /etc/php.ini
    added the line “ extension=mssql.so” and ensure the extension_dir = “/usr/lib/extensions/no-debug-non-zts-20060613″
    [root@rc-129 mssql]# php -v ” there is no error displayed”
    PHP 5.2.9 (cli) (built: Aug 13 2009 17:51:53)
    Copyright (c) 1997-2009 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies

    [root@rc-129 mssql]# php -r ‘phpinfo();’ | grep “mssql”
    mssql
    mssql.allow_persistent => On => On
    mssql.batchsize => 0 => 0
    mssql.charset => no value => no value
    mssql.compatability_mode => Off => Off
    mssql.connect_timeout => 5 => 5
    mssql.datetimeconvert => On => On
    mssql.max_links => Unlimited => Unlimited
    mssql.max_persistent => Unlimited => Unlimited
    mssql.max_procs => Unlimited => Unlimited
    mssql.min_error_severity => 10 => 10
    mssql.min_message_severity => 10 => 10
    mssql.secure_connection => Off => Off
    mssql.textlimit => Server default => Server default
    mssql.textsize => Server default => Server default
    mssql.timeout => 60 => 60
    PWD => /home/installation/php-5.2.9/ext/mssql
    _SERVER["PWD"] => /home/installation/php-5.2.9/ext/mssql
    _ENV["PWD"] => /home/installation/php-5.2.9/ext/mssql

    [root@rc-129 mssql]# service httpd restart
    Stopping httpd: [ OK ]
    Starting httpd: [ OK ]

    Pls not that MSSQL extension can be enabled without unixodbc driver but you can’t establish the connection untill you not bind it with freedts installation.

    You may use the following sample php file to test the connectivity.

    error_reporting(E_ALL);
    $a = new dbConnect();
    class dbConnect {
    var $connId;
    var $host;
    var $db;
    var $user;
    var $pass;
    #function dbConnect
    function dbConnect() {
    $this->host = '192.168.0.1:8000';
    $this->db = 'userdb';
    $this->user = 'username';
    $this->pass = 'pass';

    $this->connId = mssql_connect($this->host, $this->user, $this->pass);
    if (!$this->connId) {
    trigger_error(“Error connecting to Server $this->host”, E_USER_ERROR);
    die();
    }else{
    echo ‘Connected to MSSQL server sucessfully’;
    }
    if (!mssql_select_db($this->db, $this->connId)) {
    trigger_error(“Unable to connect to database $this->db”, E_USER_ERROR);
    die();
    }
    }
    function __destruct(){
    if ($this->connId){
    @mssql_close($this->connId);
    #print(“Database Connection Closed”);
    }
    }
    }

    May 11, 2010

    How do I install UCC SSL certificate on Cpanel servers

    Filed under: admins,Apache,Control panel,WHM/Cpanel — Liju Mathew @ 12:32 am

    I have purchased a UCC ssl certificate from Godaddy which is support to used for 5 domains. I can installed my primary domain ssl easily by reading Godaddy’s cpanel installation instructions. But I couldn’t see they anywhere for ssl implemention of other domain.

    I have tried to install this ssl from the WHM–> ssl manager. But every time the primary ssl domain name certificate is re-installing. There is no any errors showing up during the installation and it’s still using self-signed certificate on browsing. After spending with 30 minutes I feel there is noting we can do with cpanel.

    Then I directly checked the http.conf settings and copy my primary domain ssl settings to the other virtualhost which is included on the SAN list of that SSL certificate.

    SSLCertificateFile /etc/ssl/certs/www.sites.com.crt
    SSLCertificateKeyFile /etc/ssl/private/www.sites.com.key
    SSLCACertificateFile /etc/ssl/certs/www.sites.com.cabundle

    Pls note that we can use the same certificate and private key for all the domains included on the UCC certificate. Then I restarted the Apache and found that it’s working correctly. I have verified it by viewing the certificate file also.

    Now we need to fix the custom modification on httpd.conf saved on cpanel settings. for doing this,
    root@server81-28-25-12 [~]# /usr/local/cpanel/bin/apache_conf_distiller --update

    April 22, 2010

    Customizing php local variables on web

    Filed under: admins,Apache,PHP — Liju Mathew @ 6:11 pm

    I need to reset the php values of ‘upload_max_filesize” to 11MB but the default settings were set to 2MB. But I do not want to change this setting affected globally.

    Here are the tips.

    1. Create a empty ‘php.ini; file on the web where you want to use the upload size high.

    I want upload variable set to 12MB on this web folder (/home/wwwasd/public_html/uploadsfiles) only.
    Eg. http://asd.com/uploadfiles
    I created a php.ini under ‘/home/wwwasd/public_html/uploadsfiles’ and add the values “upload_max_filesize = 20M”

    #vi /home/wwwasd/public_html/uploadsfiles/php.ini
    add the following lines and save the file.
    upload_max_filesize = 20M

    If it is not work in some servers, then you may use the .htaccess files to do that.
    Add the value in .htaccess file
    php_value variable value
    php_value upload_max_filesize 100M

    April 16, 2010

    Force users to use https rather than http

    Filed under: admins,Apache,CentOS,Linux — Liju Mathew @ 4:55 am

    Here is the rewrite rule which helps to re-direct all http requests will change to https tunnel when the user hit it on the browser

    Copy it on .htaccess to the folder where you want to protect the access only through SSL.

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

    March 30, 2010

    How do I enable openssl extension on PHP

    Filed under: admins,PHP,Webserver — Liju Mathew @ 11:47 am

    I used a custom php build on My Centos server. Now I want to enable openssl extension in order to communicate with SSL.

    Solution.

    Download and install openssl
    1. #wget http://www.openssl.org/source/openssl-1.0.0.tar.gz
    #./config && make && make install you may use yum method to install it ( yom install openssl*)
    2. Next step is to start the phpp re-compilation. For this, have modified my config parameter in order to work with ‘openssl’

    ./configure –prefix=/usr/local/php –with-apxs2=/usr/sbin/apxs –with-xsl –with-mysql –with-config-file-scan-dir=/etc/php.d –prefix=/usr –exec-prefix=/usr –bindir=/usr/bin –sbindir=/usr/sbin –sysconfdir=/etc –datadir=/usr/share –includedir=/usr/include –libdir=/usr/lib –libexecdir=/usr/libexec –with-config-file-path=/etc –with-bz2 –with-curl –with-exec-dir=/usr/bin –with-png –with-zlib –with-pear=/usr/share/pear –with-zml –with-gd –with-libxml=/usr/lib –enable-calendar –with-openssl=shared –with-png –with-bcmath –with-mysqli –enable-soap -with-jpeg –enable-sockets –enable-mbstring –enable-shared –with-jpeg-dir=/usr/local –with-freetype-dir=/usr/local/lib –with-pdo-mysql=shared –with-gettext

    [root@rc-040 php-5.2.9]# mv /usr/lib/httpd/modules/libphp5.so /tmp/

    # cd php-5.2.9
    #make && make install

    I have modify the ext_dir (extension_dir = “/usr/lib/extensions/no-debug-non-zts-20060613″)  location on php.ini and add a new line “extension=openssl.so” at the end of  /etc/php/ini “file

    #service httpd restart
    [root@rc-040 php-5.2.9]# php -r 'phpinfo();' | grep openssl
    openss
    l

    Open the browser and verify “openssl “ is showing on phpinfo() function.

    Next Page »

    Theme: Rubric. Blog at WordPress.com.

    Follow

    Get every new post delivered to your Inbox.