MyTrueHost launched Web Hosting for Indian clients just in Rs 60/Month with various payment options(netbanking, debit card, credit card,cash card or paypal).
Please Visit at https://www.mytruehost.in

Installing XCache on Linux machines

XCache is a fast, stable PHP opcode cacher that has been tested and is now running on production servers under high load. It is supported on all of the latest PHP. It optimizes performance by removing the compilation time of PHP scripts by caching the compiled state of PHP scripts into the shm (RAM) and uses the compiled version straight from the RAM. This will increase the rate of page generation time by up to 5 times as it also optimizes many other aspects of php scripts and reduce server load.

To install follow the steps mentioned below.

1. Download and extract the source for XCache .

$ cd /usr/local/src/

$ wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz
$ tar -xzvf xcache-1.2.2.tar.g

Build, configure and install theXCache module.

$ cd xcache
$ phpize
$ ./configure –enable-xcache
$ make && make install

You can see a message like this . Note theextension directory.

Build complete.

Don’t forget torun ‘make test’.
Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20060613/

Now configure the php.ini file ( To find .ini file, use the command  `php -i | grep php.ini`)

 

$ cat xcache.ini >> /usr/local/Zend/etc/php.ini

Replace the following  line in php.ini with correct path ,which describes the Installed shared extensions that we noted above.

zend_extension = /usr/local/lib/php/extensions/non-debug-non-zts-xxx/xcache.so

It will become like this,Now configure the php.ini file ( To find .ini file, use the command  `php -i | grep php.ini` )

 

zend_extension =  /usr/local/lib/php/extensions/no-debug-non-zts-20060613/xcache.so

Restart apache and confirm theXcache  installation.

$ /etc/init.d/httpd restart
$php -v

 

 

PHP scripts giving 500 Internal Server Errors and apache error log shows FATAL: erealloc()”

“PHP scripts giving 500 Internal Server Errors and apache error log shows the error as follows:”

PROBLEM

FATAL:  erealloc():  Unable to allocate 37581 bytes
[Mon Apr 14 19:07:39 2008] [error] [client 125.17.242.245] Premature end
of script headers: /home/username/public_html/site/index.php


SOLUTION
 

The cause of the problem is because of the line “RLimitMEM 22369621” in httpd.conf file.commented out this line:# grep RLimitMEM /usr/local/apache/conf/httpd.conf#RLimitMEM

How to enable runkit PHP extension

Installing runkit PHP extension.

#cd /usr/local/src #wget http://pecl.php.net/get/runkit-0.9.tgz #tar -zxvf runkit-0.9.tgz #cd runkit-0.9 #phpize #./configure #make

After running the make command you will get the following error.

/usr/local/src/runkit-0.9/runkit_import.c: In function 'php_runkit_import_class_props': /usr/local/src/runkit-0.9/runkit_import.c:230: warning: passing argument 2 of 'zend_unmangle_property_name' makes integer from pointer without a cast /usr/local/src/runkit-0.9/runkit_import.c:230: error: too few arguments to function 'zend_unmangle_property_name' make: *** [runkit_import.lo] Error 1

Fix is as follows

Edit the file /usr/local/src/runkit-0.9/runkit_import.c and change the following line zend_unmangle_property_name(key, &cname, &pname); To: zend_unmangle_property_name(key, key_len, &cname, &pname);

Again continue with the installation steps.

#cd /usr/local/src/runkit-0.9 #make #make install

Edit the loaded PHP configuration file ( here /usr/local/lib/php.ini ) and add the following line.

extension=runkit.so

You can verify the runkit extension by

root@host[/usr/local/src/runkit-0.9]# php -i | grep -i runkit runkit runkit support => enabled

Php memory size exhausted error

If you are getting a php Fatal error like

Fatal error: Allowed memory size of 20971520 bytes exhausted at /usr/ports/lang/php5/work/php-5.2.1/Zend/zend_hash.c:1036 (tried to allocate 232 bytes) in /home2/webofunni/www/mediawiki-1.10.1/includes/SpecialPage.php on line 784

Then error is because of small memory limit in php. Try to increase php memory limit by following method .

1. Add following line to .htaccess

php_value memory_limit 32M

2. if that doesn’t work open php.ini and look for

memory_limit = XMwhere X is some number. Increase that number to higher value and try.

Here is a short explanation of memory_limit directive in php.ini

memory_limit integer ( default value 8M)

This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. In order to use this directive you must have enabled it at compile time. So, your configure line would have included: –enable-memory-limit. Note that you have to set it to -1 if you don’t want any limit for your memory
.

Compile Apache + Mysql + PHP

Install Apache(apache2.2.2)

1. Download apache2.2.2(httpd-2.2.2.tar.gz) store in /usr/local/src
2. Type the following to un-tar the file into a directory called apache_[version]: tar -xvf apache_[version].tar
3.  cd into /usr/local/apache_[version] (or wherever you un-tared it)
4. Type the following to prepare for building, replacing [path] with your own path, such as /usr/local/usr/local/apache_new
5. ./configure –prefix=[path] –enable-module=so
6. make
7. make install
8. Check if you have mod_so enabled:
* cd to the Apache bin directory (/usr/local/apache_new/bin/ or wherever you installed Apache originally)
* Type ./httpd -l
9. Open httpd.conf(/usr/local/apache_new/conf/) and find a line starting with ServerAdmin.
ServerAdmin admin@example.com
10. Find a line starting with ServerName:
ServerName server1.example.com:80
11. Save the file.
12. cd up a directory (type cd ..)
13. Start Apache using the following command:
# ./bin/apachectl start
14. Call the IP(192.168.1.5) or domain name(server1.example.com)from browser You will get a page “IT WORKS”

Install Mysql 4.1

Add a login user and group for mysqld to run:
# groupadd mysql
# useradd -g mysql mysql
# tar zxvf mysqlversion.tar.gz
# cd mysqlversion
# ./configure–prefix=/usr/local/mysql
# make
# make install
# cp support-files/my-medium.cnf /etc/my.cnf
# cd /usr/local/mysql

If you haven’t installed  mysql before, you must create the mysql grant tables:
#bin/mysql_install_db –user=mysql
(If you run the command as root, you should use the –user option. The value of the option should be the name of the login account that you have created in the first step to use for runnning the server)

#cd /usr/local/mysql
#chown -R root .
#chown -R mysql var
#chgrp -R mysql .

Install PHP(PHP4.4.2)

Unpack a source archive
# tar -zxvf php-4.3.3.tar.gz

Configure PHP as Apache module with MySQL support
#./configure –with-apxs2=/usr/local/apache/bin/apxs –with-mysql=/usr/local/mysql

Compile the sources
# make

Install the compiled Apache module
# make install

Copy php.ini-dist to /usr/local/lib/php.ini
# cp ./php.ini-dist /usr/local/lib/php.ini

Integrate PHP with Apache

Open httpd.conf(/usr/local/apache_new/conf) open in your text editor

AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

Save the file, go up a directory (cd ..), and stop and restart Apache by typing:

./bin/apachectl stop Followed by ./bin/apachectl start

Find the document root from httpd.conf(/usr/local/apache_new/conf) file
DocumentRoot “/usr/local/apache_new/htdocs”

Configuring Websites

Edit /usr/local/apache2/conf/httpd.conf and make sure it has the
correct document root settings :: /var/www/
(change the defautlt documetroot in config file (#DocumentRoot “/usr/local/apachenew/htdocs”) to /var/www/ and also change the the ‘directory’ directive(#<Directory “/usr/local/apachenew/htdocs”) to /var/www/(search for the DocumentRoot and change))

Un-comment the following options …
-> Include conf/extra/httpd-vhosts.conf
-> Include conf/extra/httpd-default.conf

Then edit the v-hosts file(conf/extra/httpd-vhosts.conf) and setup a couple of dummy sites just to make sure everything is working as it should(Comment out all the default VirtualHost entries inside this file)

NameVirtualHost ServerIP:80

<VirtualHost ServerIP:80>
DocumentRoot /var/www/test1/
ServerName test1.com
</VirtualHost>

<VirtualHost ServerIP:80>
DocumentRoot /var/www/test2/
ServerName test2.com
</VirtualHost>

Create the two directories in /var/www/ and place a index.html file in  each, with some domain specific text in, so we can differentiate between the two when testing.

Launch Apache
# /usr/local/apache2/bin/apachectl start

Check the two sites

Install php5 and php4 in cPanel server

Now php has flushed their support for php4. Now most of the sites are loading under php5. But traditional php sites won’t work under php5. So we have to have php5 as primary and php4 as secondary php. Previously it was php4 as default and php5 as secondary, but now it is in the other way round.

Options to be added while configuring

 

1. Make sure that you are not using with-apxs option, as this would break existing php.

Install php5 and php4 in cpanel server. 2.Make sure you have the following prefixes and suffixes to install to the proper directories, otherwise currently installed php could be broken. --prefix=/usr/local/php4 --exec-prefix=/usr/local/php4 --program-suffix=4 3.Add the necessary options for proper CGI redirects from Apache: --enable-force-cgi-redirect --enable-discard-path An example configuration option would be ./configure --prefix=/usr/local/php4 --exec-prefix=/usr/local/php4 --program-suffix=4 --with-xml --with-gd --enable-exif --enable-mbstring --with-freetype-dir=/usr --enable-versioning --with-zlib --enable-force-cgi-redirect --enable-discard-path make make install

 

Integrating php4 with cpanel/cgi-sys

 

cp -f /usr/local/php4/bin/php4 /usr/local/cpanel/cgi-sys/php4 chown root:wheel /usr/local/cpanel/cgi-sys/php4 cp /usr/local/Zend/etc/php.ini /usr/local/php4/lib/php.ini Make sure that you add the following line to the php4 php.ini file. Make sure that you can't add this line if you are using a common php.ini file. cgi.fix_pathinfo = 1  ; needed for CGI/FastCGI mode

 

Integrating php4 in apache configuration

 

1. Add index.php4 entry in DirectoryIndex 2. Add the following entries after the AddType entry of default php5. These would make apache understand all .php4 files to execute as php4 Action application/x-httpd-php4 "/cgi-sys/php4" AddHandler application/x-httpd-php4 .php4 3.service httpd configtest 4. If there is no error in previous step service httpd stop service httpd startssl 5. put a info.php4 with the following contents in document root <? phpinfo(); ?> 6. Check the page whether it is showing php4 details

Install mod perl as DSO module

There are different ways to install mod_perl. This article explains how to install it as DSO using Apache extension tool apxs.

1) Download and untar the source.

$ cd /usr/local/src
$ wget http://perl.apache.org/dist/mod_perl-1.0-current.tar.gz
$ tar -xzf mod_perl-1.0-current.tar.gz
$ cd mod_perl-1.29/

2) Configure it as DSO

$ perl Makefile.PL USE_APXS=1 WITH_APXS=/usr/local/apache/bin/apxs EVERYTHING=1
$ make
$ make test
$ make install

3) Restart httpd

$ /usr/local/apache/bin/apachectl configtest
$ /usr/local/apache/bin/apachectl restart

You may use the above procedure for installing mod_perl as DSO module in Cpanel server running Apache 1.3.x. You may test the mod perl installed by adding the following configuration directives in httpd.conf.

# mod_perl scripts will be called from
Alias /perl /home/<user>/public_html/perl
PerlModule Apache::Registry

<Location /perl>
AllowOverride All
SetHandler perl-script
PerlHandler Apache::Registry
Options ExecCGI
PerlSendHeader On
Allow from all
Options +FollowSymLinks
</Location>

You may put the above entry anywhere in httpd.conf.  And, here are two sample files for testing.

test1.pl

 use strict;
my $r = shift;
$r->send_http_header(‘text/html’);
$r->print(“It worked!!!\n”);

test2.pl

my $r = Apache->request;
$r->send_http_header(‘text/plain’);
$r->print(“mod_perl rules!\n”);


Those files must have 755 permission.

Install mod evasive

Download mod_evasive from

http://www.nuclearelephant.com/projects/mod_evasive/

$ tar zxvf  mod_evasive_1.10.1.tar.gz
$ cd mod_evasive

Compile mod_evasive apache module

For Apache 2
$ /usr/local/apache/bin/apxs -i -a -c mod_evasive20.cFor Apache 1.3
$ /usr/local/apache/bin/apxs -i -a -c mod_evasive.c

Compilation is done under the assumption that path to apache is /usr/local/apache. If not replace /usr/local/apache with your path to apache.

Edit your httpd.conf [usually located in /usr/local/apache/conf/httpd.conf] and add

DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10
DOSEmailNotify someuser@somedomain.com

The values set for the above parameters seems to work well for most cases. You may want to experiment with the values set and fine tune them.

Caution: Although mod_evasive can be quite effective in some cases, in others it can cause more problems by blocking legitimate IPs.

Configure Apache to listen multiple ports

The listen directive in the Apache configuration file can be used to make Apache to listen in a particular port or IP address or port combination.

Listen 80
Listen 8000

In this format the Apache server listens on the given ports on all interfaces (IP addresses) which are up in the server. If you mention the above two directives in the Apache configuration file then the Apache server will listen on both the ports 80 and 8000. Multiple Listen directives may be used to specify a number of addresses and ports to listen to.

Listen IP:80

You need to replace the IP address in this example with the IP address you want the Apache service to listen. In this format an IP address is given as well as a port. In this case the server will listen on the given port and interface( IP address ). If you want the Apache service to listen on two IP addresses in the server you can use multiple listen directive in the configuration file.

Listen IP1:80
Listen IP2:80

Please remember to restart the Apache service in the server once the changes are made to the configuration file.

How to install APC (Alternative PHP Cache)

APC gives our server a huge performance boost. It is a free and robust framework for caching and optimizing PHP intermediate code.

The installation steps are given below :

1. Login to the server as root
2. Download APC. You will get the latest tar file from the site http://pecl.php.net/package/apc 

     wget http://pecl.php.net/get/APC-3.0.14.tgz

3. Extract and move into the directory

    tar -xzvf APC-3.0.14.tgz
cd APC-3.0.14

4. Locate the location of phpize

    whereis phpize

It should look like:

    phpize: /usr/bin/phpize

5. Run the same whereis command for php-config and apxs. Next type:

    /usr/bin/phpize

6. Compile APC

    ./configure –enable-apc –enable-apc-mmap –with-apxs –with-php-config=/usr/local/bin/php-config
make
make install

The “make install” command will return the location of the apc.so extension. Note down the location as we need it later.

7. Install APC into php.ini. For that we need to edit php.ini and add the APC extension.

          vi /usr/local/lib/php.ini

Add the following lines in php.ini

       extension_dir = /usr/local/lib/php/extensions/no-debug-non-zts-20060613 (We have already note this down after the                                                                                                                                                                             installation)
extension=apc.so
apc.enabled=1
apc.shm_segments=1
apc.shm_size=128
apc.ttl=300
apc.user_ttl=300
apc.num_files_hint=1024
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.enable_cli=1
apc.stat = 1
apc.rfc1867=1
apc.rfc1867_prefix=”upload_”
apc.rfc1867_name=”APC_UPLOAD_PROGRESS”
apc.rfc1867_freq=”100k”

8. Restart Apache

        service httpd restart

You can check whether APC is successfully installed by checking the phpinfo page.