Random Shouts from the Engine Room Neal Pollack's Weblog

Wednesday Sep 13, 2006

There are many documents and blogs that can be found on the internet
regarding how to use Solaris 10 for a SAMP Server (Solaris, Apache2, MySQL, PHP).
However, many of them are for older versions of the software packages mentioned
above, or do not include the popular PHP language.  Some of them lack any detail
or examples to help you understand what is going on.

Before starting, it should be clarified that an installation of Solaris 10 or Solaris
Express does include Apache 2.0.x and Mysql4.  The Companion CD for Solaris 10 also
includes PHP4.  However, at this time Solaris does not bundle PHP5 or MySQL5 at all.

An older article for configuring a SAMP server with the above packages
can be found at;
http://www.sun.com/bigadmin/content/submitted/samp.html
although it lacks any significant detail, and uses the older apache 1.3.  A much better
article by Mel Lester is found at;

http://www.sun.com/bigadmin/jsp/descFile.jsp?url=descAll/amps_apache_mysql_p
  (http://meljr.com/~meljr/AMPSolaris10.html)

which is well written, shows much detail, and is almost what we want, with
the exception that it uses the version of MySQL 4 that is bundled with Solaris 10,
and not the current MySQL version 5.x that we prefer.

The primary reason that many of us like to rebuild the software is to obtain recent
versions of the packages due to performance, bugs, or security fixes, and possibly to include
compile time options that provide features you may need for various PHP web applications.

For this exercise, the installation will use the following software;

  - Apache2 as delivered with the Solaris installation.
  - Mysql 5 from www.blastwave.org using pkg-get to install.
  - Latest PHP5 from php.net, downloaded and compiled.

and build it in 32-bit mode, using a mostly GNU tool chain.

The procedure below will integrate these three applications together so that you are ready to
use "Solaris 10, Apache2, PHP5, and MySQL5" web applications.

Here are the Steps:

1.  Install Solaris 10, Solaris Express/Nevada, or OpenSolaris.

2.  Make sure your system is networked so that it can reach the internet and is using a
    static IP Address.  If you need assistance with network configuration, review the
    following documentation;  http://docs.sun.com/app/docs/doc/816-4554

3.  We wish to install Mysql5 from Blastwave.org.  Open a web browser, go to this URL;
    http://www.blastwave.org/howto.html
    and perform steps 1 through 7.
    It's that simple, and you are now ready to use the pkg-get
    command to install packages such as mysql5 over the network.

4.  We are now ready to install mysql5 packages.
    From a console or xterm window, log in as root and issue these commands;
    # /opt/csw/bin/pkg-get -i mysql5 mysql5client mysql5devel mysql5rt
    # /opt/csw/bin/pkg-get -i mysql5test

    Note:  It is very important to install the mysql5devel package
    above, or else you will have trouble building PHP5 later, below.

5.  Now let's set up mysql5.  Follow this guide:
    http://www.blastwave.org/mantis/main_page.php
    [ I have repeated it here in case the page is down, and also expanded
      upon some of the discussion. ]

    A) Create the config file /opt/csw/mysql5/my.cnf:
       Copy one of the my-*.cnf files in /opt/csw/mysql5/share/mysql/
       to /opt/csw/mysql5/my.cnf and make any changes appropriate for your
       environment, such as enabling InnoDB.
       Note that /opt/csw/mysql5/var is a deprecated location for my.cnf
       If you are not sure of which file to copy, use my-small.cnf

    B) It is important to set up a mysql user and group BEFORE initializing the
       database in the next step.  This is done for you by the Blastwave package
       install script.  However, if you are building mysql from source, you will
       need to create a mysql user and group as follows:

       # groupadd mysql
       # useradd -c "MySQL Server" -d /dev/null -g mysql -s /bin/false mysql

    C) Initialize the mysql database and fix the permissions:
       cd /opt/csw/mysql5
       ./bin/mysql_install_db
       chown -R mysql:mysql ./var

       CAUTION:  If you skip the "chown" step above, MySQL will refuse to start.

    D) Start mysql5:
       To simply attempt to start the server and see if the above
       steps were done correctly, you can issue this command;

          #  cd /opt/csw/mysql5 ; /opt/csw/mysql5/bin/mysqld_safe &

       You can then check with the ps command to see if it started,
       and use the kill command and the PID to stop it.

       CAUTION:  Make sure you kill the above process before proceeding,
       or else MySQL will not start properly when you enable the SMF server below.
       This command should work;

         #  pkill mysql

       Now, to ensure it will start after a reboot, read on;

       NOTE:  Recent builds of Solaris Express, Nevada, and Solaris
       10 updates are using SMF to start daemons such as mysql.
       The process below may vary.  If your version of Solaris uses SMF,
       you will use the svcadm commands shown below to
start/stop Mysql5.

       Old RC file method:

           # /etc/init.d/cswmysql5 start

       New SMF method:

       If you installed the mysql5 package on a version of Solaris that is
       using SMF instead of RC files, you will find  that the package
       installed an SMF manifest for mysql5, and you can see the
       state of the service by using this command;

       # svcs -a | grep mysql
       disabled       13:36:01 svc:/network/cswmysql5:default

       To make sure the mysql5 server starts (and also at reboot),
       issue this command;
       # svcadm enable svc:/network/cswmysql5:default

       You can verify using this command again;
       # svcs -a | grep mysql
       online         15:12:43 svc:/network/cswmysql5:default

       You can stop the server with command;
         # svcadm disable svc:/network/cswmysql5:default
       and it will remain stopped, even across a reboot, until you
       issue the svcadm enable command.

    E) PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
       This should NOT be the same as your Solaris root user password!
       To do so, start the server, then issue the following commands:


       To set the local password;
           #  /opt/csw/mysql5/bin/mysqladmin -u root password 'new-password'

           #  /opt/csw/mysql5/bin/mysqladmin -u root -h zhost password 'new-password'
       ( The above command line will fail, and is not needed, if you have disabled
         network access via the security discussion in part "5i" below. )

       See the mysql5 manual for more instructions.
       http://www.mysql.org/doc/

    F) OPTIONAL:  Takes some time. You can run test suites for the MySQL
       daemon with the following commands;
       # cd /opt/csw/mysql5/mysql-test
       # ./mysql-test-run

    G) Check the install:
           #  ./bin/mysql -p
       -you willbe prompted to enter MySQL root's password-

       You should see a mysql prompt.
       Try a command such as STATUS to see if the server responds.
       Next, try to run a test query from the mysql prompt:
       show databases;
       -The mysql and test database is returned-
       quit

       Note:  Startup options may be overriden by creating and editing either 
              /opt/csw/mysql5/etc/mysql5rc

              or   /etc/opt/csw/mysql5rc. 
       The template for mysql5rc is in /opt/csw/mysql5/share/mysql. You

       must use this template, if making an rc file for your system.

       For example,

       a.)   #  mkdir -p /etc/opt/csw
           (I use these permissions - `chown root:bin /etc/opt/csw`
           and `chmod 0755 /etc/opt/csw`)

       b.)  #  cp  /opt/csw/mysql5/share/mysql/mysql5rc  /etc/opt/csw/

       If no mysql5rc file is available, the daemon starts with defaults.
       If this is your first experimental system, don't bother with this step, it is optional.


   H)  Reference Docs:

       http://www.mysql.org/doc/
       http://dev.mysql.com/tech-resources/articles/mysql_intro.html

   I)  MySQL Security:   An item that is beyond the scope of this article.  However,
       there are some very basic steps to be considered:

       *  Make sure the MySQL root user has a password set, and that it is different
          than the host system root password.

       *  Make sure that only the mysql user has read and write access to the database directory.

       *  If using mysql on a web server for PHP (so only localhost connections are needed
          between php/apache and mysql), add the line "skip-networking" to the [mysqld] section
          of your /opt/csw/mysql5/my.cnf configuration file.  This will disable all TCP/IP remote
          connections to the MySQL server daemon.

       *  Disable the use of the LOAD DATA LOCAL INFILE command, which could permit
          unauthorized reading from local files, especially when new SQL injection
          attacks occur.  In the [mysqld] section of your my.cnf file, add

            set-variable=local-infile=0

       *  Get rid of anonymous user accounts in the users table.

       The above steps only scratch the surface, but make a good level of improvement
       after installation.  Please do review articles about MySQL security on the web
       by entering "Securing MySQL" into your favorite internet search engine.


6.  We are now done with installing and testing MySQL5.  Next, let's build PHP5.
    Let's borrow portions from this web page, http://meljr.com/~meljr/PHPSolaris10.html
    with the kind permission granted by Mel, but modify some of the PHP configuration since
    we are using different options and paths.

    Specifically, we will change the configuration of PHP5 before compiling to use
    the path to our Blastwave MySQL5 in  /opt/csw/mysql5, and also add some other options.
    The procedure will also verify that you have the needed GNU tools installed to build PHP5.

    A.  Log into the global zone as root and ensure that /opt/csw/bin and /usr/sfw/bin are in $PATH
        global# echo $PATH
        /opt/csw/bin:/usr/sfw/bin:/usr/sbin:/usr/bin:/usr/openwin/bin:/usr/dt/bin:/usr/ccs/bin

        OK, let's talk.  First, you may not want to modify the .profile for root and also
        clutter up the / directory with junk.  I'd suggest, being Solaris 10, Solaris Express,
        or OpenSolaris, that you create the dir /root, and make another root account in
        /etc/password that uses the bash or ksh shell, and points to /root as a home dir.
        But that is a choice and topic for you and google.  Whatever you decide, please ensure
        that your path has the components above.  Then proceed.

    B.  Use the blastwave.org pkg-get command (installed in step #3 above) to install
         the gnu autoconf, automake and gsed packages.
         Versions of the below software should be relatively similar or more recent.

        global#  pkg-get -i autoconf
        ...
        global#  which autoconf && autoconf --version | head -2
        /opt/csw/bin/autoconf
        autoconf (GNU Autoconf) 2.59
        Written by David J. MacKenzie and Akim Demaille.

        global#  pkg-get -i automake
        ...
        global#  which automake && automake --version | head -2
        /opt/csw/bin/automake
        automake (GNU automake) 1.8.3
        Written by Tom Tromey <tromey@redhat.com>.

        global#  pkg-get -i gsed
        ...
        global#  which gsed && gsed --version | head -2
        /opt/csw/bin/gsed
        GNU sed version 4.1.4
        Copyright (C) 2003 Free Software Foundation, Inc.

    C.  Verify availability of other Open Source Software Required to install PHP.
        (You can review this if you wish:  http://www.php.net/manual/en/install.unix.solaris.php )
        Versions of the below software should be relatively similar or more recent.

        global#  which gcc && gcc --version | head -2
        /usr/sfw/bin/gcc
        gcc (GCC) 3.4.3 (csl-sol210-3_4-branch+sol_rpath)
        Copyright (C) 2004 Free Software Foundation, Inc.

        global#  which gmake && gmake --version | head -2
        /usr/sfw/bin/gmake
        GNU Make 3.80
        Copyright (C) 2002  Free Software Foundation, Inc.

        global#  which flex && flex --version | head -2
        /usr/sfw/bin/flex
        flex version 2.5.4

        global#  which bison && bison --version | head -2
        /usr/sfw/bin/bison
        bison (GNU Bison) 1.875
        Written by Robert Corbett and Richard Stallman.

        global#  which gm4 && gm4 --version | head -2
        /opt/csw/bin/gm4
        GNU M4 1.4.3
        Written by Rene' Seindal.

        global#  which perl && perl -v | head -2
        /opt/csw/bin/perl

        This is perl, v5.8.7 built for sun4-solaris-thread-multi

        global#  which gunzip && gunzip -V | head -2
        /usr/bin/gunzip
        gunzip 1.3.3-patch.1
        (2002-03-08)

        global#  which gtar && gtar --version | head -2
        /usr/sfw/bin/gtar
        tar (GNU tar) 1.14
        Copyright (C) 2004 Free Software Foundation, Inc.


    D.  Test the Open Source tools by building libxml2 from source:
         Download the latest version from:  http://xmlsoft.org
         At this time, we found the following version of zipped source here;

            # wget ftp://xmlsoft.org/libxml2/libxml2-2.6.26.tar.gz

        You choose which directory to perform the following steps in;

         global#  gunzip -cd libxml2-2.6.26.tar.gz | gtar xvpf -
         global#  cd libxml2-2.6.26
         global#  ./configure
         ...
         global#  gmake
         ...
         global#  gmake install
         ...

         You are now done building and installing the libxml2 software and will
         find it located in /usr/local


    E.  If the file /etc/apache2/httpd.conf doesn't exist:

             global#   cp  /etc/apache2/httpd.conf-example  /etc/apache2/httpd.conf

        Edit /etc/apache2/httpd.conf with your favorite text editor;

        * Set ServerName if necessary (default is 127.0.0.1) to your hostname.
        * Set ServerAdmin to a valid email address.


    F.  Download and Compile the latest production version of PHP from www.php.net
        Again, you choose your own directory such as /src or /build or whatever.
        As of this writing, it was at  http://www.php.net/downloads.php#v5
        We choose to download the gzipped version so we could use the command below
        to proceed;

        global#  gunzip -cd  php-5.1.6.tar.gz | gtar xvpf -
        ...
        global#  cd  php-5.1.6

        This is where we differ from the original web page.  The original was using
        the older mysql4 found in /usr/sfw, and we are using a current mysql5 located
        in /opt/csw/mysql5.  So our choice of configuration options is now;

        global#  ./configure --with-apxs2=/usr/apache2/bin/apxs --enable-dbase \
        --with-libxml-dir=/usr/local --with-config-file-path=/etc/apache2 \
        --with-mysql=shared,/opt/csw/mysql5 \
        --with-mysqli=shared,/opt/csw/mysql5/bin/mysql_config \
        --with-xpm-dir=/usr  --with-gd  --with-tiff-dir=/usr  --with-bz2=/usr/lib \
        --with-jpeg-dir=/usr  --with-png-dir=/usr  --with-zlib  --enable-mbstring \
        --enable-calendar   --enable-bcmath  --enable-ftp  --enable-exif

        The above configuration options are good enough for a simple server setup.
        There are many other options, and that is left for user choice and documentation.
        You can see some of the options by entering command   # ./configure --help
        and also review  http://www.php.net/manual/en/configure.php
        NOTE:  If you try to enable openssl, you will have to recompile Apache2 and MySQL
        to have the same version openssl library, or else PHP to MySQL connections will fail.
        If you are going to use cookies for sessions, you might see a performance gain by adding
        the mcrypt library to your system, and using PHP compile option  --with-mycrpt.
        Amusing Note:   If you are curious what config options other people are using, simply
        try entering "phpinfo()" into your favorite internet search engine :-)
        Anyway, let's build it now;

        ...
        global#  gmake
        ...
        global#  gmake install

        ...
        Installing PHP SAPI module:       apache2handler
        /var/apache2/build/instdso.sh SH_LIBTOOL='/var/apache2/build/libtool' libphp5.la /usr/apache2/libexec
        /var/apache2/build/libtool --mode=install cp libphp5.la /usr/apache2/libexec/
        cp .libs/libphp5.so /usr/apache2/libexec/libphp5.so
        chmod +x /usr/apache2/libexec/libphp5.so
        cp .libs/libphp5.lai /usr/apache2/libexec/libphp5.la
        libtool: install: warning: remember to run `libtool --finish /build/php-5.1.2/libs'
        chmod 755 /usr/apache2/libexec/libphp5.so
        [activating module `php5' in /etc/apache2/httpd.conf]
        Installing PHP CLI binary:        /usr/local/bin/
        Installing PHP CLI man page:      /usr/local/man/man1/
        Installing build environment:     /usr/local/lib/php/build/
        Installing header files:          /usr/local/include/php/
        Installing helper programs:       /usr/local/bin/
          program: phpize
          program: php-config
        Installing man pages:             /usr/local/man/man1/
          page: phpize.1
          page: php-config.1
        Installing PEAR environment:      /usr/local/lib/php/
        [PEAR] Archive_Tar    - installed: 1.3.1
        [PEAR] Console_Getopt - installed: 1.2
        pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0)
        [PEAR] PEAR           - installed: 1.4.6
        Wrote PEAR system config file at: /usr/local/etc/pear.conf
        You may want to add: /usr/local/lib/php to your php.ini include_path
        Installing PDO headers:          /usr/local/include/php/ext/pdo/
        #


    G.  Copy the file php.ini-dist from your php-5.1.6 source directory to Apache2's config dir;

        global#  cp  php.ini-dist   /etc/apache2/php.ini
       
        If you are setting up apache web servers in zones, perhaps you might have an
        example path such as;
             global#  cp  php.ini-dist  /zones/zone0/root/etc/apache2/php.ini
        or whatever zone you are using.


Next, we will edit configuration files.  Continued in the next blog entry...
  
Comments:

This is interesting, and I'm doing that kind of things at work too, but it still much more painful than on a Linux distro, with little or no advantage.
You've got a lot of library duplication there. First, rebuilding libxml2. Why? Because Solaris version is 2.6.10, and PHP5 asks for 2.6.11 minimum... What does it take to have Sun update it?
Then you're going to have a lot of duplicated libraries in /opt/csw, which are going to mix up sooner or later with those in /usr or your own, as I've learned the hard way.
This is a useful article if your goal in life is becoming a software package maintainer in a messy environment. But as I'd rather spend less time juggling with dependencies, and more doing productive work. It's just a frustrating exercise toying endlessly with -R, crle, and friends.
This isn't going to convince anybody else than a hard-core Solaris admin (as I am, still) that Solaris is an enjoyable OS.

Posted by Laurent Blume on September 15, 2006 at 05:18 AM PDT #

In response to Laurent Blume's comment : Please check out 'Cool Stack' at http://cooltools.sunsource.net/coolstack. This provides an optimized AMP package for SPARC/Solaris with Apache/PHP/MySQL pre-configured. It bundles all necessary libraries and is a single download. Shanti Project Lead for Cool Stack

Posted by Shanti Subramanyam on September 15, 2006 at 02:01 PM PDT #

Sun has integrated libxml2 version 2.6.23 into Solaris Nevada, and it should be in OpenSolaris by now, or any moment. We are also working to see about resource to backport it to a Solaris 10 update. The point is a good one.

Posted by Neal Pollack on September 18, 2006 at 04:07 PM PDT #

hmm

Posted by 196.3.62.3 on September 22, 2006 at 11:43 AM PDT #

Why do we need to compile php? It becomes such a headache to maintain and upate. If it works, pkg-get is so much easier. Blastwave has php5, ap2_modphp5 and php5_mysql, so I have done the following (and nothing else): pkg-get install apache2 pkg-get install mysql5 pkg-get install php5 pkg-get install php5_mysql pkg-get install ap2_modphp5 And I am getting: http://solaris.ismlab.usf.edu/phpinfo.php Clearly, not there yet. I was hoping no other configuration would be necessary (the equivalent to the above works in Debian). Could you show what additional configuration is necesary to use these (or any other) packages to build a basic SAMP system? Thanks Manish

Posted by Manish Agrawal on September 27, 2006 at 03:36 PM PDT #

Actually, my bad. The above pkg-get steps do work. My problem was that the apache2 from the Solaris default installation was running too. svcadm disable apache2 did the trick (the apache2 from Blastwave is cswapache2). Now to actually run a php application to make sure that the connectivity with MySQl is actually in place. Manish

Posted by Manish Agrawal on October 05, 2006 at 12:57 PM PDT #

'Cool Stack' is good but is not enough. I am trying to convince one of our developers to move from Linux to Solaris 10 with all software installed on the linux: Apache2, PHP, MySQL. But he uses in PHP e.g. Smarty, mbstring, gd, adodb etc and a lot of extensions which in Linux are usually in packages. Now I have to compile almost all the soft from sources (especially PHP) because his needs. 'Cool Stack' is not a solution here.

Posted by przemol on October 19, 2006 at 05:07 AM PDT #

I second that motion. I've just tried out CoolStack and was very please until I found out I was missing an extension that's not included (mbstring) ... How do I get this compiled into the CoolStack ?

Posted by Jim Doherty on November 02, 2006 at 12:46 AM PST #

When we built Cool Stack, we debated on what PHP extensions to include. The problem is that the more extensions you include, the slower PHP gets. We finally decided to stick with a set we thought was most useful. Realizing that many customers may end up re-building PHP, we have included a "config.sh" script in the PHP source directory. Just edit it to include your extension(s) and run the script. If you have suggestions on "must-have" extensions, please let me know via email. We'll be sure to include them going forward. By the way, mbstring is already on the list.

Posted by Shanti Subramanyam on November 07, 2006 at 02:11 PM PST #

Sorry - forgot to post my email address in my previous post. It's 'firstname.lastname@sun.com'

Posted by Shanti Subramanyam on November 07, 2006 at 03:05 PM PST #

Post a Comment:
Comments are closed for this entry.