Tuesday, August 2, 2011

Add a module to apache using apxs

To add mod_rewrite.c using apxs. Assuming the apache source file is located at /usr/src/apache/httpd-2.2.14

cd /usr/src/apache/httpd-2.2.14/modules/mappers/

/usr/local/apache/bin/apxs -i -a -c mod_rewrite.c



You will get the message module has been added. Restart apache.

Install mysql

Install mysql

yum list | grep mysql



Choose the mysql you need to install and do the following.

yum install mysql-package




Manual install using rpm:



Download rpms from here and install:

http://httpupdate.cpanel.net/mysqlinstall/

rpm -ivh package-name
Manual install by building from source:

wget http://mysql.he.net/Downloads/MySQL-5.1/mysql-5.1.33.tar.gz
tar xzvf mysql-5.1.33.tar.gz
cd mysql-5.1.33./configure --prefix=/usr/local/mysql
--with-extra-charsets=complex --enable-thread-safe-client
--enable-local-infile --enable-shared --with-plugins=innobase

make

make install

cd /usr/local/mysql
sudo ./bin/mysql_install_db --user=mysql
sudo chown -R mysql ./var

Start mysql

mysql -uroot

Nagios Installation

What You'll End Up With

If you follow these instructions, here's what you'll end up with:

* Nagios and the plugins will be installed underneath /usr/local/nagios
* Nagios will be configured to monitor a few aspects of your local system (CPU load, disk usage, etc.)
* The Nagios web interface will be accessible at http://localhost/nagios/

Prerequisites

During portions of the installation you'll need to have root access to your machine.

Make sure you've installed the following packages on your Fedora installation before continuing.

* Apache
* PHP
* GCC compiler
* GD development libraries

You can use yum to install these packages by running the following commands (as root):

yum install httpd php
yum install gcc glibc glibc-common
yum install gd gd-devel

1) Create Account Information

Become the root user.

su -l

Create a new nagios user account and give it a password.

/usr/sbin/useradd -m nagios
passwd nagios

Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.

/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache

2) Download Nagios and the Plugins

Create a directory for storing the downloads.

cd /usr/src

Download the source code tarballs of both Nagios and the Nagios plugins (visit http://www.nagios.org/download/ for links to the latest versions). These directions were tested with Nagios 3.1.1 and Nagios Plugins 1.4.11.

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz

3) Compile and Install Nagios

Extract the Nagios source code tarball.

cd /usr/src

tar xzf nagios-3.2.1.tar.gz
cd nagios-3.2.1

Run the Nagios configure script, passing the name of the group you created earlier like so:

./configure --with-command-group=nagcmd

Compile the Nagios source code.

make all

Install binaries, init script, sample config files and set permissions on the external command directory.

make install
make install-init
make install-config
make install-commandmode

Don't start Nagios yet - there's still more that needs to be done...

4) Customize Configuration

Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios. You'll need to make just one change before you proceed...

Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you'd like to use for receiving alerts.

vi /usr/local/nagios/etc/objects/contacts.cfg

5) Configure the Web Interface

Install the Nagios web config file in the Apache conf.d directory.

make install-webconf

Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account - you'll need it later.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Restart Apache to make the new settings take effect.

service httpd restart

Note Note: Consider implementing the ehanced CGI security measures described here to ensure that your web authentication credentials are not compromised.

6) Compile and Install the Nagios Plugins

Extract the Nagios plugins source code tarball.

cd /usr/src
tar xzf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11

Compile and install the plugins.

./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

7) Start Nagios

Add Nagios to the list of system services and have it automatically start when the system boots.

chkconfig --add nagios
chkconfig nagios on

Verify the sample Nagios configuration files.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If there are no errors, start Nagios.

service nagios start

8) Modify SELinux Settings

Fedora ships with SELinux (Security Enhanced Linux) installed and in Enforcing mode by default. This can result in "Internal Server Error" messages when you attempt to access the Nagios CGIs.

See if SELinux is in Enforcing mode.

getenforce

Put SELinux into Permissive mode.

setenforce 0

To make this change permanent, you'll have to modify the settings in /etc/selinux/config and reboot.

For information on running the Nagios CGIs under Enforcing mode with a targeted policy, visit the Nagios Support Portal or Nagios Community Wiki.

9) Login to the Web Interface

You should now be able to access the Nagios web interface at the URL below. You'll be prompted for the username (nagiosadmin) and password you specified earlier.

http://server_IP/nagios/



Configure nagios.

The main conf file for nagios is /usr/local/nagios/etc/nagios.cfg

When you take nagios in the browser after this freshinstall, you can see localhost added. The conf fle for this is /usr/local/nagios/etc/objects/localhost.cfg

This has been added to the file usr/local/nagios/etc/nagios.cfg as follows.

[root@localhost objects]# grep localhost.cfg /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

If you need to add another host copy this file in the another name and change the IP, hostname accordingly.

cp
/usr/local/nagios/etc/objects/localhost.cfg /usr/local/nagios/etc/objects/newserver.cfg

Include this cfg file to the nagios.cfg as follows.

cfg_file=/usr/local/nagios/etc/objects/newserver.cfg

Check nagios for errors.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If no error restart nagios

service nagios restart

Check in browser, if you can see the new server.

Lite speed configuration + PHP recompilation

Features of LiteSpeed WebServer

- Runs on almost all platforms like Linux, FreeBSD, Solaris, Mac OS X etc
- It is fully compatible with most of the common control panels like cPanel, Ensim, DirectAdmin, Plesk, etc.
- PHP scripting is up to 50% faster than Apache’s mod_php

1.Litespeed configuration

1.1 Check Litespeed

Take http://IP:7080/ on the browser, you will see a Litespeed welcome page.

Let us check if it is listening to the port we have mentioned.

# netstat -pant | grep lshttpd
tcp 0 192.168.1.19:7080 0.0.0.0:* LISTEN 18718/lshttpd
tcp 0 192.168.1.19:80 0.0.0.0:* LISTEN 18718/lshttpd

1.2 Admin Area

You can manage the admin area at

http://IP:7080/.

Here IP is your server IP

1.3 Log Files are resides under

log :: /usr/local/lsws/.

2. To Integrate with DA

LiteSpeed Web Server works very well with Directadmin managed web sites. The performance will increase up to 10x times by replacing apache with lsws.

To replace Apache with LSWS :-

2.1 Goto admin area

Access admin area at http://IP:7080 and with the admin username and password.

2.2 Goto Configurations >> Server >> General.

Keeping the cursor against the button along with each option will give you a small definition about the same.

2.3 Scroll down to “Using Apache Configuration File”

Load Apache Configuration => Yes
Auto Reload On Changes => Yes (Changes made in WHM/cPanel will be applied automatically)
Apache Configuration File => /usr/local/apache/conf/httpd.conf
Apache Port Offset => 1000 (Try LiteSpeed on port 1080 and 1443 first, change to 0 later)
Apache IP Offset => 0
PHP suEXEC => Yes (Run PHP in suEXEC mode)
PHP suEXEC Max Conn => 8 (The maximum PHP processor each account can have)

2.4 Scroll back up to “Index Files” and set it as follows:

Index Files index.html, index.php, index.php5, index.php4, index.htm
Auto Index Not Set
Auto Index URI Not Set

2.5 Scroll down to “HT Access”

Allow Override Check: Limit, Auth, FileInfo, Indexes, Options Uncheck: None
Access File Name .htaccess

2.6 Goto Configurations >> Server >> Listeners

delete all current listeners.

2.7 Now restart the webserver

service lsws restart

33 PHP recompilation

By default, Litespeed comes with PHP 4.4.x compiled with LSAPI and hence we have to install latest stable version of PHP with LSAPI for our LiteSpeed. With PHP LiteSpeed SAPI, LiteSpeed’s PHP performance is much more efficient than Apache’s mod_php or fast_CGI.

You can easily recompile PHP in the server from the Panel.

3.1 login to admin area.

http://IP:7080/.

3.2 Go to

Admin >> Actions >> Recompile PHP

3.3 Recompile PHP

Compile PHP with LSAPI

3.3.1 Step 1 : Select a PHP version

Here you can select PHP version. Select your desired PHP version and click next.

3.3.2 Step 2 : Choose PHP 5.2.9 Build Options

Here I have selected PHP 5.2.9

a. Load Configuration

- Use configuration from previous Build
- Restore default

b. Install Path Prefix - You can specify installation path

c. Configure Parameters - Configuration command

d. Security Patches Suhosin (General Hardening) Mail Header (Identifies Mail Source)

e. Install Opcode Cache None APC eAccelerator XCache

3.2.4 Click Build PHP

3.4 Here you will get a custom phpbuild command.

If you log in as root, you can directly run the command:

# /usr/local/lsws/phpbuild/buildphp_manual_run.sh

If you log in as a user who has sudo permission, you can run the command with sudo and input root password after prompt.

$ sudo /usr/local/lsws/phpbuild/buildphp_manual_run.sh

To apply changes, please visit Control Panel and execute a Graceful Restart. Apply Changes

Install Configuring Litespeed Webserver

1.1 Features of LiteSpeed WebServer

- Runs on almost all platforms like Linux, FreeBSD, Solaris, Mac OS X etc
- It is fully compatible with most of the common control panels like cPanel, Ensim, DirectAdmin, Plesk, etc.
- PHP scripting is up to 50% faster than Apache's mod_php
- supports CGI, Fast CGI, PHP, Servlet/JSP, Proxy, SSLv2/SSLv3/TLSv1, IPv4 and IPv6
- GZIP compression
- high performance .htaccess implementation, this alone can double the server capacity and reduce server load by 5-10 times against using apache.
- LDAP authentication
- Apache compatible URL rewrite engine
- MS FrontPage Server Extension
- Strictest HTTP request validation
- Deny any buffer-overrun attempt
- Secure against popular DoS attacks
- Chroot support
- Chroot and suexec CGI script
- supports FastCGI suEXEC for improved security
- Small memory footprint
- Thousands of concurrent connections
- Increase scalability of external web applications
- Efficient and high performing CGI daemon and Perl daemon
- SSL Hardware acceleration
- can recover from service failure instantly
- Migration from other webservers is quite quick and easy
- this can also act as a security guard in front of current webserver and hence improving performance, scalability and security.
- can perform up to 50% better during high loads when compared to httpd and lighttpd.
- PHP CGI/FCGI SAPI
- With PHP LiteSpeed SAPI, LiteSpeed's PHP performance is up to 100% better than Apache's mod_php.
- Ruby LSAPI is about 50% faster than Ruby FCGI for the simple "Hello, World" test.


2. Install LiteSpeed

# cd /usr/src


# wget http://litespeedtech.com/packages/3.0/lsws-3.1.1-std-i386-linux.tar.gz


# tar -xvzf lsws-3.1.1-std-i386-linux.tar.gz


# cd lsws-3.1.1


# ./install.sh



You will encounter few questions and need to select the following options:

* Do you agree with above license? Yes
* Destination [/opt/lsws]: /opt/lsws [ /usr/local/lsws can also be used]
* User name [admin]: admin
* Password: youradminpassword
* Retype password: youradminpassword
* User [nobody]: nobody [use a non-system user that doesn't have a shell access and home directory]
* Group [nobody]: nobody [group the webserver will be running as]
* HTTP port [8088]: 1080 [you can give any port you wish to run lsws. If any other webserver is running on this port, stop it before starting lsws]
* Admin HTTP port [7080]: 7080
* Both these ports should be enabled in the firewall
* Setup up PHP [Y/n]: Y
* Suffix for PHP script(comma separated list) [php]: php
* Would you like to change PHP opcode cache setting [y/N]? N
* Would you like to install AWStats Add-on module [y/N]? N
* Would you like to import Apache configuration [y/N]? N
* Would you like to have LiteSpeed Web Server started automatically when the machine restarts [Y/n]? Y
* Would you like to start it right now [Y/n]? Y


LiteSpeed Web Server started successfully! Have fun!


2.1 Check Litespeed

Take http://192.168.1.19:1080/ on the browser, you will see a Litespeed welcome page.

Let us check if it is listening to the port we have mentioned.

# netstat -pant | grep lshttpd
tcp 0 192.168.1.19:7080 0.0.0.0:* LISTEN 18718/lshttpd
tcp 0 192.168.1.19:80 0.0.0.0:* LISTEN 18718/lshttpd


2.2 Admin Area
You can manage the admin area at

http://192.168.1.19:7080/.


Here 192.168.1.19 is my local machine's ip.


2.3 Log Files
The log files are located at /opt/lsws/logs.


3. To Integrate with Cpanel
LiteSpeed Web Server works very well with cPanel managed web sites. The
performance will increase up to 10x times by replacing apache with lsws.


To replace Apache with LSWS :-
3.1 Goto admin area
Access admin area at http://192.168.1.19:7080 and with the admin username and password.


3.2 Goto Configurations >> Server >> General.
Keeping the cursor against the button along with each option will give you a small definition about the same.


3.3 Scroll down to "Using Apache Configuration File"

Load Apache Configuration => Yes
Auto Reload On Changes => Yes (Changes made in WHM/cPanel will be applied automatically)
Apache Configuration File => /usr/local/apache/conf/httpd.conf
Apache Port Offset => 1000 (Try LiteSpeed on port 1080 and 1443 first, change to 0 later)
Apache IP Offset => 0
PHP suEXEC => Yes (Run PHP in suEXEC mode)
PHP suEXEC Max Conn => 8 (The maximum PHP processor each account can have)


3.4 Scroll back up to "Index Files" and set it as follows:


Index Files index.html, index.php, index.php5, index.php4, index.htm
Auto Index Not Set
Auto Index URI Not Set




3.5 scroll down to "HT Access"


Allow Override Check: Limit, Auth, FileInfo, Indexes, Options Uncheck: None
Access File Name .htaccess




3.6 Goto Configurations >> Server >> Listeners
delete all current listeners.


3.7 Now restart the webserver

service lsws restart


4. PHP
By default, Litespeed comes with PHP 4.4.x compiled with LSAPI and hence we have to install latest stable version of PHP with LSAPI for our LiteSpeed. With PHP LiteSpeed SAPI, LiteSpeed's PHP performance is much more efficient than Apache's mod_php or fast_CGI.

# /opt/lsws/fcgi-bin/lsphp -v
PHP 4.4.7 (litespeed) (built: May 30 2007 05:16:33)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies



4.1 Download the latest stable PHP


# wget http://in2.php.net/distributions/php-5.2.3.tar.gz
# tar -zxf php-5.2.3.tar.gz
# cd php-5.2.3
# cd sapi



4.2 Download and expand latest LSAPI for PHP into the “sapi” folder:

# wget http://www.litespeedtech.com/packages/lsapi/php-litespeed-4.0.tgz
# tar -zxf php-litespeed-4.0.tgz


4.3 Change directory to php-5.2.3 and run commands:

# cd ..
# touch ac*
# ./buildconf --force


4.4 Configure/Compile PHP:

4.4.a # php -i | grep configure | sed "s/'//g" | sed "s/'//g"


4.4.b # Remove the "--with-apxs=/usr/local/apache/bin/apxs" part from 6.4.a

and add '--prefix=/php5' '--with-litespeed' '--with-config-file-path=../php'


# ./configure '--prefix=/php5' '--with-litespeed'

'--with-config-file-path=../php' --with-mysql ...[append the full options from

4.4.a]


# make


# make install



Note: You must compile PCRE (Perl Compatible Regular Expressions) support in
order for the default auto-index PHP script to work correctly (at least this
is true for 3.0RC2).


4.5 Replace the lsphp binary in /opt/lsws/fcgi-bin/lsphp with /php-5.2.3/sapi/litespeed/php:

# cd /opt/lsws/fcgi-bin/
# mv lsphp lsphp.old
# cp /php-5.2.3/sapi/litespeed/php lsphp


4.6 To check installation success:

# /opt/lsws/fcgi-bin/lsphp -v

PHP 5.2.3 (litespeed) (built: May 31 2007 14:05:12)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies



4.7 php.ini

The php.ini file will be located at /opt/lsws/php/php.ini

If we want to use the old PHP.ini just copy it here.

# cd /opt/lsws/php
# mv php.ini php.ini.old
# cp /usr/local/ZEND/etc/php.ini .



4.8 Restart Litespeed Webserver

Finally restart LSWS and use our new PHP binary.

/opt/lsws/bin/lswsctrl restart and thats it. You are done !!!


5. Limitations

This webserver comes as Standard version (which is free and it has several limitations) and it comes as an Enterprise version (which is more optimized and it doesn't have much limitations). Few drawbacks of free version are: the Maximum Concurrent Connections is limited to 150, it cannot utilize more than one processor etc. Hence, to utilize the full advantage of LSWS you have to purchase the Enterprise version.

6. Conclusion

We have installed LiteSpeed Webserver and integrated it to use with CPanel. Now the web pages will load fast. At the same time the server load and memory usage will be lower. More web sites can now be hosted on this server and we can feel the speed. In short, LiteSpeed is the best choice for shared hosting service providers in terms of performance, security and server capacity.

Go ahead, give LiteSpeed a try and discover why over 300,000 internet domains are currently powered by LSWS.


References:
http://litespeedtech.com/
http://en.wikipedia.org/wiki/LiteSpeed_Web_Server/
http://creativeflux.co.uk/entry/replacing-apache-with-litespeed/
http://www.usefuljaja.com/litespeed


Downloads:
http://www.php.net/downloads.php
http://www.litespeedtech.com/products/webserver/lsapi/
Categories for this entry

* Technical Bench » Software Installations - General
* Technical Bench » Webserver

Fuser command

fuser is a UNIX command used to show which processes are using a specified file, file system, or socket.

# To list the process numbers of local processes using the /etc/passwd file, enter:

fuser /etc/passwd

# To list the process numbers and user login names of processes using the /etc/filesystems file, enter:

fuser -u /etc/filesystems

# To terminate all of the processes using a given file system, enter:

fuser -k -x -u -c /dev/hd1

or

fuser -kxuc /home

List the content of a tar file

if You need to list the contents of a tar or tar.gz file on screen before extracting the all files.

List the contents of a tar file
$ tar -tvf file.tar

List the contents of a tar.gz file
$ tar -ztvf file.tar.gz

List the contents of a tar.bz2 file
$ tar -jtvf file.tar.bz2