old-www/LDP/LG/issue47/silva.html

407 lines
17 KiB
HTML

<!--startcut BEGIN header ==============================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML><HEAD>
<title>Developing Web Applications at Home - Part 1 LG #47</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
ALINK="#FF0000">
<!--endcut ============================================================-->
<H4>
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Developing Web Applications at Home - Part 1</font></H1>
<H4>By <a href="mailto:afsilva@liberty.edu">Anderson Silva</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<P ALIGN=LEFT STYLE="margin-bottom: 0in"> One of my favorite things
about linux is that it allows me to have a full-featured server at
home for a very small price. I have a 3 computer network at home, and
my router is a simple Intel Pentium 133 w/ 32 MB RAM and 1.7 Gb HD.</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"> That machine which run on
Red Hat 6.0 is my router, dns server, firewall/proxy server, samba
server, and my web server, and it runs great. I must tell you that
the only reason that I shut that server off is when there are
thunderstorm warning in my city, but other than that the machine runs
flawless.</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"> And the reason for this
article is to allow you to run your own web applications of your
computer, even if your machine is a small Pentium 133 like mine. I
normally, write articles that are aimed for the newbies simply
because I think they need much more support than the &quot;older&quot;
guys do, and this article is no different.</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"> I would like to introduce
to you a scripting language called PHP. And for you that prefer
another language such as PERL, ASP or Cold Fusion, all I can say is
&quot;don't get mad at me just because I did not choose your
favorite language&quot;.</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"> PHP is a server dependent
scripting language that can be embedded on HTML, and according to its
documentation it was created &quot;sometime in the fall of 1994&quot;.
If you decide to play around with PHP you will notice that its syntax
is very similar to C, so if you have any programming experience with
C, C++ or even Java, programing on PHP should be a breeze.
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"> The greatest thing about
PHP is that it allows you to make web sites that will interface with
several types of databases. A few examples are:</P>
<UL>
<UL>
<UL>
<UL>
<LI><P ALIGN=LEFT STYLE="margin-bottom: 0in">Oracle</P>
<LI><P ALIGN=LEFT STYLE="margin-bottom: 0in">Sybase</P>
<LI><P ALIGN=LEFT STYLE="margin-bottom: 0in">mSQL</P>
<LI><P ALIGN=LEFT STYLE="margin-bottom: 0in">MySQL</P>
<LI><P ALIGN=LEFT STYLE="margin-bottom: 0in">ODBC</P>
<LI><P ALIGN=LEFT STYLE="margin-bottom: 0in">dBase</P>
<LI><P ALIGN=LEFT STYLE="margin-bottom: 0in">and many others...</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"></P>
</UL>
</UL>
</UL>
</UL>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"> This article will show you
how to install PHP version 3 (PHP3) on a RedHat System that is using
MySQL as its database. <B>Note:</B><SPAN STYLE="font-weight: medium">
RedHat's full install will install PHP3 all ready to work with
PostgreSQL database.</SPAN></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"><BR>
</P>
<OL TYPE=I>
<LI><P ALIGN=LEFT STYLE="margin-bottom: 0in"><FONT SIZE=4><SPAN STYLE="font-weight: medium">Installing
MySQL:</SPAN></FONT></P>
<OL>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"></P>
</OL>
</OL>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"> You
can download MySQL from:</P>
<OL TYPE=I>
<OL>
<OL>
<OL>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"><A HREF="http://www.mysql.com/download_3.22.html"><SPAN STYLE="font-weight: medium">http://www.mysql.com/download_3.22.html</SPAN></A></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"></P>
</OL>
</OL>
</OL>
</OL>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"><SPAN STYLE="font-weight: medium"> If
you are running Red Hat, I would recommend to you to download the
RPMs for the database. Download:</SPAN></P>
<OL>
<LI><P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium">
The Server - MySQL-3.22.27-1.i386.rpm</P>
<LI><P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium">
The Client - MySQL-client-3.22.27-1.i386.rpm</P>
<LI><P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium">
The Development Libraries - MySQL-devel-3.22.27-1.i386.rpm</P>
</OL>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"> <B>Note:</B>
MySQL 3.22.27 is the most recent-stable version as of the day this
article was written.</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"> Once
you have downloaded all three files, run the following command as
root:</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"> <B>rpm
-ihv MySQL-*</B></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"><B> </B><SPAN STYLE="font-weight: medium">This
should install all of the MySQL packages you have downloaded.</SPAN></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<OL TYPE=I START=2>
<LI><P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=4>Learning
MySQL:</FONT></P>
</OL>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=4> <FONT SIZE=3>Learning
the basics of MySQL should not be a challenge because of two main
reasons:</FONT></FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<OL>
<LI><P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium">
<FONT SIZE=3>Online Documentation is very well organized, and
helpful.</FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3>It can
be found at: <A HREF="http://www.mysql.com/doc.html">http://www.mysql.com/doc.html</A></FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"></P>
<LI><P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium">
<FONT SIZE=3>Graphical User Interfaces that are available on
the web to make MySQL administration much easier. </FONT>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3>You
can find a whole list of GUI Clients for MySQL at:
<A HREF="http://www.mysql.com/Contrib/">http://www.mysql.com/Contrib/</A></FONT></P>
</OL>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<OL TYPE=I START=3>
<LI><P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=4>Installing
PHP3:</FONT></P>
</OL>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=4> <FONT SIZE=3>As
I said in the beginning of this article RedHat already comes with the
RPM for the installation of PHP3, but by default it is setup to
support PostgreSQL. And to make this RPM work with MySQL is not hard
at all, thanks to great F.A.Q. whic can be found at the PHP official
web site (http://www.php.net). </FONT></FONT>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3> To
solve this problem I quote the F.A.Q. section from the PHP web site.</FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium">
</P>
<BLOCKQUOTE>
<P> 3.3 I installed PHP using RPMS, but it doesn't compile with the
database support I need! What's going on here?</P>
<P> Due to the way PHP
is currently built, it is not easy to build a complete flexible PHP
RPM. This issue will be addressed in PHP4. For PHP, we currently
suggest you use the mechanism described in the INSTALL.REDHAT file in
the PHP distribution. If you insist on using an RPM version of PHP,
read on...
<P> Currently the RPM packagers are setting up the RPMS to install
without database support to simplify installations AND because RPMS use
/usr/ instead of the standard /usr/local/ directory for files. You need
to tell the RPM spec file which databases to support and the location
of the top-level of your database server.</P>
<P>This example will explain the process of adding support for the
popular MySQL database server, using the mod installation for
Apache.</P>
<P>Of course all of this information can be adjusted for any database
server that PHP supports. I will assume you installed MySQL and
Apache completely with RPMS for this example as well. </P>
<P>First remove mod_php3
<P> rpm -e mod_php3
<P> Then get the source rpm and INSTALL it, NOT --rebuild
<P> rpm -Uvh mod_php3-3.0.5-2.src.rpm
<P> Then edit the /usr/src/redhat/SPECS/mod_php3.spec file
<P> In the %build section add the database support you want, and the
path.
<P> For MySQL you would add --with-mysql=/usr \
<P> The %build section will look something like this:
<P> ./configure --prefix=/usr \
<P> --with-apxs=/usr/sbin/apxs \
<P> --with-config-file-path=/usr/lib \
<P> --enable-debug=no \
<P> --enable-safe-mode \
<P> --with-exec-dir=/usr/bin \
<P> --with-mysql=/usr \
<P> --with-system-regex
<P> Once this modification is made then build the binary rpm as
follows:
<P> rpm -bb /usr/src/redhat/SPECS/mod_php3.spec
<P> Then install the rpm
<P> rpm -ivh /usr/src/redhat/RPMS/i386/mod_php3-3.0.5-2.i386.rpm
<P> Make sure you restart Apache, and you now have PHP with MySQL
support using RPM's. Note that it is probably much easier to just
build from the distribution tarball of PHP and follow the instructions
in INSTALL.REDHAT found in that distribution.
</BLOCKQUOTE>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3> Another
problem is that some distributions (including RedHat) that also come
with PHP3 installed, don't have PHP3 activated on Apache's
configuration file. To solve this problem again we count on the PHP3
F.A.Q. session.</FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"><FONT FACE="helvetica, sans-serif"><FONT SIZE=2><B> </B></FONT></FONT></P>
<BLOCKQUOTE>
I installed PHP using RPMS, but Apache isn't processing the PHP
pages! What's going on here? Assuming you installed Apache PHP
completely with RPMS, you need to uncomment or add some or all
of the following lines in your http.conf file:
<PRE>
# Extra Modules
AddModule mod_php.c
AddModule mod_php3.c
AddModule mod_perl.c
# Extra Modules
LoadModule php_module modules/mod_php.so
LoadModule php3_module modules/libphp3.so
LoadModule perl_module modules/libperl.so
</PRE>
<P> And add:<BR>
<TT>AddType application/x-httpd-php3 .php3</TT><BR>
To the global properties, or to the properties of the VirtualDomain
you want to have PHP support added to.
</BLOCKQUOTE>
<P> If you have successfully installed MySQL, re-installed PHP3, and
activated PHP3 in you Apache configuration you should be all set to
start using PHP3.</FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3> <B>Note:
Once you are done changing the Apache configuration make sure you
restart it.</B></FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"><FONT SIZE=3><B> Quick Test:</B></FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3> This
is a quick test for you to try, and see if php3 is running correctly
in your system:</FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3> Go
to your web root directly (RH systems at: /home/httpd/html), and
create the following file and name it <B>phptest.php3</B>.</FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3> &lt;?</FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3> echo
&quot;&lt;HTML&gt;\n&quot;;</FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3> echo
&quot;&lt;HEAD&gt;&lt;TITLE&gt;Hello World!&lt;/TITLE&gt;&lt;/HEAD&gt;\n&quot;;</FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3>
echo &quot;Testing PHP3 with Hello World!\n&quot;;</FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3>
?&gt;</FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3> And
the open you web browser, and you should get just the formatted web
site. If you do get that, you should be all set to start using PHP3.
If you have not been able to get the right results, I would suggest
you to check out PHP's web site at: <A HREF="http://www.php.net/">http://www.php.net</A></FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3> Next
month, I will send in a couple of more complex examples with some
data entry on a MySQL database.</FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3> </FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3>The
texts that are found inside a table were extracted from the PHP3 Web
Site.</FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<DL>
<DD>
<TABLE WIDTH=413 BORDER=1 BORDERCOLOR="#000000" CELLPADDING=4 CELLSPACING=0>
<COL WIDTH=403>
<THEAD>
<TR>
<TD WIDTH=403 VALIGN=TOP>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3>PERMISSION
NOTICE:
</FONT>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3>Javascript/PHP
code used with permission of the PHP </FONT>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3>Development
Team.
</FONT>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3>Copyright
1998. All rights reserved.
</FONT>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3>
</FONT>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3>For
more information on the PHP Development Team and
</FONT>
</P>
<P ALIGN=LEFT STYLE="font-weight: medium"><FONT SIZE=3>the PHP
project, please see &lt;http://www.php.net&gt;. </FONT>
</P>
</TD>
</TR>
</THEAD>
</TABLE>
</DL>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3>
</FONT>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3> </FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><FONT SIZE=3> </FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in; font-weight: medium"> </P>
<OL TYPE=I>
<OL>
<OL>
<OL>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"></P>
</OL>
</OL>
</OL>
</OL>
<P ALIGN=CENTER STYLE="margin-bottom: 0in"><BR>
</P>
</BODY>
</HTML
<!-- BEGIN copyright ==================================================-->
<P> <hr> <P>
<H5 ALIGN=center>
Copyright &copy; 1999, Anderson Silva<BR>
Published in Issue 47 of <i>Linux Gazette</i>, November 1999</H5>
<!-- END copyright ===================================================-->
<!--startcut footer ===================================================-->
<P> <hr> <P>
<A HREF="index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="reid.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="../faq/index.html"
><IMG SRC="./../gx/dennis/faq.gif"
ALT="[ Linux Gazette FAQ ]"></A>
<A HREF="slambo.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
</BODY></HTML>
<!--endcut ============================================================-->