Search This Blog

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Wednesday, June 10, 2009

Install Configure Apache Localhost Perl on Linux Ubuntu

This article teaches those who want to run Perl scripts from browser on Ubuntu Linux with Apache HTTP Server.

1. First, you need to install apache2 by executing the following command from the terminal:

sudo apt-get install apache2

2. Now you can install mod_perl by executing the following command from the terminal:

apt-get install libapache2-mod-perl2

3. If you know how to set up a local server directory to let files like example.html running from browser like http://localhost/example.html or you previously installed LAMP, then you can read on, if not, please read this article first before continue.

4. Now you may need to edit Apache Configuration file in order to tell Apache Perl where your .pl script is located, so that the server can execute it as Perl script. So let’s say if you put your Perl script example.pl inside a folder located at your defined local server directory for instance /home/shi/Documents/Host/perl/example.pl, you need to open apache2.conf:

sudo gedit /etc/apache2/apache2.conf

add in the code:
view source
print?
01.Alias /perl/ /home/shi/Documents/Host/perl/
02.
03.PerlModule ModPerl::Registry
04.
05.
06. SetHandler perl-script
07. PerlHandler ModPerl::Registry
08. #PerlHandler ModPerl::PerlRun
09. Options +ExecCGI
10. #PerlSendHeader On
11.

(change the line /home/shi/Documents/Host/perl/ to your server directory name)

And now restart your server by running the following command in terminal:

sudo /etc/init.d/apache2 restart

Now write a test.pl file with the test script below:

#!/usr/bin/perl
use CGI;
my $query= new CGI;
print $query->header;
print "hello people in my head\n";

set the test.pl file permission to 755 and put it in your local server directory and type the url path in the browser and you should see the message: ‘hello people in my head’.

Monday, June 8, 2009

How to install memcached and php memcache on linux server

memcached is a high-performance memory object caching system intended to speed up dynamic web applications by alleviating database load.

memcached is meant to work in concert with something like the MySQL query cache, not replace it. The two implementations excel at vastly different things: memcached is an object cache, while MySQL provides a query cache.

memcached is extremely fast. It uses libevent, which provides a mechanism to execute a callback function when a specific event occurs on a file descriptor, to scale to any number of open connections. On a modern Linux system memcached utilizes epoll, is completely non-blocking for network I/O, ensures memory never gets fragmented, and uses its own slab allocator and hash table to achieve 0(1) virtual memory allocation.

How it install it on Linux server ?

  • Install dependency software (Libevent)
#curl -O http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz
#tar -xzvf libevent-1.4.9-stable.tar.gz
#cd libevent*
#./configure
#make
#make install

  • Now let’s download the newest Memcached source

#curl -O http://www.danga.com/memcached/dist/memcached-1.3.0.tar.gz
#tar zxf memcached-1.3.0.tar.gz
#cd memcached-1.3.0
#./configure
#make
#make install
  • Then add /usr/local/lib to LD_LIBRARY_PATH in your .bash_profile

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH

How it Works

First, you start up the memcached daemon on as many spare machines as you have. The daemon has no configuration file, just a few command line options, only 3 or 4 of which you’ll likely use:

Run Memcached as a daemon (d = daemon, m = memory, u = user, l = IP to listen to, p = port)

#memcached -d -m 1024 -u root -l 127.0.0.1 -p 11211 –u nobody

This starts memcached as a daemon (-d) on the IP address and port specified with -l and -p, respectively, running as the user nobody (-u), allocating 1024 for object storage (-m). You should adjust the amount of storage to suit your needs; many memcached installs run with 4 GB. Once you are comfortable with your startup options, add the appropriate command to your startup scripts.

Create a /etc/init.d/memcached file and add above line to start memcached when the server boots

With memcached installed and running, it’s time to get PHP talking to the object cache. While multiple PHP API exists, the one in the PECL repository is recommended. If you are running a newer version of PHP, installation is as simple as:

# pecl install memcache

Or you can use following steps to install PECL memcache manually.

#cd /usr/local/src
#curl -O http://pecl.php.net/get/memcache
#tar zxvf memcache*
#cd memcache-*
#phpize
#./configure
#make && make install

Now we have to make sure PHP loads the newly built memcache.so library by adding the following line to php.ini:

extension=memcache.so

Now restart Apache:

Service httpd restart

Once it sucussfully install you can create phpinfo() on your webserver should now confirm that memcache is installed.

memcache How to install memcache on linux server?