<?xml version="1.0"?>
<article><artheader><title>Sybase-PHP-Apache mini-HOWTO</title><author><firstname>Tyson</firstname><othername>Lloyd</othername><surname>Thwaites</surname><affiliation><address format="linespecific"><email>tyson.lloydthwaites@ite.com.au</email></address></affiliation></author><abstract><para>This HOWTO explains how to set up a Linux machine to run
    an Apache web server using PHP to access a Sybase-ASE
    database. </para></abstract><revhistory><revision><revnumber>1.3</revnumber><date>2001-07-11</date><authorinitials>TLT</authorinitials><revremark>Fixed example PHP script.</revremark></revision><revision><revnumber>1.2</revnumber><date>2001-06-13</date><authorinitials>TLT</authorinitials><revremark>Shane Gelven pointed out an error in the init script paths.</revremark></revision><revision><revnumber>1.1</revnumber><date>2001-05-29</date><authorinitials>TLT</authorinitials><revremark>Updated environment configuration section, changed HOWTO name.</revremark></revision></revhistory></artheader><sect1 id="copyright"><title>Copyright and License</title><para>This document is copyright 2001 by Tyson Lloyd Thwaites, and is released under the
terms of the GNU Free Documentation License, which is hereby incorporated
by reference. Send feedback to
<ulink url="mailto:tyson.lloydthwaites@ite.com.au"><citetitle>tyson.lloydthwaites@ite.com.au</citetitle></ulink>.</para></sect1><sect1 id="instlinux"><title>Install Linux</title><para>This howto assumes you have already installed a working Linux system.
This howto is based on a Redhat 6.2 system. I would appreciate any
feedback on setting this up on other distros.</para><para>The first thing you will have to do is uninstall the <filename moreinfo="none">apache</filename> 
and <filename moreinfo="none">mod_php</filename> rpms. Try the following:</para><programlisting format="linespecific">    # rpm -e apache
    # rpm -e httpd
    # rpm -e mod_php
    # rpm -e php</programlisting><para>That should get rid of them. Just to be sure, run this:</para><programlisting format="linespecific">    # rpm -qa | less</programlisting><para>and check that there is nothing to do with Apache or PHP
left on you system.</para></sect1><sect1 id="instsybase"><title>Install Sybase</title><para>Download the Sybase-ASE files from 
<ulink url="http://linux.sybase.com">linux.sybase.com</ulink>. Sybase-ASE 11.0.3.3 is
free for production. This howto refers to that version.</para><para>First, install the Sybase RPMS as root:</para><programlisting format="linespecific">    # rpm -ivh sybase-ase-11_0_3_3-6_i386.rpm
    # rpm -ivh sybase-doc-11_0_3_3-6_i386.rpm
    # rpm -ivh sybase-ocsd-10_0_4-6_i386.rpm</programlisting><para>For information on how to configure Sybase, read the instructions in the
file <filename moreinfo="none">/opt/sybase/doc/howto/howto-ase-quickstart.html</filename>. This document is very
good, so we shouldn't need any more information here.</para><note><title>Hint</title><para>After you have installed the sample database and run a select against it,
you can stop following the instructions. The rest of the howto goes on
to uninstall the sample database, but we want to keep it for testing later.</para></note><note><title>NOTE</title><para>Some people have reported problems with the way the Sybase init scripts
try to guess the Sybase directory. If you see the following error:</para><programlisting format="linespecific">    export: sybase-ase-11.0.3.3: not a legal variable name</programlisting><para>when trying to run sybinstall.sh, then you need to edit the sybinstall.sh.
Open the script and find the following lines (around line 104):</para><programlisting format="linespecific"># export SYBASE=/opt/sybase
export SYBASE=`rpm -q --queryformat \
		'%{installprefix}\n' sybase-ase-11.0.3.3`</programlisting><para>Change these lines so they look like this:</para><programlisting format="linespecific">export SYBASE=/opt/sybase
#export SYBASE=`rpm -q --queryformat \
#		'%{installprefix}\n' sybase-ase-11.0.3.3`</programlisting><para>This hardcodes the SYBASE path to /opt/sybase. If you did install Sybase somewhere
non-standard and you get this error, you will have to change this path to point to your
Sybase directory.</para></note></sect1><sect1 id="config"><title>Configure Environment</title><para>After installing Sybase, you need to setup the Linux environment in order
to allow clients to connect to the dataserver.</para><para>The first thing we need to do is to set certain environment variables in
<filename moreinfo="none">/etc/profile</filename>. Open <filename moreinfo="none">/etc/profile</filename>
as super user and insert the following lines:</para><programlisting format="linespecific">    export SYBASE=/opt/sybase
    export SYBPLATFORM=linux
    export LD_LIBRARY_PATH=$SYBASE/lib
    export LC_ALL=default
    export PATH="$SYBASE/bin:$PATH"
    export DSQUERY=SYBASE</programlisting><para>Next you need to change to permissions of the Sybase directory. This fixes
some problems where PHP is unable to connect to the Sybase server.
Run the following command as super user:</para><programlisting format="linespecific">chown -R sybase:sybase /opt/sybase</programlisting><para>To test whether your Sybase environment works, type the following:</para><programlisting format="linespecific">    # su - nobody
    $ isql -Usa -P
    1ent sp_helpdb
    2ent go</programlisting><para>You should see a list of databases. To test whether you can use the sample
datebase, now type:</para><programlisting format="linespecific">    1ent use pubs2
    2ent go
    1ent select * from titles
    2ent go</programlisting><para>If you a list, you have sucessfully set up Sybase.</para><note><title>NOTE</title><para>You may need to do the following in order for PHP to be able to access
Sybase. Edit the file /opt/sybase/install/rc.sybase and remove the line
that says:</para><programlisting format="linespecific">    unset LANG; unset LC_ALL; \ </programlisting><para>I don't know why that line is there, but it can stuff things up.</para></note><note><title>NOTE</title><para>Some people have reported problems with the way the Sybase init scripts
try to guess the Sybase directory. If you see the following error:</para><programlisting format="linespecific">    errorerwerqwerqwerwerwer
<para>when trying to run sybinstall.sh or rc.sybase, then you need to change</para></programlisting></note><para>You may also want to add sybase to the list of services to run at boot
time. To do this execute the following commands:</para><programlisting format="linespecific">    # ln -s /opt/sybase/install/rc.sybase /etc/rc.d/init.d/sybase
    # ln -s /etc/rc.d/init.d/sybase /etc/rc.d/rc3.d/S15sybase
    # ln -s /etc/rc.d/init.d/sybase /etc/rc.d/rc3.d/K15sybase</programlisting><para>Now Sybase will start whenever you boot into runlevel 3.</para><note><title>NOTE</title><para>The note for </para></note><sect2 id="preapache"><title>Preconfigure Apache</title><para>Download and unpack the latest Apache distribution. In the Apache
directory issue the following command:</para><programlisting format="linespecific">    # ./configure --prefix=/usr/local/apache</programlisting><para>I think the 'prefix' value specifies where you want to store your html files;
I just set it to the same as the apache install directory, where Apache will
put its files when you run '<command moreinfo="none">make install</command>'.</para></sect2></sect1><sect1 id="instphp"><title>Install PHP</title><para>Download the latest PHP distribution and unpack it.</para><para>Change to the <filename moreinfo="none">php</filename> directory and run the <command moreinfo="none">configure</command> 
script. You need to pass
certains options to the script. To enable PHP access Sybase, you
need <command moreinfo="none">--with-sybase-ct</command>. You will also need to specify the web server interface
to use; in our case, this is Apache, so we use <command moreinfo="none">--with-apache</command>
To build a CGI version of PHP, (which is also very useful as a shell scripting tool), just leave
out the --with-apache.</para><para>Here is a complete configure script with the above two options, as well as
a number of other options that are useful.</para><programlisting format="linespecific">    # ./configure --with-apache=../apache_1.3.19
      --with-sybase-ct=/opt/sybase --enable-bcmath --enable-calendar
      --enable-ctype --enable-exif --enable-ftp --enable-gd-imgstrttf
      --with-gd --enable-trans-sid --enable-shmop --enable-sockets
      --enable-sysvsem --enable-sysvshm --enable-wddx</programlisting><para>You will need to change to apache path to wherever you unpacked your apache
distribution.</para><para>If the configure scripts completes successfully, you can then proceed:</para><programlisting format="linespecific">    # make entent make install</programlisting><para>PHP should compile without any hitches. After it has installed, you need
to install the <filename moreinfo="none">php.ini</filename> file:</para><programlisting format="linespecific">    # cp php.ini-optimized /usr/local/lib/php.ini</programlisting><para>Now we need to change a few things in <filename moreinfo="none">/usr/local/lib/php.ini</filename>. Set the
following parameters to the ones specified below:</para><programlisting format="linespecific">    magic_quotes_sybase = on
    sybct.min_server_severity = 11
    sybct.min_client_severity = 11</programlisting><para>I also like to set the following:</para><programlisting format="linespecific">    register_globals = on
    include_path=.:/usr/local/lib/php</programlisting><para>You have now completed the PHP installation.</para></sect1><sect1 id="instapache"><title>Install Apache</title><para>Now <command moreinfo="none">cd</command> back into the apache unpack directory. Issue the following commmands:</para><programlisting format="linespecific">    # ./configure --activate-module=src/modules/php4/libphp4.a
    # make entent make install</programlisting><para>This should proceed without any problems. When its done, edit the file
<filename moreinfo="none">/usr/local/apache/conf/httpd.conf</filename> and uncomment the following line:</para><programlisting format="linespecific">    AddType application/x-httpd-php .php</programlisting><para>This tells apache to allow PHP to process files with a <filename moreinfo="none">.php</filename> extension. You
may also want to add some other extensions to the end of this line, eg:</para><programlisting format="linespecific">    AddType application/x-httpd-php .php .php3 .html .htm</programlisting><para>You now have all the software you need and are ready to test your system.</para></sect1><sect1 id="testsys"><title>Test the System</title><para>First, make sure Apache and Sybase are started:</para><programlisting format="linespecific">    # /usr/local/apache/bin/apachectl start
    # /opt/sybase/install/rc.sybase start</programlisting><para>Now go to the directory <filename moreinfo="none">/usr/local/apache/htdocs</filename>. 
Create a file called <filename moreinfo="none">test.php</filename> and insert the following contents:</para><programlisting format="linespecific">        ent?php
                $con = sybase_connect("SYBASE", "sa", "");
                sybase_select_db("pubs2");
                $qry = sybase_query("select * from titles", $con);

                echo sybase_result($qry, 1, 1);

                sybase_close($con);
        ?ent</programlisting><para>Save the file and then access the following URL in your browser:</para><programlisting format="linespecific">    http://localhost/test.php</programlisting><para>If you see some text, then congratulations! You have a complete
Linux/Apache/PHP/Sybase-ASE installation. If not...well, there you go. Make
sure you actually have installed the pubs2 database. If you are not sure, try
running:</para><programlisting format="linespecific">        # isql -Usa -P ent /opt/sybase/scripts/installpubs2</programlisting><para></para><para><ulink url="mailto:tyson.lloydthwaites@ite.com.au">Email me</ulink> if
you have any problems, corrections (please!) or additions, but please
do not email me unless you have tried everything in this howto!
Thanks.</para></sect1><sect1 id="postinst"><title>Post Install Tasks</title><para>After you have a working system, first of all, breath a deep sigh of satisfaction. 
(I also suggest eating something.) After this, there are a few post-install tasks you
should perform.</para><para>The FIRST thing you should do is change the password for the 'sa' user. By default this
password is blank. To set a password for sa, type the following in isql:</para><programlisting format="linespecific">        1ent sp_password null, 'new_pass123', 'sa'
        2ent go</programlisting><para>This will set the password. You will now need to pass this as a parameter to sybase_connect.
You will also need to specify it when starting isql, which you can do by using the '-P' switch.</para><note><title>NOTE</title><para>Once you have ste a password, you cannot unset it. (Sybase requires a minumum of six characters
in a password, so '' won't be accepted.)</para></note><para>You also may wish to install the Windows client tools. These can be found on a CD if you bought
a cope of ASE from Sybase. Otherwise, if you are using the free 11.0.3.3 version, you can download
a demo of ASE 12.0 for NT, and only install the 'ASE Plugin for Sybase Central', 'ASE ODBC Driver' 
and 'Sybase Central' components. </para><note><title></title><para>I am not sure of the licensing issues involved in using the client tools if you haven't purchased ASE.
Although I don't think it would be a problem, you should contact Sybase directly if you want to be sure.</para></note><para>I am open to more hints to put in this section.</para></sect1></article>

