Life of a Geek Admin

The Daily adventures of a true geek administrator

Life of a Geek Admin - The Daily adventures of a true geek administrator

Install Tomcat 7 and Java 1.7 on CentOS 6 RHEL 6

In this post we will cover how to install the Apache Tomcat 7 and jre 1.7 on CentOS 6 and RHEL 6. This process doesn’t use the rpm’s from the Redhat repositories, but uses the latest tar balls from Apache and Oracle. We will also be using service accounts to control Tomcat and its processes.

Download latest Tomcat from http://tomcat.apache.org/download-70.cgi. Version 7.0.40 is the curent version at the time of this post.
Download the latest Java 1.7 jdk from http://www.oracle.com/technetwork/java/javase/downloads/index.html, click on the JDK download buton. You will want jdk-7u21-linux-x64.tar.gz tarball.
Copy the downloaded tarballs to /tmp directory on your server.

Change directory to /opt or the directory of your choice on the server. I am using /opt for this post to contain Java and Tomcat.

$ cd /opt

Make the tomcat directory and change to it.

$ mkdir tomcat
$ cd tomcat

This step is optional to create individual instances by name for tomcat. Doing this allows you to run multiple instances of tomcat on a server. For this example tomcat-inst1 is what we will be using.

$ mkdir tomcat-inst1
$ cd tomcat-inst1

untar Tomcat in the instance you will be running.

$ tar -xvzf /tmp/apache-tomcat-7.0.40.tar.gz

Create a symlink called tomcat-current. This will allow you to untar newer versions of Tomcat and juwst update the symlink.

$ ln -sf apache-tomcat-7.0.40 tomcat-current

Create tomcat service account and set the UID to 520

$ useradd -u 520 -c “Tomcat Service Account” -d /opt/tomcat -m -s /bin/bash tomcat

 

Change ownership of the tomcat directory to the tomcat user.

$ cd /opt
$ chown -R tomcat:tomcat tomcat

Create an init.d script to start the Tomcat instance at reboot. There is not one available when using Apache supplied tarball install. Copy the below code and save as tomcat-inst1 in /etc/init.d directory, modify the instance name variable.

#!/bin/bash
#
# Startup script for the Tomcat 7.0 Servlet/JSP Container
#
# chkconfig: 345 98 02
# description: Tomcat is the servlet container that is used in the
#              official Reference Implementation for the Java Servlet
#              and JavaServer Pages technologies.

# Source function library.
. /etc/rc.d/init.d/functions

INSTANCE=tomcat-inst1
export INSTANCE
CATALINA_HOME=/app/tomcat/${INSTANCE}/tomcat-current

# Source configuration.
[ -f /etc/sysconfig/${INSTANCE} ] && . /etc/sysconfig/${INSTANCE}

RETVAL=0


start() {
    if [ -f /var/run/${INSTANCE}_restart ]
        then
        /bin/rm /var/run/${INSTANCE}_restart
    fi
    echo -n $"Starting $prog: "

    if [ ! -f /var/lock/subsys/${INSTANCE} ]; then
        
            su - tomcat -c "INST_NAME=${INSTANCE} $CATALINA_HOME/bin/startup.sh"
        

        if [ $RETVAL = 0 ]; then
            success $"$prog startup"
            touch /var/lock/subsys/${INSTANCE}
        else
            failure $"$prog startup"
        fi
    fi

    echo
    return $RETVAL
}

stop() {
    /bin/touch /var/run/${INSTANCE}_restart
    echo -n $"Stopping $prog: "

    if [ -f /var/lock/subsys/${INSTANCE} ]; then
        su - tomcat -c "$CATALINA_HOME/bin/shutdown.sh -force"

        if [ $RETVAL = 0 ]; then
            success $"$prog shutdown"
            rm -f /var/lock/subsys/${INSTANCE}
        else
            failure $"$prog shutdown"
        fi
    fi

    echo
    return $RETVAL
}

stopforce() {
    /bin/touch /var/run/${INSTANCE}_restart
    echo -n $"Forcefully Stopping $prog: "

    if [ -f /var/lock/subsys/${INSTANCE} ]; then
        su - tomcat -c "$CATALINA_HOME/bin/shutdown.sh -force"

        if [ $RETVAL = 0 ]; then
            success $"$prog shutdown"
            rm -f /var/lock/subsys/${INSTANCE}
        else
            failure $"$prog shutdown"
        fi
    fi

    echo
    return $RETVAL
}

status() {
    local base=${1##*/}
    if [ -f /var/lock/subsys/${base} ]; then
        echo $"${base} is running..."
        return 0
    else
        echo $"${base} is stopped."
        return 3
    fi
}

getpid() {
        tomcatpid=`ps auwwwx | grep -v grep |grep -i /${INSTANCE}/ | awk '{print $2}'`
        echo "The PID for ${INSTANCE} is ${tomcatpid}."
        echo
}

threaddump() {
        getpid
        kill -3 ${tomcatpid}
        echo "Thread dump has been sent to where stdout is logged."
        echo
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  stopforce)
        stopforce
        ;;
  status)
        status ${INSTANCE}
        ;;
  restart|reload)
        stopforce
        start
        ;;
  condrestart)
        if [ -f /var/lock/subsys/${INSTANCE} ] ; then
                stop
                start
        fi
        ;;
  getpid)
        getpid
        ;;
  threaddump)
        threaddump
        ;;
  *)
        echo $"Usage: $prog {start|stop|stopforce|restart|condrestart|reload|status|getpid|threaddump}"
        exit 1
esac

exit $RETVAL

Make the following changes
# Source function library.
. /etc/rc.d/init.d/functions

INSTANCE=tomcat-inst1
export INSTANCE
CATALINA_HOME=/app/tomcat/${INSTANCE}/tomcat-current

Set init script to run at startup.

$ chkconfig --levels 345 tomcat-inst1 on

Setup Java jdk 1.7

$ cd /opt
$ mkdir java
$ cd java

Untar the tarball

$ tar -xzvf /tmp/jdk-7u21-linux-x64.tar.gz

Create the symlink

$ ln -sf jdk1.7.0_21 current

Create setenv.sh in /opt/tomcat/tomcat-inst1/tomcat-current/bin/ . In this exaple there is a ENV_LEVEL which you can omit the two lines or use them. This is for maintaining different developement levels set to correct environment (DEV, INT, CERT, PROD) if you want to use them.

#Java Home for this Tomcat Instance
JAVA_HOME=/app/java/current

#Set Java Options (Memory minimum/maximum?
JAVA_OPTS="-server -Xms1024m -Xmx1024m"

#Modify umask so that group has r+w
umask 02
CATALINA_PID=${CATALINA_HOME}/bin/catalina.pid

ENV_LEVEL=DEV
export ENV_LEVEL

$ chmod 755 setenv.sh
$ chown tomcat:tomcat setenv.sh

Modify tomcat-users.xml to set password and roles access.

$ cd /opt/tomcat/tomcat-inst1/tomcat-current/conf

Make a backup of the current file.

$ mv tomcat-users.xml tomcat-users.xml.orig

Create a new file with the following contents and set the passwords to your liking.

$ vi tomcat_users.xml

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="manager-gui"/>
  <role rolename="tomcat"/>
  <role rolename="admin"/>
  <user username="manager" password="tommgr" roles="manager-gui,admin"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
</tomcat-users>

chmod 600 tomcat-users.xml
chown tomcat:tomcat tomcat-users.xml

Now we can start Tomcat up and should be working.

Install Tomcat 7 on Windows 7

In continuing with building a testing environment on Windows 7 / Windows 2008 R2 I have embarked on installing Apache Tomcat 7 on my Windows 7 desktop. First download 32 or 64 bit from http://tomcat.apache.org/download-70.cgi/tomcat-7.0-doc/tomcat-7.0-doc/taglibs/migration.html.You will find the download links in the binary distributions section of the page. You will also need to make sure you have Jave jdk installed.

My current setup is 32 bit running Apache 2.2.22 with PHP 5.4.0, so I am going with apache-tomcat-7.0.28-windows-x86.zip. Once the download is completed, just extract the zip file to the directory of your choosing. For this example I have chosen c:\apps\apache-tomcat-7.0.28.

Configure Tomcat

Now we to set a few properties for Tomcat to know where the JDK is installed. We do this by creating the setenv script file. Since we are running 32 bit windows instance, it is best to use a 32 bit instance of the JDK. Open your favorite text editor and create a file called setenv.bat with the following contents:

set "JRE_HOME=%ProgramFiles(x86)%\Java\jre6"
exit /b 0

Save the file to c:\apps\apache-tomcat-7.0.28\bin. That’s all you have to do with the bat file. The catalina.bat file will look for and execute it if it finds the file.

Setting up the Windows Service

Now we need to setup Tomcat to run as a service. Open a command prompt us9ing Run as Administrator option and change into the directory you extracted Tomcat to.

cd C:\apps\apache-tomcat-7.0.28\bin

Run setenv.bat that you just created to set JRE_HOME variable and run service.bat script with the following syntax.

Usage: service.bat install/remove [service_name] [/user username]

service.bat install Tomcat7

The service will now appear in Service as Apache Tomcat [your name] and set as Manual.

At this point you can start the service as well as change it to Automatic. Open a browser and type in http://localhost:8080 and you should be greeted with the standard Tomcat page.

You should now have a working installation of Tomcat 7 on your Windows 7 / Windows 2008 R2 system. Next step is to set the username and password for accessing Tomcat Manager app. By default this is commented out in the %TOMCAT_FOLDER%/conf/tomcat-users.xml file. Open the file with a text editor an un-comment the section in tomcat-users.
<role rolename=”tomcat”/>
<role rolename=”role1″/>
<user username=”tomcat” password=”tomcat” roles=”tomcat”/>
<user username=”both” password=”tomcat” roles=”tomcat,role1″/>
<user username=”role1″ password=”tomcat” roles=”role1″/>
</tomcat-users>

Using this configuration will not allow to access the manager and host information. You will also need to add the manager-gui and admin-gui role to access the status and other functions. So you could change the tomcat-users.xml to look like.

<tomcat-users>
<role rolename=”manager-gui”/>
<role rolename=”admin-gui”/>
<user username=”manager” password=”tomcat” roles=”manager-gui,admin-gui”/>
</tomcat-users>

Save this and restart the Tomcat service and you should now be able to access those screens.  Make sure to use stronger passwords than the defaults.

 

Enabling Server Status on Apache 2.2

Apache 2 has a nice feature to allow a server admin to view the performance of Apache. When mod_status module is enabled an HTML page will be presented to allow stats to be presented in a readable format in which refresh can be set.

Server status details:

  • The number of worker serving requests
  • The number of idle worker
  • The status of each worker, the number of requests that worker has performed and the total number of bytes served by the worker (*)
  • A total number of accesses and byte count served (*)
  • The time the server was started/restarted and the time it has been running for
  • Averages giving the number of requests per second, the number of bytes served per second and the average number of bytes per request (*)
  • The current percentage CPU used by each worker and in total by Apache (*)
  • The current hosts and requests being processed (*)

 

Enabling the module is easy and can be done on Apache running on Windows and other Unix / Linux systems. First lets open the Apache configuration file httpd.conf.

Find the LoadModule line

LoadModule status_module modules/mod_status.so

and un-comment or add it. Next we need to add the ExtendedStatus variable and set it to On, the default setting is Off.

Note: This setting applies to the entire server, and cannot be enabled or disabled on a virtualhost-by-virtualhost basis. The collection of extended status information can slow down the server.
Add

ExtendedStatus On

Now we need to add the server-status site to Apache. You can create a virtual host for the server object and store it in the conf.d or you can just add it to the httpd.conf, the choice is yours.

Save the httpd.conf file and restart Apache, make sure to test the config changes before restarting. Open a browser and  open http://servername/server-status and you should be directed to Apache Server status page.

As you can see there is plenty of good information on the performance of the server as well as another problem determination tool.

Automatic Updates
You can get the status page to update itself automatically if you have a browser that supports “refresh”. Access the page http://your.server.name/server-status?refresh=N to refresh the page every N seconds.

Display Machine Readable Status File
A machine-readable version of the status file is available by accessing the page http://your.server.name/server-status?auto. This is useful when automatically run, see the Perl program in the /support directory of Apache, log_server_status.

Running ASP.NET on Apache 2.2

Continuing with running Apache 2.x on Windows systems (Windows 7 and Windows 2008 R2) I found the desire to be able to deliver ASPX pages on the Windows server in my development environment. Upon searching the Internet I came across an Apache module mod_aspdotnet.so found here. The module is no longer being actively updated but works well on Apache 2.0 – 2.2 installations.

This implementation is limited  and true ASP hosting should be done with IIS, but no one said we couldn’t have a try at it!

Download mod_aspdotnet-2.2.0.2006-setup-r2.msi but do not double click to run the installation. Instead we need to extract the contents to a temporary directory and will manually copy Apache.Web.dll and mod_aspdotnet.so to the correct directory’s. The reason is that double-clicking will not put the Apache.Web.dll file in the correct location and will register with the GlobalAssemblyCache.

Open a command prompt and change to the directory where you downloaded the file to and run the command.

msiexec /a  /qb TARGETDIR=

Example:

msiexec /a mod_aspdotnet-2.2.0.2006-setup-r2.msi /qb TARGETDIR=c:\temp

The files will be extracted into

First, copy mod_aspdotnet.so to your Apache modules directory c:\Apache2\modules next copy Apache.Web.dll to the c:\apache2\bin, assuming this is where you have installed Apache.

Modify Apache’s httpd.conf file and add this section to the end of the file.

# asp.net support
LoadModule aspdotnet_module modules/mod_aspdotnet.so

AddHandler asp.net asax ascx ashx asmx aspx axd config cs csproj \
licx rem resources resx soap vb vbproj vsdisco webinfo

AliasMatch "^/(?i)aspnet_client/system_web/(\d+)_(\d+)_(\d+)_(\d+)/(.*)" \
"C:/Windows/Microsoft.NET/Framework/v$1.$2.$3/ASP.NETClientFiles/$4"


Options FollowSymlinks
Order allow,deny
Allow from all

# Create Temporary ASP.NET Files directory under .NET framework 2.0.
AspNetMount /asp "C:/apache2/htdocs/asp"
Alias /asp "C:/apache2/htdocs/asp"

# Allow asp.net scripts to be executed

Options FollowSymlinks Indexes
AspNet Files
Order allow,deny
Allow from all
DirectoryIndex default.htm default.aspx

Save the changes and restart Apache service, hopefully the service will restart without errors. Now we need to test the setup, in the Directory directive I have created a test asp site.

Open your editor of choice and paste in the following code. This will display the .NET version.

<%@ Page Language="VB" %>








Save the file as default.aspx in the c:\apache2\asp\ directory.

Hope this works for you as it did for me. This will only work on Apache 2.0 / 2.2.

Install mod_perl on Apache 2.2 on Windows 7

To continue on with developing on Windows using Apache/MySQL/PHP I wanted to add mod_perl to the mix. For this post I chose to make it work on Apache 2.2 but it could possibly work on Apache 2.4 as well, but I have not tested they portion yet.

First piece of the puzzle is to download a version of Perl that supports the Module on Apache. In the past I have gone with ActiveState’s ActivePerl but lately I have been using Strawberry Perl due to changes in retrieving older releases.I settled on Perl 5.10 release.

Download Strawberry Perl 5.10.5 from http://strawberryperl.com/releases.html and click on strawberry-perl-5.10.1.5.msi under the Strawberry Perl May 2011 section.
Once downloaded just double-click to install it, you can change the default installation path or change it to your preference. Once the installation is completed then, open a command prompt to set the perl environment and reboot the system.

c:\> cd C:\strawberry

Run the command

c:\strawberry> perl\bin\perl.exe update_env.pl.bat

Next download and compile the mod_perl using ppm (Perl Package Manager)

ppm install http://cpan.uwinnipeg.ca/PPMPackages/10xx/mod_perl.ppd

The installation process will start. Once it compiles the module it will ask where to put it. This will be your Apache modules directory (ex:c:/Apache2/modules)

Close the command prompt and edit c:\Apache2\conf\httpd.conf
We must tell Apache to load the module and tell it where the perl Dll lives. You can add this to the bottom of the file.

LoadModule perl_module modules/mod_perl.so
LoadFile "C:/strawberry/perl/bin/perl510.dll"

Find the mime section and modify this

AddHandler cgi-script .cgi .plx .plex .pl

Now we need to enable and add a few items to allow perl to execute.

Look for the alias_module section and make sure the cgi-bin line is pointed to the correct location.

ScriptAlias /cgi-bin/ "c:/Apache2/cgi-bin/"

Next you will need to add ExecCGI in the Option section.

Options Indexes FollowSymLinks ExecCGI

Save the changes and restart Apache service. We are now ready to test to see if it displays a simple Perl Hello script.

You can copy the code and save it as test.pl in c:\apache2\htdocs or anther directory of your preference.

#!c:\strawberry\perl\bin\perl.exe
# ^^^ this must be the first line of the script! ^^^
# start code

use strict;
use CGI;
my $q = new CGI;

# print header and start the markup output

print $q->header( "text/html" ),$q->start_html( "hello from perl cgi!" );
print $q->h2("Hello Mark...");
print $q->end_html;
# end code

I hope this helps get Perl working in your Windows Apache install.

Install WordPress on Apache 2.4 on Windows

In following along with a previous post on installing Apache 2.4 PHP 5.4 and MySQL 5.5.21 on Windows, I will explain how to install WordPress 3.3.1. The installation is very easy to accomplish.

First download the latest version of WordPress from here, which at the time of this post it is 3.3.1. Next you will need to unzip the file to c:\apache24\htdocs\ on your system.

Next step is to create an empty database. To accomplish this task open a command prompt.Login to mysql and create the DB (wordpress) and create the user account and grant access.

$ mysql -u root -p
mysql> CREATE DATABASE `wordpress` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> CREATE USER 'wpadmin'@'localhost' IDENTIFIED BY 'P$ssw0rd!';
mysql> CREATE USER 'wpadmin'@'%' IDENTIFIED BY 'P$ssw0rd!';
mysql> GRANT ALL ON `wordpress` . * TO 'wpadmin>'@'localhost';
mysql> GRANT ALL ON `wordpress` . * TO 'wpadmin'@'%';
mysql> exit

Close the command prompt open Windows Explorer and open C:\Apache24\htdocs\wordpress\wp-config-sample.php with a text editor of your choice.  Find the following lines and change the database name to wordpress and your username and password for , which by default is root with no password.

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘wordpress’);

/** MySQL database username */
define(‘DB_USER’, ‘wpadmin’);

/** MySQL database password */
define(‘DB_PASSWORD’,  'P$ssw0rd');

/** MySQL hostname */
define(‘DB_HOST’, ‘localhost’);

Save the file as wp-config.php.

Open your Internet browser and type in http://localhost/wordpress/wp-admin/install.php and everything from there should run smoothly to complete the installation.

How install Apache 2.4 PHP 5.4 and MySQL 5.5.21 on Windows 7

Recently decided to install a working Apache 2.4 / PHP 5.4.9 and MySQL 5.5 running locally on my Windows 7 laptop for web design, not using XAMPP or WAMP installation methods. Which are great but this round I wanted to match my Linux server.

Apache 2.4 Install

First download Apache 2.4 from http://www.apachelounge.com/download/ (httpd-2.4.1-win32.zip) Apache 2.4.1
with IPv6 apr-1.4.6 apr-util-1.4.1 apr-iconv-1.2.1 pcre-8.21 lua-5.1 libxml2-2.7.8 openssl-1.0.0g zlib-1.2.6. This release is supported by the PHP 5.4 install from windows.php.net for Apache 2.4.

Extract the zip and copy it to the root of C:\. This will be C:\Apache24 when it is all done.

Update 01-17-2013: The version of the php5apache2_4.dll must match the version of PHP you are installing. The link that was reference before has been changed and moved to http://www.apachelounge.com/download/additional/ for versions 5.4.9 and earlier. As of PHP 5.4.10 the module is now included in the Windows build.

PHP 5.4.9 and Earlier

Download PHP 5.4.9 VC9 x86 Thread Safe from http://windows.php.net/download/releases/archives/php-5.4.9-Win32-VC9-x86.zip . Extract and rename folder to php and move to C:\
Also, download php5apache2_4.dll-php-5.4-win32.zip (http://www.apachelounge.com/download/win32/modules-2.4/php5apache2_4.dll-php-5.4-win32.zip)
Runs with PHP 5.4 Thread Safe (TS), and only with Apache 2.4 Win32 VC9 or VC10.

PHP 5.4.10 and higher

Download PHP 5.4 VC9 x86 Thread Safe from http://windows.php.net/download/ . Extract and rename folder to php and move to C:\.

Update 01-17-2013: This next edit seems to cause issues with php5apache2_4.dll not found errors, so I have added two options for PHP 5.4.9 and earlier and PHP 5.4.10 and above. I want to thank all those who have brought this to my attention and I hope this helps out. Also, due to the addition of the php5apache2_4.dll being included in PHP 5.4.10 and above builds you no longer need to download the module separately.

PHP 5.4.9 and earlier Option 1

Extract php5apache2_4.dll-php-5.4-win32.zip and copy php5apache2_4.dll to the c:\php\ directory. This is needed to allow Apache to use PHP.  Edit Apache’s config file, c:\Apache24\conf\httpd.conf and add the following lines to the bottom of the file.

LoadModule php5_module "c:/php/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"

While we are at it we can add index.php to Apache’s list just incase we want to have a starting page as php.

Find Directory index and add index.php

DirectoryIndex index.html index.php

Next we need to input a value  for ServerName variable. You will have to un-comment it. Save the changes to the config file. Next move to the Register Apache Service step.

PHP 5.4.9 and earlier Option 2

Extract php5apache2_4.dll-php-5.4-win32.zip and copy php5apache2_4.dll to the c:\php\ext directory. This is needed to allow Apache to use PHP.  Edit Apache’s config file, c:\Apache24\conf\httpd.conf and add the following lines to the bottom of the file.

LoadModule php5_module "c:/php/ext/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"

While we are at it we can add index.php to Apache’s list just incase we want to have a starting page as php.

Find Directory index and add index.php

DirectoryIndex index.html index.php

Next we need to input a value  for ServerName variable. You will have to un-comment it. Save the changes to the config file. Next move to the Register Apache Service step.

PHP 5.4.10 and newer

Edit Apache’s config file, c:\Apache24\conf\httpd.conf and add the following lines to the bottom of the file.

LoadModule php5_module "c:/php/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"

While we are at it we can add index.php to Apache’s list just incase we want to have a starting page as php.

Find Directory index and add index.php

DirectoryIndex index.html index.php

Next we need to input a value  for ServerName variable. You will have to un-comment it. Save the changes to the config file. Next move to the Register Apache Service step.

Register Apache Service

Now let’s register Apache as a service. Open a command prompt and type.

c:\apache24\bin\httpd -k install

If do not want Apache starting automatically at start-up/reboot:

GUI Way

  • START | RUN
  • Type in services.msc, hit Enter or click OK
  • Locate Apache2 service and double-click (or right-click for Properties)
  • Find the caption Startup type: (in the middle of the dialog box), use the pull-down and select Manual
  • Click OK

Command line

C:\> sc config Apache2.4 start= demand

Add

c:\Apache24; c:\Apache24\bin

to PATH in Environment variables. PATH ENVIRONMENT (System Properties | Advanced | Environment Variables | System variables | Path).
Example:
;c:\php;c:\apache24;c:\apache24\bin;

Now lets check Apache settings by issuing the command, c:\Apache24\bin\httpd -S

PHP Edits

Now we have to do a few edits to the php.ini file to tell it to load support for mysql and the location for the extensions. Since there is not a already set php.ini file we need to rename one of the two examples to php.ini.

Rename c:\php\php.ini-development to php.ini

Now let’s edit php.ini
Uncomment extension directory.

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"

Uncomment mysql modules
extension=php_mysql.dll
extension=php_mysqli.dll

Save the changes and open a command prompt. Check to make sure it shows loaded modules.

C:\> php -m

So now we have Apache running and configured to use php. Lets create a file called info.php, save it and see if Apache parses the info correctly to display the results.

Open Notepad or your favorite Windows editor and type and save the following.

 <?php
phpinfo();
?>

Open your browser and type, localhost/info.php for the location and you should receive alot of information about PHP.

MySQL
Download and install mysql-5.5.21-win64.msi. Change installation directory to C:\MySQL\MySQL Server 5.5 instead of Program files as there could be permissions issues. Once the installation is completed you can let the configuration wizard run and setup the database server. The defaults will work just fine, but remember what you set the password to for root.

PHPMyAdmin
PHPMyAdmin is a very nice tool to use for administering your MySQL installation.
Download and install phpmyadmin-3.4.10.1-english.zip.
Extract the file and move to c:\apache24\htdocs. Rename directory to phpmyadmin.
Create a config directory under phpmyadmin. Open a browser and type localhost/phpmyadmin/setup/index.php to complete the installation.

At this point you should have a working Apache / PHP / MySQL installation running and ready for you to start developing !!!

Quick and Easy Apache/PHP/MySQL on Windows

While working on a website for a customer came upon a connectivity issue while working on a laptop getting to the Linux server to test the code. I thought about installing Apache / MySQL / PHP all locally on the laptop and setup a testing server, when I stumbled on XAMPP.

XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. XAMPP is really very easy to install and to use – just download, extract and start. The current version is 1.7.4 and contains: Apache, MySQL, PHP + PEAR, Perl, mod_php, mod_perl, mod_ssl, OpenSSL, phpMyAdmin, Webalizer, Mercury Mail Transport System for Win32 and NetWare Systems v3.32, Ming, FileZilla FTP Server, mcrypt, eAccelerator, SQLite, and WEB-DAV + mod_auth_mysql.

Installation is pretty simple. Double click on xampp-win32-1.7.4-VC6-installer.exe to start the process. Click OK to select the Language (English). Click Next on the Welcome screen.

xampp1

Next is the location of where XAMPP root will be on the system. The default is c:\xampp which will work in most cases, but if you have a separate drive you can change the location. When you are satisfied click next to continue.

 

xampp2

This will bring up the XAMPP Options screen. The service section has the option to start Apache, MySQL and Filezilla as a service at startup time. For our purpose I have checked the boxes for Apache and MySQL to start. If you choose not to you can always use the XAMPP control panel to start / stop the services. Once you are satisfied click Install. The installation will take a few minutes to complete, just sit back and relax and click finish when you are prompted.

xampp3

You now have a running web server with a database to start working with on your system.

Switch to our mobile site