Thursday, October 12, 2006

Apache, PHP and Mysql Installation & Configuration on Solaris 10

I have a new assignment last week which need to migrate company groupware from LAMP (Linux, Apache, Mysql, PHP) to SAMP (Solaris 10, Apache, Mysql, PHP) platform.

Hereby is the step by step guide to install and configure Apache, Mysql and PHP on Sun Solaris 10. This guideline is not my original work; I had added some extra steps for the issue I faced while using this guideline.

Pre Installatioin Requirement (Entry Criteria)
  1. Solaris 10 successful installed.
  2. Apache and Mysql is installed, they come with the Solaris 10 installation disk.

Step 1 – Configure and Test Start Apache2
  1. Apache 2.xx is included with Solaris 10. A few configuration details need to be addressed prior to starting Apache 2.xx:
    1. Login as root
    2. Copy the file, /etc/apache2/httpd.conf-example to /etc/apache2/httpd.conf
      # cp /etc/apache2/httpd.conf-example /etc/apache2/httpd.conf
    3. Edit /etc/apache2/httpd.conf
    4. Set ServerName if necessary (default is 127.0.0.1)
    5. Set ServerAdmin to a valid email address 
    6. From the command line type:
      # svcadm enable apache2
  2. That is all it takes to to start the basic Apache 2 web server bundled with Solaris 10. In fact, the Apache 2 web service should persist through server and/or zone boots. The actual web pages are located in the /var/apache2/htdocs directory by default.
Steps 2 – Configure and Start MySQL
  1. To start using the mysql bundled with Solaris 10, a number of post-install procedures need to be made by root.
  2. This configuration has been successfully tested in a SPARCE Root Local Zone.
  3. The following steps are derived from the mysql manual (manual.ps, manual.txt or manual_toc.html) found in the /usr/sfw/src/mysql/Docs directory.
  4. Log in as root and initialise the database tables.
    # /usr/sfw/bin/mysql_install_db
    Preparing db table
    Preparing host table
    Preparing user table
    Preparing func table
    Preparing tables_priv table
    Preparing columns_priv table
    Installing all prepared tables
    060118 21:24:03 /usr/sfw/sbin/mysqld: Shutdown Complete
    <snip...>
  5. Create mysql user and group and change data directory group.
    # groupadd mysql
    # useradd -g mysql mysql
    # chgrp -R mysql /var/mysql
    # chmod -R 770 /var/mysql
    # installf SUNWmysqlr /var/mysql d 770 root mysql
  6. MySQL reads configuration files from different places in the following order:
    Filename              Purpose
    ---------             ---------
    /etc/my.cnf           Global options
    DATADIR/my.cnf        Server-specific options
    defaults-extra-file   The file specified with --defaults-extra-file=path
    ~/.my.cnf             User-specific options
  7. Optionally copy a MySQL daemon configuration file to configuration directory.
    Note: there are other configuration profiles available.
    For default solaris installation DATADIR is /var/mysql.
    # cp /usr/sfw/share/mysql/my-medium.cnf /var/mysql/my.cnf  
  8. Start mysql daemon by hand
    # cd /usr/sfw/bin
    # ./mysqladmin -u root password 'new-password'
    # ./mysqladmin -u root -h `hostname` password 'new-password'
  9. Set the root MySQL user password (Substitute a unique password for "new-password")
    # cd /usr/sfw/bin
    # ./mysqladmin -u root password 'new-password'
    # ./mysqladmin -u root -h `hostname` password 'new-password'
    Note the use of single quotes surrounding your new-password and the back ticks surrounding the hostname command -- they are not the same!
  10. Test the server:
    # ./mysqlshow -p
    Enter password: new-password

    +-----------+
    | Databases |
    +-----------+
    | mysql |
    | test |
    +-----------+

    # ./mysql -u root -p
    Enter password: new-password

    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 3 to server version: 4.0.20-standard
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

    mysql> show databases;
    +-----------+
    | Databases |
    +-----------+
    | mysql |
    | test |
    +-----------+
    2 rows in set (0.00 sec)

    mysql> quit;
  11. Optionally perform the following steps for automatic start and stop of mysql daemon at boot and shutdown:  Link boot time start up script from rc3.d and rc[012S].d
    # ln /etc/sfw/mysql/mysql.server /etc/rc3.d/S99mysql
    # ln /etc/sfw/mysql/mysql.server /etc/rc0.d/K00mysql
    # ln /etc/sfw/mysql/mysql.server /etc/rc1.d/K00mysql
    # ln /etc/sfw/mysql/mysql.server /etc/rc2.d/K00mysql
    # ln /etc/sfw/mysql/mysql.server /etc/rcS.d/K00mysql
Step 3 – Download and Configure PHP
  1. Log into the global zone (default should be global) as root. Check by using following command
    # zonename
    global
  2. Ensure that /opt/csw/bin and /usr/sfw/bin are in $PATH
    # declare PATH=/opt/csw/bin:/usr/sfw/bin:/usr/openwin/bin:/usr/dt/bin:/usr/ccs/bin:$PATH
    # echo $PATH
    /opt/csw/bin:/usr/sfw/bin:/usr/sbin:/usr/bin:/usr/openwin/bin:/usr/dt/bin:/usr/ccs/bin
  3. Tell Solaris to use gm ake rather make come with Solaris.
    # MAKE=gm ake
    # export MAKE
  4. Install pkg-get from BlastWave.In the HowTo, we only need to follow Step 1 & Step 2. Solaris 10 have a copy of wget.
  5. Test by using pkg-get to install the gnu autoconf, automake and gsed packages.
    # pkg-get -i autoconf
    ...
    # which autoconf && autoconf --version | head -2
    /opt/csw/bin/autoconf
    autoconf (GNU Autoconf) 2.59
    Written by David J. MacKenzie and Akim Demaille.

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

    # pkg-get -i gsed
    ...
    # which gsed && gsed --version | head -2
    /opt/csw/bin/gsed
    GNU sed version 4.1.4
    Copyright (C) 2003 Free Software Foundation, Inc
    .
    # pkg-get -i c url
    ...
    # which c url && c url --version | head -2
    /opt/csw/bin/c url
    c url 7.15.5 (sparc-sun-solaris2.8-) libcurl/7.15.5 OpenSSL/0.9.8d zlib/1.2.3 libidn/0.5.19
    Protocols: tftp ftp telnet dict ldap http file https ftps
  6. Verify availability of other Open Source Software Required to install PHP. Refer from http://www.php.net/manual/en/install.unix.solaris.php
    # which gc c && gc c --version | head -2
    /usr/sfw/bin/gc c
    gc c (GCC) 3.4.3 (csl-sol210-3_4-branch+sol_rpath)
    Copyright (C) 2004 Free Software Foundation, Inc.

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

    # which fl ex && fl ex --version | head -2
    /usr/sfw/bin/fl ex
    fl ex version 2.5.4

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

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

    # which p erl && p erl -v | head -2
    /opt/csw/bin/p erl

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

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

    # which gt ar && gt ar --version | head -2
    /usr/sfw/bin/gt ar
    tar (GNU tar) 1.14
    Copyright (C) 2004 Free Software Foundation, Inc.
  7. Test the Open Source tools by builing libxml2 from source. Download the latest version from: xmlsoft.org [ftp://xmlsoft.org/]
    #g unzip -cd libxml2-2.6.23.tar.gz | g tar xvpf -
    #cd libxml2-2.6.23
    #./configure
    ...
    #gm ake
    ...
    #gm ake install
    ...
  8. If the file /etc/apache2/httpd.conf doesn't exist:
    # cp /etc/apache2/httpd.conf-example /etc/apache2/httpd.conf
    Edit /etc/apache2/httpd.conf
    Set ServerName if necessary (default is 127.0.0.1)
    Set ServerAdmin to a valid email address
  9. Download and Compile the latest production version of PHP [http://www.php.net/].
    # pwd
    /build
    # gunzip -cd php-5.1.2.tar.gz | g tar xvpf -
    ...
    # cd php-5.1.2

    # ./confi gure --with-apxs2=/usr/apache2/bin/apxs \
    --with-mysql=/usr/sfw --enable-dbase \
    --with-libxml-dir=/usr/local \
    --with-config-file-path=/etc/apache2
    ...

    # gm ake
    ...
    # gm ake ins tall
    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/
    c p .libs/libphp5.so /usr/apache2/libexec/libphp5.so
    chm od +x /usr/apache2/libexec/libphp5.so
    c p .libs/libphp5.lai /usr/apache2/libexec/libphp5.la
    libtool: inst all: warning: remember to run `libtool --finish /build/php-5.1.2/libs
    chm od 755 /usr/apache2/libexec/libphp5.sov [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: phpi ze
    program: php-co nfig
    Instal ling ma n pages: /usr/local/ma n/ma n1/
    pa ge: ph pi ze.1
    pa ge: p hp-co n fig.1
    Instal ling PE AR environment: /usr/local/lib/p hp/
    [PE AR] Archive_T ar - instal led: 1.3.1
    [PE AR] Console_Ge topt - instal led: 1.2
    pe ar/PE AR can optionally use package "pe ar/XML_RPC" (version >= 1.4.0)
    [PE AR] PEAR - installed: 1.4.6
    Wrote PE AR sys tem 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/
  10. This step is optional only use if you defined a zone for web services. Copy the file, php.ini-dist from /build/php-5.1.2 in Global Zone to /etc/apache2/php.ini in the Zone where you want Apache2 to load the PHP module.
    # cp php.ini-dist /zones/zone0/root/etc/apache2/php.ini
    To configure zone, please refer to System Administration Guide: Solaris Containers-Resource Management and Solaris Zones. You able to download the document from http://docs.sun.com/app/docs/doc/817-1592?a=load
  11. Log in as root to the zone where Apache2 and the PHP module will run
    # zlogin zone0
    [Connected to zone 'zone0' pts/4]
    Last login: Thu Jan 19 18:05:50 on pts/5
    Sun Microsystems Inc. SunOS 5.10 Generic January 2005 # cd /etc/apache2
  12. Edit the configuration files
    Edit the php.ini file to set PHP options.
    Edit the httpd.conf file to load the PHP module.

    The path on the right hand side of the LoadModule statement must point to the path of the PHP module on your system. The gm ake install from above may have already added this for you, but be sure to check.
    LoadModule php5_module libexec/libphp5.so
    Have Apache2 parse the .php extension as PHP
    AddType application/x-httpd-php .php
    Add index.php is one of the main page if exis
    DirectoryIndex index.html index.html.var index.php
  13. Start Apache2 and Test.
    # svcadm enable apache2
    # svcs | grep -i apache2
    online 18:07:10 svc:/network/http:apache2
Exit Criteria
  1. Apache2 and Mysql should running now
  2. Use web browser and visit your server IP and it should show the Apache Info Page
  3. Create a simple PHP file and save into Apache Document Root directory. Insert below text into the file.
    <?php phpinfo(); ?>
  4. Load the php file from web browser, PHP configuration page should appear
  5. Restart the server
    #init 6
  6. After server restart, repeat the step 1, 2 & 4. These service should start automatically.

 Reference
  1. AMPS (Apache MySQL PHP SSL) for Solaris 10 by Mel Lester Jr
      

1 comment:

  1. This is often very a beautiful post. Firstly, i would choose to several thanks for swing stress on but association plays an enormous role in hosting aspect. Fantastic stuff.

    Reliable dedicated hosting

    ReplyDelete