Installation and setup of the Blastwave.org AMP stack

Plenty of information is available for setting up an AMP stack on different flavours of Linux and even MS Windows. Some good quality guides are also available from Sun for setting up the Sun AMP stack on Solaris and OpenSolaris. This blog entry, presents a simple step-by-step guide on how to install and setup a high performance AMP stack from Blastwave.org. Assuming good hardware and reasonably well behaved content a basic installation should be able to scale well into the ten of millions hits per month.

Some important notes before we proceed.

  • This guide assumes basic knowledge of the UNIX environment including the use of a shell and a command line editor (vi or vim recommended). Also, basic survival skills around the UNIX file system structure will be of a great help. However, minimal to no knowledge of Solaris is necessary, so if this is the first thing you want to try with Solaris/OpenSolaris is setting up a professional AMP stack welcome aboard.
  • You should have available a relatively clean and properly configured Solaris or OpenSolaris system. Obviously root access is necessary.
  • This guide is aimed at Solaris 10 and OpenSolaris also called Solaris 11 by some. The Blastwave stack works on Solaris 8 and 9 but the steps are a little different. Chances are that if you are using one of those systems you won't need this guide to begin with.
  • For those coming from another Unix-like system be aware that in Sol10+ apache, mysql and other services/daemons are controlled through the Servive Management Framework (SMF) and should not in most cases be started and stopped manually. For example, apache should not be started using apachectl. More information on this is available later in this guide.

Step 0. Solaris and OpenSolaris installation

If you are new to Solaris, an installation from the OpenSolaris live CD is pretty much all you need and will be easier than configuring Solaris 10. A fresh installation of Solaris 10 requires the creation of a user account while OpenSolaris will be fully configured with a user account and proper permissions. In Solaris, switching to the root account from a normal account is done by typing su at the command line and then entering the root password. The output will look something like this :

$ su 
Password: 
# 

Note that one should generally never log to the desktop or directly to a remote shell as root for security reasons. OpenSolaris is configured in such a way that it is impossible to do so. Also, somewhat like sudo in Linux it is possible to execute a command with additional privileges by prefixing a shell command with pfexec.

$ pkgadd -d gawk-3.1.7.pkg 
pkgadd: ERROR: You must be "root" for pkgadd to execute properly. 
$ pfexec pkgadd -d gawk-3.1.7.pkg 

The following packages are available: 
  1  CSWgawk     gawk - GNU AWK 
                 (i386) 3.1.7,REV=2009.10.02 

Select package(s) you wish to process (or 'all' to process 
all packages). (default: all) [?,??,q]: 

Step 1. Installing the package manager

Software from Blastwave are managed by using pkgutil which must be installed prior to doing anything else. Very simply, pkgutil can be installed by running the following command as root or with pfexec :

# pkgadd -d http://blastwave.network.com/csw/pkgutil_`/sbin/uname -p`.pkg

Additional information on how to use Blastwave, especially information pertaining to setting up gpg key verification can be found in the how-to guide at www.blastwave.org/howto.html.

The package will then be downloaded and a prompt should appear in the terminal.

# pkgadd -d http://blastwave.network.com/csw/pkgutil_`/sbin/uname -p`.pkg

## Downloading...
..............25%..............50%..............75%..............100%
## Download Complete


The following packages are available:
  1  CSWpkgutil     pkgutil - Installs Solaris packages easily
                    (i386) 1.6.1,REV=2009.06.15

Select package(s) you wish to process (or 'all' to process
all packages). (default: all) [?,??,q]:

At this prompt you should enter “all” or “1” to select the installation of CSWpkgutil. A second prompt will quickly follow :

Processing package instance  from 

pkgutil - Installs Solaris packages easily(i386) 1.6.1,REV=2009.06.15

Please see /opt/csw/share/doc/pkgutil/license for license information.

## Processing package information.
## Processing system information.
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.
## Checking for setuid/setgid programs.

This package contains scripts which will be executed with super-user
permission during the process of installing this package.

Do you want to continue with the installation of  [y,n,?]

Again enter “y” to continue the installation. Some more output will follow ending hopefully with a message stating that the installation of CSWpkgutil was successful.

Step 2. Installation of the software packages

The first thing to do after installing pkgutil is to fetch the catalog containing the list of all available packages. This is done, again as root, by typing :

# /opt/csw/bin/pkgutil --catalog

Note that all the software from Blastwave including pkgutil are located in the /opt/csw directory. The choice of adding or not /opt/csw/bin in the PATH is yours to make and this guide will always use the full absolute path when invoking executables from the Blastwave stack. If you have no idea what is the PATH don't touch anything and continue on.

Now is the time to install the first package, namely the Apache http server.

# /opt/csw/bin/pkgutil --install apache2

Entering the previous installation command will query the catalog for the required dependencies and after reporting them to the user will ask for a confirmation to continue.

# /opt/csw/bin/pkgutil --install apache2
Parsing catalog, may take a while...
New packages: CSWcommon-1.4.6,REV=2008.04.28 ... CSWapache2-2.2.13,REV=2009.09.25
Total size: 81.2 MB
32 packages to fetch. Do you want to continue? [Y,n]

Enter Y to watch a cascade of output as packages are downloaded and then installed. Depending on the speed of your machine and Internet connexion this will take a little while. Answer “y” at all the confirmation prompts encountered. During installation, the pkgadd utility will sometimes complain about conflicting files, these are normal and can in most case be safely ignored by entering “y”. Congratulation Apache 2 is now installed.

Now the same thing must be done for the all of the following packages forming the core of a functional AMP stack. Note that apache2 is already installed at this point. While the order should not matter installing them in the presented order is recommended.

  • apache2 - Apache web server
  • php5 - PHP hypertext processor 5
  • mysql5 - MySQL database server
  • php5_mysql - MySQL extension to PHP 5
  • ap2_modphp5 - PHP5 module for Apache 2.2+

At this point all the required software for a fully functional AMP stack are installed. The only thing required next is to configure it's components.

Step 3. Basic configuration of the Apache web server

The main configuration file for Apache is located in the /etc/opt/csw/apache2 and is named httpd.conf. A backup file named httpd.conf.CSW contains the default settings in case it is required to reset the configuration.

Important note : Apache will not start without performing these configuration steps listed bellow. The entries to edit are ordered the same way as they appear in the httpd.conf file.

The first entry that should be configured, albeit optional is the ServerAdmin entry. If a web facing server is configured this entry should contain the email of the web admin.

ServerAdmin webmaster@jblopen.com

By default the user and group for the apache daemon is nobody:nobody. This must be changed to a more reasonable user. Solaris 10 and OpenSolaris have a user and group webservd configured at installation and makes a perfect choice for the Apache daemon.

User webservd
Group webservd

Next is one critical entry is the ServerName entry. This should be configured to the primary domain name for the server followed by the port to listen for connexions. If there is no domain associated with the server the ip address of the server should be used. For a local test installation the address of 127.0.0.1:80 can be used to instruct the web server to listen for connexions on the local host.

ServerName 127.0.0.1:80

or

ServerName jblopen.com:80

That is all for a basic installation.

Step 4. Starting and testing Apache

At this point we are ready to try Apache. First of all, the cswapache2 services may already have tried to start before being properly configured. This will place the service in maintenance mode preventing it to start before the error condition is cleared. Since we took care of the configuration we first must clear the status of cswapache2 by running :

svcadm clear cswapache2

Then we can start the server :

svcadm enable cswapache2

Then we should verify that the server is running :

# svcs cswapache2
STATE          STIME    FMRI
online         17:08:05 svc:/network/http:cswapache2

Now point a browser to the address configured earlier. 127.0.0.1 or localhost if you want to test a local installation. If a white page is displayed instead of a server not found error then the installation is working. You can edit the file /opt/csw/apache2/share/htdocs/index.html to try a basic web page instead of a blank one. Be sure to press reload on your browser to refresh the changes.

Step 5. Configuring MySQL and PHP

The good news is that PHP is already configured with sensible default values that should be adequate for most needs. MySQL however, needs to be initialized, a nifty script is included to ease that task named quick_start-csw. The script will ask for basic configuration information, for most question it is safe to select the default.

First run the quick start script in a terminal as root :

# /opt/csw/mysql5/share/mysql/quick_start-csw

The first question asked is the data directory where the databases will be stored.

# /opt/csw/mysql5/share/mysql/quick_start-csw

This is the blastwave quick start script to setup a MySQL5 database
  directory.

  The base directory is /opt/csw/mysql5.
  The default database directory is /var/opt/csw/mysql5.

  If you have not setup a partition for the database and
  you want one; now is a good time to exit this script and
  create and mount the partition.

  If you have not setup a my.cnf file and you do not want
  one of the sample files; now is a good time to exit and
  create the file /etc/opt/csw/mysql5/my.cnf.

Data directory: The default is /var/opt/csw/mysql5.

Accept the default or enter a directory [?,q]

Press enter to accept the default. Next step is the location of the configuration file.

my.cnf pathname: The default is either to use the supplied file in
  the base directory or to create one in the base directory from
  the small memory footprint sample.  If your enter a pathname,
  it will be used to create the options file in the base directory.
  my.cnf: The default is /etc/opt/csw/mysql5/my.cnf

Accept the default or enter a pathname [?,q]

Again press enter to accept the default. This will use the default low memory footprint configuration for MySQL. Enter “y” at the next question to apply the changes. The next step is optional but strongly recommended for everything that will be facing a network.

Before we can secure the installation of MySQL we must start the SQL server, similar to apache this can be done using SMF. First clear the service if in maintenance mode :

# scvadm clear cswmysql5

Then start it :

# scvadm enable cswmysql5

To secure the installation of MySQL run the following script :

# /opt/csw/mysql5/bin/mysql_secure_installation

The first thing the script will ask is the current root password for MySQL. It is blank by default so press enter to input a blank password. Then enter “y” to enter the new password for root access to MySQL. The script then ask about removing the anonymous user. Unless you have a good reason it should be removed by answering “y”. The same thing should be done with remote root login and the test database. Finally the script will ask for reloading the privileges table for the changes to take effect, answer “y”.

Before proceeding it is a good idea to restart Apache and MySQL.

# svcadm restart cswmysql5
# scvadm restart cswapache2

Step 6. Test the whole stack

To test the entire configuration create the file phpinfo.php in the root web folder. By default this should be :

/opt/csw/apache2/share/htdocs/phpinfo.php

Insert the following content into the newly created file :

<?php phpinfo(); ?>

Then point a browser to this file, URL localhost/phpinfo.php for a local test. This should display a lot of information about the AMP stack configuration. If however the browser only display the php code restart apache and reload the page. Of particular importance on this page is the mysql section, if it contains something then it means that mysql is working correctly and that it is accessible by your web server.

Assuming everything went well, you now have a fully functional AMP stack on Solaris!

Important files and directories :
Apache2 :
Configuration file : /etc/opt/csw/apache2/httpd.conf
Default web root : /opt/csw/apache2/share/htdocs/
Logs : /var/opt/csw/apache2/log

PHP5
Configuration file : /opt/csw/php5/lib/php.ini

MySQL
Admin command : /opt/csw/mysql5/bin/mysql
Configuration file : /etc/opt/csw/mysql5/my.cnf
Logs : /var/opt/csw/mysql5/

Where to go from here :

  • Additional packages can be browsed for at http://www.blastwave.org/pkg/packages.ftd.
  • Having the web root inside the /opt/csw directory is a bit awkward. This can be changed in the httpd.conf file by modifying the DocumentRoot entry and the corresponding ... section.
  • By default the .htaccess files are ignored. This can be enabled by stetting the AllowOverride parameter to “all”.

Enjoy!

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.