Wednesday, March 28, 2012

HOW TO Install phpMyAdmin in CentOS

I am using CentOS 5 in one of my Virtual Servers and I wanted it to have phpMyAdmin. I tried installing it by doing yum install phpmyadmin but it said No package phpmyadmin available. So I add to add a repo. I discovered that rpmforge repo had this package. To add it, I executed the following commands:
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm
rpm -Uhv rpmforge-release-0.5.1-1.el5.rf.i386.rpm
If you have 64-bit version installed, you should try this one out:
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm
rpm -Uhv rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm
If you get a 404 Not Found, then you will need to figure out the latest updated version of repo url from rpmforge usage page.
After that, you may like to update your packages by doing this:
yum update
and then continue installing phpmyadmin
yum install phpmyadmin
It should ask you for confirmation and you can continue installing phpMyAdmin with dependencies.
When installation is done, you can edit /etc/httpd/conf.d/phpmyadmin.conf and allow it to be opened from anywhere and not just the same computer. You are going to need this if you have installed it in a remote virtual server.
To do so, open up /etc/httpd/conf.d/phpmyadmin.conf using:
nano /etc/httpd/conf.d/phpmyadmin.conf
You will see:
<Directory "/usr/share/phpmyadmin">
  Order Deny,Allow
  Deny from all
  Allow from 127.0.0.1
</Directory>
Just change the line “Allow from 127.0.0.1″ to “Allow from [yourip]“, where [yourip] is IP address of your computer if you have public static IP. Otherwise, you can also set it to “Allow from all”.
Press Ctrl+O followed by Enter to save and Ctrl+X to exit nano.
Now, you must restart apache. To do so, run
service httpd restart
Now, you can access phpMyAdmin by visiting http://vps_server_IP_or_domain/phpmyadmin. But you will get the following error:
Error
The configuration file now needs a secret passphrase (blowfish_secret).
To make it work, you will need to edit config.inc.php. To do so, type in:
nano /usr/share/phpmyadmin/config.inc.php
Find a line saying:
$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS
FOR
COOKIE AUTH! */
Fill in any secret keyword there, eg mysecretpassphrase, so that it looks like:
$cfg['blowfish_secret'] = 'mysecretpassphrase'; /* YOU MUST FILL IN THIS
FOR
COOKIE AUTH! */
and then save it.
If you don’t have mysql server installed, you will get the following error:
Error
#2002 – The server is not responding (or the local MySQL server’s socket is not correctly configured)
To install mysql-server, just run:
yum install mysql-server
and then start it:
service mysqld start
Then change the root password:
mysqladmin -u root password PASSWORD_HERE
Now, you will have to remove phpmyadmin:
yum remove phpmyadmin
and reinstall it again:
yum install phpmyadmin
Then you will need to edit the config.inc.php again to enter blowfish secret (see above). Then, you can login.
If however, you want phpMyAdmin to connect to a remote server, you can change the line by replacing localhost with your server IP:
$cfg['Servers'][$i]['host'] = 'localhost';
Hope this helps.

how to fix : No activity within 1800 seconds; please log in again

1800 seconds is such a long time, right?
  1. It’s 30 minutes.
  2. It’s 0.5 hours.
  3. It’s 0.0208333333 days.
  4. It’s also 5.70397764 × 10-5 years.
And it’s not long enough for me. phpMyAdmin logs you out after 1800 seconds, obviously for security reasons. That’s fine if there are other people about, if I was in an office with people coming and going, but I work from home. All I see for most of the day is my family, the radio, my messy desk, computers, and the view out the window. Time to figure out how to make that 1800 second limit a little longer or remove it altogether.
After a little digging, I discovered that extending the time limit to a day is actually quite easy. Open your phpMyAdmin’s config.inc.php and search for or add the following line:
$cfg['LoginCookieValidity'] = 86400;
Refresh your logged out phpMyAdmin and presuming you haven’t left it idle for 24 hours, you’ll be logged in again!
If the time limit really bugs you, you need http authentication. Look for the “auth_type” line in the config.inc.php and change that to “http”. phpMyAdmin won’t log you out as long as your browser is open. Perfect!
If you’re concerned about sending your MySQL username and password in the clear each time you make a request to phpMyAdmin you can either use SSL or try the “config” auth_type. Make sure you fill in the username and password fields in the config file, and secure the phpMyAdmin directory with a htpasswd file.

How to Install php-mcrypt on CentOS 6.2

Symptoms :
This error appeared when i try to use phpmyadmin on authentication type as cookie. mcrypt is necessary if you want to use cookie based authentication with phpymyadmin.
The mcrypt exension is missing. Please check your PHP configuration.
mcrypt
To install php-mcrypt on CentOS 6.2, follow the following steps :
1. Download epel repository :
[root@centos62 ~]# [root@centos62 ~]# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
[root@centos62 ~]# wget http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6
2. Install epel repository :
[root@centos62 ~]# rpm --import RPM-GPG-KEY-EPEL-6
[root@centos62 ~]# rpm -i epel-release-6-5.noarch.rpm
3. Simply run the following command to install php-mcrypt :
[root@centos62 ~]# yum install php-mcrypt -y

How to check CentOS version via command line?

Via command line, type this:
cat /etc/redhat-release
To safely upgrade CentOS to the latest version, type this:
yum update

Sunday, October 16, 2011

PHP jQuery AJAX Javascript Long Polling

Background

"Long polling" is the name used to describe a technique which:
  • An AJAX request is made (utilizing a javascript framework such as jQuery)
  • The server waits for the data requested to be available, loops, and sleeps (your server-side PHP script)
  • This loop repeats after data is returned to the client and processed (usually in your AJAX request's onComplete callback function)
This essentially simulates a continuous real-time stream from the client to the server. It can be more efficient than a regular polling technique because of the reduction in HTTP requests. You're not asking over and over and over again for new data - you ask once and wait for an answer. In most cases this reduces the latency in which data becomes available to your application.
There are a variety of use cases in which this technique can be handy. At the top of the list are real-time web-based chat applications. Each client executes a long polling loop for chat and user events (sign on/sign off/new message). Meebo is perhaps the greatest example of this.
It's important to note some of the server side technical limitations of long polling. Because connections remain open for considerably longer time than a typical HTTP request/response cycle you want your web server to be able to handle a large number of simultaneous connections. Apache isn't the best candidate for this type of situation. nginx and lighttpd are two lightweight web servers built from the ground up to handle a high volume of simultaneous connections. Both support the FastCGI interface and as such can be configured to support PHP. Again, Meebo uses lighttpd.
For similar reasons - it's also a good idea to choose a different sub-domain to handle long polling traffic. Because of client side browser limitations you don't want long polling connections interfering with regular HTTP traffic delivering page and media resources for your application.

Implementation

jQuery makes implementation a breeze.


var lpOnComplete = function(response) {
    alert(response);
    // do more processing
    lpStart();
};
 
var lpStart = function() {
    $.post('/path/to/script', {}, lpOnComplete, 'json');
};
 
$(document).ready(lpStart);
 
 
Straightforward. When the document is ready the loop begins. Each iteration the returned data is processed and the loop is restarted.
On the server side - just like we discussed earlier:


$time = time();
while((time() - $time) < 30) {
    // query memcache, database, etc. for new data
    $data = $datasource->getLatest();
 
    // if we have new data return it
    if(!empty($data)) {
        echo json_encode($data);
        break;
    }
 
    usleep(25000);
}
 
Actually, a couple points of interest here. We don't actually loop infinitely server side. You may have noticed the logic for the while loop - if we've executed for more than 30 seconds we discontinue the loop and return nothing. This nearly eliminates the possibility of substantial memory leaks. Also, if we didn't put a cap on execution time we would need to print a "space" character and flush output buffers every iteration of the loop to keep PHP abreast to the status of this process/connection. Without output being sent PHP cannot determine if the connection was lost via connection_status() or connection_aborted(). As a result this could lead to a situation where there are an increasing number of "ghost" processes eating up server resources. Not good!
That pretty much sums it up! Not that difficult, right?

Friday, June 24, 2011

How to install LAMP + Zend Ubuntu 11.04

 It's super easy to install LAMP server in Ubuntu 11.04, just need to run the follow command, sudo apt-get install lamp-server^ You may ask to set up root password for mysql during the installation, other than that, everything is automatically. To restart apache, run the following command, sudo /etc/init.d/apache2 restart OK, install Zend is also easy, sudo apt-get install zend-framework After that you have to make sure zend library path is included. Go to php.ini (@/etc/php5/apache2/), edit the following line, ; UNIX: "/path1:/path2" include_path = ".:/usr/share/php:/usr/share/php/libzend-framework-php" I also found, after added include_path in the php.ini, the Zend library is still not found if I run the php script in the command line. Not sure why, but the solution I found is uncomment the line at /etc/php5/conf.d/zend-framework.ini, [Zend] include_path=${include_path} ":/usr/share/php/libzend-framework-php" Happy ubuntu!

Thursday, May 19, 2011