Basic Install question

I’m struggling with the instruction in the postgres install doc. The following is from the doc:

10. Unzip and untar the new source file. Type

     $ cd /usr/src/pgsql
     $ gunzip -c ~/postgresql-v6.5.3.tar.gz | tar xvf -

 11. Configure the source code for your system. It is this step at which you
     can specify your actual installation path for the build process (see
     the --prefix option below). Type

     $ cd /usr/src/pgsql/src
     $ ./configure [ options ]

If I follow those instruction I get /usr/src/pgsql/postgresql-6.5.3/src. Notice the ugly extra directory added in the middle.
Did I do something wrong or did the authors make a mistake or do they just assume I’ll just accept the discrepancy.

I followed the directions and it works. It’s just that I get worried if things don’t go as it looks like they should.

Also why do they always use:
gunzip -c ~/postgresql-v6.5.3.tar.gz | tar xvf -
Is not tar –xvzf postgresql-v6.5.3.tar.gz the same thing and neater looking?

I’m trying to put together some directions for some people in my company that are new to linux so I would prefer to make the directions as easy to follow as possible?
Who is Participating?
jlevieConnect With a Mentor Commented:
I'd like to suggest a change or two. As soon as the postgres user has been created, edit postgres' shell init file for the Postgres specific env vars and "chown -R postgres:postgres postgres-6.5.3. Also make the postgres installation dir (/usr/local/pgsql) and make it owned by the postgres admin (mkdir /usr/local/pgsql; chown postgres:postgres /usr/local/pgsql). Then "su - postgres" and "cd /home/public/postgres-6.5.3/src" before the "./configure --with-tcl", etc. The Postgres install docs actually tell you to be the postgres user before the configure & build.

As to using the PHP CVS vs the tarball. I suspect that most folks who are playing with 4.0 are using the CVS tree as it's more up to date and thus has more bugfixes in it. The 4.0 distribution isn't intended for production use just yet, and in fact is labeled as a "Release Candidate".
My guess is that they just forgot the extra directory.  You could try listing the contents of the tar file as well (tar -ztf postgresql-v6.5.3.tar.gz), see if it shows everything inside the postgresql-6.5.3 directory that was created (It should show it).  That's a pretty common practice for distributions just so that when you upgrade to a new distribution it's in a seperate directory and thus you can go back to the old version easier if the new one doesn't work.  As for just using tar rather than piping gunzip through tar, theoretically it SHOULD work.  I can't remember offhand what the -c switch is though in gunzip.
davidpmAuthor Commented:
Thank you for your comments
The -c is "Write output on standard output; keep original files unchanged.

I cann't help but wonder if there isn't a gunzip syntex that eliminates the top level postgresql-v6.5.3 directory and puts the contents in /usr/src/pgsql

Also I'm concerned that tar –xvzf syntax may leave the resulting files in a slightly different state perhaps with permission or such.
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

The tar file was created one directory level above the postgres distribution dir (postgresql-6.5.3), so when unpacked it will create a postgresql-6.5.3 directory (and its sub-dirs) where ever you are in the filesystem. There's nothing magic about where you unpack the distribution, you can put the sources any where that you've got room. The folks that wrote the docs seem to like to use /usr/psql, I have a "sources" disk so I unpack it to /sources/db/postgresql-6.5.3. Also there's nothing magic about the default directory that postgres will be installed to after it's build. The default form configure will use /usr/local, but you can change that with "./configure --prefix=/path-to/postgres".

Having a tar contain a distribution encapsulated in a directory is a "good thing". If you ever accidentally unpack a distribution that doesn't have a top-level directory while in some source dir and have it mix all of the files in the tarball with what's already in that dir, you'll become very fond of the way the postgres folks did it (ask me how I know...).

Yes "tar xvzf some.tar.gz" is neater than "gunzip -c some.tar.gz | tar xvf -". The reason that both forms are shown is that not all versions of tar support "decompression on the fly" (the z flag). Linux uses gnu tar which does support that feature, but most mainstream OS's (Solaris, Irix, etc) don't.

BTW, I couldn't tell from the question... Did you get postgres built & installed & running okay?
davidpmAuthor Commented:
So you found me once again. And I don't have to ask you how you know about the missing top-level directory issue. I have a vivid imagination.

The following is what I got out of your last comment. Please correct as necessary.
1. If a tar file is created with a top-level directory eg: postgresql-6.5.3. There is no way to untar it without creating that directory.
2. The Postgress Install doc authors either made a technical error or more likely the assumption that their readers would understand the normal behavior of tar and automatically substitute actual directory entries.
3. The following commands are a technically accurate rewording of the Install doc suitable for use on redhat 6.1:
cd /usr/src
tar -xvzf /path-to/postressql-v6.5.3.tar.gz
chown postgres:postgres /usr/src/postgresql-6.5.3
cd /usr/src/postgresql-6.5.3/src
su postgres
../configure [options]
4. The tar -xvzf may be used interchangeable with the gunzip | tar syntax
5. The location the (in this case /usr/src/postgresql-6.5.3) does not matter at all as long as there is room)
6. make install will copy the binary's to /usr/local/pgsql unless the following syntax is used in the ./configure step. ./configure --prefix=/path-to/postgres.

By the way what is the difference between the tar ball I downloaded and another one I saw on the web site labeled a source distribution that had a src in the file name. I got the source with mine didn't I?

Yes it did install. The reason I'm being so picky is because I'm preparing documentation for others.
For Items 1-6, totally correct on all counts. With the caveat that we are only talking about Linux (w/regards to gzip/tar). I just looked on the master ftp site for Postgres ( and I don't see a tarball with "src" in the name. Where were you looking? And yes you got the source distro.

Are you also doing Apache, etc? I'm not sure how it's going to come out pasted into a comment, but what follows are the kinds of simplified install docs I create for things like an Apache+SSL+PHP installation.

Standard server is built with SSL & Php/database/ldap/imap support.
Everything is built with gcc-2.95.2, earlier versions are suspect on
Solaris 7/8. The following describes the packages & dependencies
as of 8 Mar 00:

Apache 1.3.12             -
Mod SSL 2.6.2-1.3.12      -
  OpenSSL 0.9.5           -
  Mm 1.0.12               -
Php 3.0.15                -
  Openldap-1.2.9          -
    db-2.7.7 (BerkeleyDB) -
  Imap (c-client)         -
  Postgres 6.5.3          -
  MySQL-3.22.32           -

1. Configure, build & install openssl

   > cd openssl-0.9.5
   > ./Configure solaris-sparcv[8|9]-gcc \   # Solaris Sparc/Ultra
   > ./Configure linux-elf \                 # Linux i386
   > ./Configure linux-sparcv[8|9] \         # Linux Sparc/Ultra
   > --prefix=/opt/Openssl -DSSL_FORBID_ENUL
   > make
   > make test
   > make install

2. Configure & build Mm

   > cd mm-1.0.12
   > ./configure --disable-shared
   > make

4. Configure mod-ssl

   > cd ../mod_ssl-2.6.2-1.3.12/
   > ./configure --with-apache=../apache_1.3.12

5. Now configure, build, and install Apache

   > cd apache_1.3.12
   > SSL_BASE=../openssl-0.9.5 EAPI_MM=../mm-1.0.12 \
   > ./configure --prefix=/opt/Apache \
   > --enable-module=most --enable-shared=max \
   > --enable-module=ssl --enable-shared=ssl --enable-rule=SSL_SDBM
   > make
   > make install
6. (optional) Configure and Build c-client IMAP libs

   > cd imap-4.7b
   > make gso       # Gcc Solaris - see Makefile
   > make lnp       # Linux w/PAM - see Makefile
   > cd c-client
   > mkdir include
   > cp *.h include
   > mkdir lib
   > cd lib
   > ln -s ../c-client.a libc-client.a

7. (optional) And the LDAP libs (we get everything, but only use the libs)
   and I assume that BerkeleyDB is installed.

   > cd openldap-1.2.9
   > CPPFLAGS=-I/usr/local/BerkeleyDB/include \ # Solaris
   > LDFLAGS=-L/usr/local/BerkeleyDB/lib \      # Solaris
   > LIBS="-lpthread -lposix4" \                # Solaris
   > ./configure --prefix=/opt/Ldap
   > make depend
   > make
   > make install

8. Now we can build Php. The assumption is that the database is already built
   and installed. I put 'em in /opt.

   > cd php-3.0.15
   > ./configure --with-apxs=/opt/Apache/bin/apxs --without-gd \
   > --with-mysql=/opt/Mysql \           # Optional MySQL
   > --with-pgsql=/opt/Postgres \        # Optional Postrgres
   > --with-ldap=/opt/Ldap \             # Optional LDAP
   > --with-imap=../imap-4.7b/c-client \ # Optional IMAP
   > --with-config-file-path=/opt/Apache/conf
   > make
   > make install
   > cp php3.ini-dist /opt/Apache/conf/php3.ini

   On Solaris watch out for the LDAP library search path (-L/opt/Ldap/lib)
   getting placed after the libraries (-lldap -llber), configure can
   botch it. Fix by re-arrainging in the top-level Makefile.

9. Check where the php modules are in the Apache conf file. They will wind
   up in an SSL conditional and should be at the global level.

10.Create a certificate. I use a temp dir in the Apache conf dir.
   After I create the certificate I move it to the ssl.* dirs
   using the real or virtual server name, e.g.,>chaos.*
   This is a locally signed certificate. For a real server you'll need
   to get a real certificate from a "Certificate Authority", like Verisign.

   > cd /opt/Apache/conf
   > mkdir ssl.tmp
   > cd ssl.tmp
   > /opt/Openssl/bin/openssl req -new >host.csr
   > /opt/Openssl/bin/openssl rsa -in privkey.pem -out host.key
   > /opt/Openssl/bin/openssl x509 -in host.csr -out host.cert -req \
   > -signkey host.key -days 365
   > mv host.cert ../ssl.crt/chaos.crt
   > mv host.csr ../ssl.csr/chaos.csr
   > mv host.key ../ssl.key/chaos.key

davidpmAuthor Commented:
Adjusted points from 20 to 100
davidpmAuthor Commented:
Well now you have gone and done it. You guessed exactly where I was going with this. Actually for this first pass I'll be happy with Apache, PHP4, Postgres I'll add security after I get the basics working. I did the following steps. And it WORKED. I reworked the order a bit to what I thought was likely to work so I'll have to try it again from scratch to make sure. Please make sure I didn't skip anything that will be necessary later or add any unnecessary steps. Thanks!!!!
1.      Installed RH 6.1 with default packages plus development packages
2.      copy postgresql-6.5.3.tar.gz to /home/public
3.      cd /home/public
4.      tar –xvzf postgresql-6.5.3.tar.gz
5.      vi /etc/groups
6.      adduser postgres
7.      passwd postgres
8.      cd /home/public/postgresql-6.5.3/src
9.      ./configure –with-tcl
10.      make
11.      mkdir /usr/local/pgsql
12.      make install
13.      chown postgres:postgres /usr/local/pgsql
14.      vi /etc/
15.      Add line: /usr/local/pgsql/lib
16.      /sbin/ldconfig (it takes a few seconds to complete please wait)
17.      su postgres
18.      cd /usr/local/pgsql
19.      vi  ~/.bash_profile
20.      Add following lines then save and exit:
21.      initdb
22.      ./postmaster –i &
23.      ./createdb test1
24.      ./psql (you should get a postgres=> prompt
25.      select datetime ‘now’;
26.      You should get a one row answer
27.      startx (start terminal window)
28.      /usr/local/pgsql/bin/pgaccess test1
29.      Create a table, fields add data etc.
30.      Take break and then start on Apache

davidpmAuthor Commented:
Oops kill line 5. The redhat adduser command creates a group automatically.
That's pretty good. I'd consider adding the instructions somewhere near the end for creating an init file in /etc/rc.d/init.d and arrainging to have it executed at system boot time to auto-start postgres.

You might also want to look at /usr/local/pgsql/data/pg_hba.conf as it determines whether access is allowed and by whom from other systems. Also you'll want to create db users and/or databases for applications, but that might be wholly known at the time postgres is installed.

Another item would be to consider building & installing either Postgres' perl support (in postgresql-6.5.3/src/interfaces/perl5) or the DBI/DBD implementations from CPAN.
davidpmAuthor Commented:
That's pretty good. I'd consider adding the instructions somewhere near the end for creating an init file in /etc/rc.d/init.d and arrainging to have it executed at system boot time to auto-start postgres.

What would that look like? I absolutely need to do that. Will look at the other too asap.
davidpmAuthor Commented:
I followed the following steps:
29.      Start on Apache
30.      copy apache_1.3.12.tar.gz to /home/public
31.      cd /home/public
32.      tar –xvzf apache_1.3.12.tar.gz
33.      cd /home/public/apache_1.3.12
34.      ./configure –prefix=/usr/local/apache \
--enable-module= most \
35.      make
36.      make install
37.      /usr/local/apache/bin/apachectl start  (that’s an L at the end of apachect)
38.      From another computer put the ip address of this computer in find box of a web browser to test if apache is running.
39.      Start installing PHP
40.      copy php-4.ORC1.tar.gz to /home/public
41.      cd /home/public
42.      tar –xvzf php-4.ORC1.tar.gz
43.      cd /home/public/php-4.ORC1
44.      ./configure --with-apxs=/usr/local/apache/bin/apxs \
45.      make

The make command for php4 gave me the following error:
make[3]: Entering directory `/home/public/php-4.0RC1/ext/pgsql'
/bin/sh ../../libtool --silent --mode=compile gcc -DHAVE_CONFIG_H -I. -I/home/public/php-4.0RC1/ext/pgsql -I../.. -I../../Zend -I/home/public/php-4.0RC1 -I/usr/local/apache/include -I/home/public/php-4.0RC1/ext/mysql/libmysql -I/usr/local/pgsl/include -I/home/public/php-4.0RC1/ext/xml/expat/xmltok -I/home/public/php-4.0RC1/ext/xml/expat/xmlparse -I/usr/local/pgsl/include -DXML_BYTE_ORDER=12 -D_REENTRANT -g -O2 -Wall  -c pgsql.c
In file included from pgsql.c:31:
php_pgsql.h:46: libpq-fe.h: No such file or directory
php_pgsql.h:52: libpq/libpq-fs.h: No such file or directory
make[3]: *** [pgsql.lo] Error 1
make[3]: Leaving directory `/home/public/php-4.0RC1/ext/pgsql'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/public/php-4.0RC1/ext/pgsql'
make[1]: *** [all] Error 1
make[1]: Leaving directory `/home/public/php-4.0RC1/ext'
make: *** [all-recursive] Error 1

I checked for the files it could not find. They are in:
In past runs I tried cp the files to another location but it just starts complaining about other files then. I thought my with-pgsql path was supposed to take care of this. In any event what do I do next?
davidpmAuthor Commented:
did i see a type in the error message whey it was looking for /usr/local/pgsl instead of pgsql
If that's it how do I fix it?
davidpmAuthor Commented:
I added a link like this that got me a little further:
ln –s /usr/local/pgsql /usr/local/pgsl

Now when I run make I get the following error:
make[3]: Entering directory `/home/public/php-4.0RC1/ext/standard'
/bin/sh ../../libtool --silent --mode=compile gcc -DHAVE_CONFIG_H -I. -I/home/public/php-4.0RC1/ext/standard -I../.. -I../../Zend -I/home/public/php-4.0RC1 -I/usr/local/apache/include -I/home/public/php-4.0RC1/ext/mysql/libmysql -I/usr/local/pgsql/include -I/home/public/php-4.0RC1/ext/xml/expat/xmltok -I/home/public/php-4.0RC1/ext/xml/expat/xmlparse  -DXML_BYTE_ORDER=12 -D_REENTRANT -g -O2 -Wall
-c basic_functions.c
basic_functions.c:324: `php_if_dl' undeclared here (not in a function)
basic_functions.c:324: initializer element for `basic_functions[201].handler' is not constant
basic_functions.c: In function `php_info_basic':
basic_functions.c:708: warning: implicit declaration of function `php_info_dl'
make[3]: *** [basic_functions.lo] Error 1
make[3]: Leaving directory `/home/public/php-4.0RC1/ext/standard'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/public/php-4.0RC1/ext/standard'
make[1]: *** [all] Error 1
make[1]: Leaving directory `/home/public/php-4.0RC1/ext'
make: *** [all-recursive] Error 1

This one I don't get at all
davidpmAuthor Commented:
Adjusted points from 100 to 150
davidpmAuthor Commented:
Of course I still need to know how to make sure all this stuff starts properly at bootup
For postgres most everything is already done for you. Look in postgresql-6.5.3/contrib/linux. There's a "self installing" init script there. For apache, you can roll your own pretty

The first time clearly showed configure botching the definition of where the postgres installation is. I'm just now starting a php-4.0 installation (following a complete reconstruction of a system that experienced a SCSI controller meltdown... read dead, really, really dead, as in hang the bus at POST), so I don't yet know what's happening there. postgres is building as I write this, so I should be able to play with it shortly.
Sorry for the dangling thing about apache. I got distracted when composing the comment. More shortly...
davidpmAuthor Commented:
I'm waiting and hoping the family stays at church a little late this morning<g>.
Okay, I don't get the same configure problem that you had. I normally put things like Postgres, MySQL, Apache, Acrobat, Netscape, etc in /opt, so I used:

../configure --with-pgsql=/opt/Postgres --with-apxs=/opt/Apache/bin/apxs

And it did the right thing w/respect to the include files. I do get the same compile errors in basic_functions.c and I'm looking at that now.
I chickened out and downloaded the latest copy via CVS from the PHP site. It compiles, installs and runs. So, why don't you try that.

Their instructions on the CVS info page are close, but not quite complete. After checking out php4 (which will create the dir ./php4), change to that dir before checking out Zend and TSRM or make will fail.
davidpmAuthor Commented:
You had better luck than me. I did the following steps logged in as root:
1. cd /home/public
2. mkdir php4-cvs
3. cd php4.cvs
5. vi ~/.cvsrc
6. Added
cvs -z3
update -d -p
checkout -p
diff -u
7. cvs -d login
8. enter login ps of phpfi
9. cvs -d co php4
10. A zillion lines of code flash by then it stops. I can find no php4 directory.
davidpmAuthor Commented:
oops typo in line 3 it was cd php4-cvs
davidpmAuthor Commented:
Adjusted points from 150 to 200
davidpmAuthor Commented:
It always stops scrolling the screen at the same place.
after the void openlog function code
davidpmAuthor Commented:
I used checkout -p instead of checkout -P (capital P)
I'm re-running the download now. Am hoping.
Well, if you get the CVS options wrong...
davidpmAuthor Commented:
Adjusted points from 200 to 250
davidpmAuthor Commented:
I'm not 100% sure I know exactly what I did but phpinfo() fired up.
If you don't mind I would like to keep the thread open because I've still got a ways to go.
I got postress to autostart based on your sugestion.
The following are remaining questions and components.
1. autostart apache
2. phpinfo() reports mysql support included even though I did not ask for it. Is this ok and/or expected.
3. Under Additional modules it show one word only "pgsql". I need to find out if the postgress support is really there.
4. In your example ./configure options you have without gd. Why?
5. Build simple page that can add, edit delete rows from a postgress table.

davidpmAuthor Commented:
I could not find any posts in www.phpbuilder forum that sugested any problems like I had with the .tar.gz file. I'm wondering why I had a typo in an include line where you did not and why we both had function errors.

What does make clean do? I just tried it in the php4 directory and after that command is when I was able to make it go through properly.

When I was getting errors with make I tried make > error.txt but I got everything put the error. I used cut and past with the mouse but how with > can I get errors, all including errors?

Thank you again for your patience.
davidpmAuthor Commented:
If you have experience with mySql and Postgress I'm interested in your comments. I'm aware that this is a hot issure for some folks but I'm just interested in real world experience good or bad.
My, my, you are certainly a busy hacker today...

As to apache auto-start, I've got it on a system that I can't get to from here and will have to wait until I'm at work.

Yes, PHPH 4.0 will show MySQL and it's not a problem. If pgsl is shown, then yes, you've included support for Postgres and it should work. Since I had to set everything up from scratch on my system I don't have any quickee examples handy to verify that it functions, but it should.

I don't include gd on Solaris as it usually won't work on any of my servers. It seems to be fine on Linux and I should update that with a note.

"make clean" is a fairly standard target that will remove everything that results from a "make" or "make all". It removes objects, executables, etc., and puts you back in a position to compile everything. You'd want to do this if you'd changed something (a header file, config option, etc) that affected the entire application. The other time to use "make clean" (or "make distclean" if supported) is to clean up the distribution directory to recover space used by the obj's & exe's after a "make install".

Redirection of stdout, which is what "make > error.txt" does, doesn't redirect stderr. That's a "good thing" as you can still see error messages with stdout redirected to a file. To have everything (stdout & stderr) redirected to a file you'd use "make >& error.txt" or "make 2>&1 error.txt". The second form is technically more correct, but either will work on most Unixen.

MySQL vs Postgres... I use both. MySQL is very popular, especially for Web apps as it's very, very fast. Postgres is a bit more SQL standard compliant and for the most part anything you'd do in Postgres in an SQL script will work with little or no modification on Oracle, Informix, etc. MySQL takes a few liberties with the SQL standard to make common tasks that web apps need to do a bit easier. So it depends on how you want to use the DB. For applications that will be primarily a Web interface, I use MySQL. For those that will see a significant amount of use other than from a Web interface, or that might later need to move to a commercial DB, I'm likely to use Postgres. Both DB's have been geting better and better over the last several years, so there's less difference between them now. MySQL is still the speed king for typical Web use, and I find that I'm using it more.
davidpmAuthor Commented:
I've started over with a new installation just to make sure my notes are accurate and I really understand each step. I discovered the following:
After these steps
17. su postgres
18. cd /usr/local/pgsql
19. vi  ~/.bash_profile
20. Add following lines then save and exit:
initdb did not work because the $PGLIB variable was not available.
It worked fine when I logged out and logged in as user postgres.

Is it true that when you su to a user you do not get that users environment?
Is there a way to get the environment of the target su user?
I also noticed that a su postgres did not ask for a password.
Some times su asks for a password sometimes not why?
Steps 19 and 20 are fairly tedious but seem necessary is that true?

I tried the startup scrip that a rpm installed apache created but it did not work for my tar.gz insalled version.
I belive you said you have a starup apache script at work?
Thanks again
You don't execute a users .bash_profile, and thus get the env vars set unless you tell su to do so via "su - some-user".

You won't get prompted for a password if you are su'ing to some user from root's account. When logged in as anyone but root you'll be prompted for a password.

Yes, having to modify everybody's startup scripts is a pain. But, there's an easier way. I'll email you some files and instructions for their use this evening (and a usable apache init script).
davidpmAuthor Commented:
That's exactly what I did.
I followed these steps
login root
su postgres
vi ~/.bash_profile
PGDATA is defined
exit vi
does not display var PGDATA
exit to get to root
exit to re-login
Login as postgres
It now displays the $PGDATA path
I checked the book and found the following
Login root
su - postgres (that's a space both sides of the -)
Aparently the standard su without the - does not give you the whole target users environment just HOME, SHELL, USER, LOGNAME and that's it. At least that's what I get out of the doc.
Tricky yes?
Looking forward to your startup scripts.
davidpmAuthor Commented:
I started all over again with a fresh format under the theory that once may be just lucky. Twice may be the indication of a working plan. The following steps worked.
My next goal is to:
1. Install MySql
2. Startup script for Apache and MySql
3. Actually read and write to Postgres and MySql tables from PHP.
I am still not happy about having to use a cvs release of PHP4 and not being able to use the tarball. I checked phpbuilder and their does not seem to be a anyone else experiencing this except me so I am puzzled and feel like I'm missing something.

1.      Installed RH 6.1 with default packages plus development packages
2.      copy postgresql-6.5.3.tar.gz to /home/public
3.      cd /home/public
4.      tar –xvzf postgresql-6.5.3.tar.gz
5.      adduser postgres
6.      passwd postgres (type in new pw twice)
7.      cd /home/public/postgresql-6.5.3/src
8.      ./configure –with-tcl
9.      make
10.      mkdir /usr/local/pgsql
11.      make install
12.      chown postgres:postgres /usr/local/pgsql
13.      vi /etc/
14.      Add line: /usr/local/pgsql/lib
15.      /sbin/ldconfig (it takes a few seconds to complete please wait)
16.      su postgres
17.      vi  ~/.bash_profile
18.      Add following lines then save and exit:
19.      exit
20.      su – postgres (there is a space on both sides of the -)
21.      cd /usr/local/pgsql/bin
22.      initdb
23.      ./postmaster –i &
24.      ./createdb test1
25.      ./psql test1 (you should get a postgres=> prompt
26.      select datetime ‘now’;
27.      You should get a one row answer
28.      \q to quit gsql
29.      startx (start terminal window)
30.      /usr/local/pgsql/bin/pgaccess test1
31.      Create a table, fields add data etc.
32.      exit xwindows
33.      exit (back to root)
34.      cd /home/public/postgresql-6.5.3/contrib/linux
35.      sh install  (postgres will start automatically on bootup)
36.      *****************
37.      Start on Apache
38.      copy apache_1.3.12.tar.gz to /home/public
39.      cd /home/public
40.      tar –xvzf apache_1.3.12.tar.gz
41.      cd /home/public/apache_1.3.12
42.      ./configure --prefix=/usr/local/apache \
--enable-module= most \
43.      make
44.      make install
45.      /usr/local/apache/bin/apachectl start  (that’s an L at the end of apachect)
46.      From another computer put the ip address of this computer in find box of a web browser to test if apache is running.
47.      ****************
48.      Start installing PHP
49.      mkdir /home/public/php
50.      cd /home/public/php
51.      vi ~/.cvsrc (it may create a new file it should start with a period)
52.      Add the following lines: (the P’s are capital)
cvs –z3
update –d –P
checkout –P
diff -u
53.      cvs –d login (login)
54.      phpfi (password)
55.      cvs –d co php4 (download)
56.      cd php4 (you must be in the php4 subdirectory before the next download)
57.      cvs login (login to zend)
58.      zend (password)
59.      cvs co Zend TSRM
60.      Put in RH 6.1 install CD
61.      mount /mnt/cdrom
62.      cd /mnt/cdrom/RedHat/RPMS
63.      rpm –Uvh  libtool-1.3.3-1.noarch.rpm
64.      cd /home/public/php/php4
65.      ./buildconf
66.      ./configure --with-apxs=/usr/local/apache/bin/apxs \
67.      make
68.      make install
69.      vi /usr/local/apache/conf/httpd.conf
70.      /AddType (searches for the AddType Section)
71.      Delete the # before the two AddType  lines before the PHP 4.x Line
72.      /usr/local/apache/bin/apachectl restart
73.      vi /usr/local/apache/htdocs/test.php
74.      Enter one line <?phpinfo()?> and exit
75.      From another networked workstation in browser put http://ip.address/test.php
76.      You should get a several page info sheet on the PHP installation.

davidpmAuthor Commented:
Easy enough change re the postgres chown order. I suspect it has something to do with security.

I tried to be clever and did a rpm install of apache on a different box so I could copy the init script but alas it did not work.
davidpmAuthor Commented:
Would copying the apachectl script to init.d and pulling a link to it from rc.d be a bad thing? It already has the start stop stuff in it.
The apache init script should be added with chkconfig, which will create the proper link in the appropriate rcN.d dirs. The init script from an rpm install probably didn't work your Apache installation because the apache bin dir isn't in the same place.
davidpmAuthor Commented:
The best I can tell about the way chkconfg works is that you have to have script in /etc/rc.d/init.d then you do
chkconfig --add script-name
I tried the appachectl and httpd and both said service does not support chkconfig. So where do I find the right file to turn on or off with chkconfig?
davidpmAuthor Commented:
I got the rpm version script to work. Your comment prompted me to find:
all programs that will let one turn script in /etc/rc.d/init.d on or off as requested

I'm not sure why I have to call the full path to make this start script work. All the other scripts just referance the executable. I suspect it has to do with the $PATH variable but have not proved it yet.
The following script is named httpd and put in the /etc/rc.d/init.d directory
# Startup script for the Apache Web Server
# chkconfig: 345 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#             HTML files and CGI.
# processname: httpd
# pidfile: /var/run/
# config: /etc/httpd/conf/access.conf
# config: /etc/httpd/conf/httpd.conf
# config: /etc/httpd/conf/srm.conf

# Source function library.
.. /etc/rc.d/init.d/functions

# See how we were called.
case "$1" in
      echo -n "Starting httpd: "
      daemon /usr/local/apache/bin/httpd
      touch /var/lock/subsys/httpd
      echo -n "Shutting down http: "
      killproc httpd
      rm -f /var/lock/subsys/httpd
      rm -f /var/run/
      status httpd
      $0 stop
      $0 start
      echo -n "Reloading httpd: "
      killproc httpd -HUP
      echo "Usage: $0 {start|stop|restart|reload|status}"
      exit 1

exit 0

You have to use the full path because /usr/local/bin is not in root's path when the script is executed. It's not worth futzing with the path for a single line or two in an init script, so everyone just uses an absolute pathe, asy you did.
davidpmAuthor Commented:
I'm almost done with my monster 100+ step instruction sheet for installing all the above. Will post for review when ready. Lost a couple of days as my notebook got sold.

Ran into one snag however.
I opened the atachment that had the apache startup script in it. I opened it on my windows notebook in notepad and saved it on the linux box via samba. Even after setting the ower and execute writes I could not execuite the script. The error I get is no file or directory.
I found a script I had copied off a linux box and even though in wordpad it looked line wrapped badly it looked ok in vi on the linux box and worked.
If I have a sample script in a word document is it possible to cut and paste and save to linux and have it work? How?
It worked with a text file that was a mysql data import script but not with the shell script.

Saving the file and moving it to Linux that way kept the carriage returns at the end of each line that windows is so fond of. Try ftp'ing the file to Linux in "text" mode which should strip the <cr>'s. Alternatively you can open the file in something like emacs (which should show them) and delete the <cr> from each line.

What got you is the carriage retun at the end of the first line. "#!/bin/sh<cr>" is not the same as "#!/bin/sh\n". Unix (Linux in this case) requires each line to be terminated by a "newline" (linefeed, aka \n) only.
davidpmAuthor Commented:
Very interesting. If I open a linux file with wordpad the cr's are messed up. If I open it in Word it displays properly.

If I open a windows file in vi it displays properly but as you say is really wrong. Is there any vi command "strip all cr's"

Or how about a way to save it in windows without the cr's

IOW to introduce ftp into my tutorial will look a little strange and manually editing cr's even worse.
davidpmAuthor Commented:
I thought I had it with
sed -e 's/\015$//' < dosfile > unixfile

The above command completed ok but even after chown and chmod when I try to run the file I get
No such file or directory.
But I can vi it so I know it is there and it looks good.
This will do it:

perl -e 'while(<>) {$_ =~ s/\015//; print;}' <withcr >without

There are more compact forms, but that one is more obvious as to what's happening.
davidpmAuthor Commented:
Your solution worked perfectly of course.
I also found another one which I plan to use for my tutorial as it is more visual and a little less typing.
vi -b filename
:1,$s/^M$//  (command to strip the carriage returns. Use CTRL V CTRL M to make the ^M mark. Thanks for putting me on the right path.

davidpmAuthor Commented:
This is the complete procedure. I want to go over your posts an check on a few things you mentioned that I did not investigate at the time such as security options etc.
Other than that this it the full Monty.

Apache, PHP4, MySql, PostgreSQL
Red Hat Linux 6.1

Step-by-Step Installation Tutorial

This tutorial expects the student to have access to the following resources:
1.      A computer to use for the Red Hat server.
2.      A Windows 95/98 computer.
3.      Both computers are networked together and can ping each other.
4.      The Internet or other source to acquire the necessary installation software.
5.      A directory /sources to which the program source files can be copied.

If a separate networked Windows 95/98 computer is not available you can do everything with just the Red Hat box. Every time the directions say to go to the Windows computer and put an address in the address box of Internet Explorer do the same process on the Linux box after running “startx” and launching Netscape from the bottom launch bar. The advantage of using the Windows box for testing is that it proves proper networking function and platform independence.

All four of the products: Apache, PHP4, MySql, PostgreSql are installed with the same basic process:
1.      Acquire the source, usually as a .tar.gz file. (For the time being the only exception is PHP4 which requires acquiring the source via the CVS source tree. We were unable to get the PHP4 release candidate .tar.gz file to compile properly.)
2.      Extracting the downloaded source
3.      configuring make options
4.      make the program
5.      make install
6.      post install steps as necessary such as setting up users and default settings.
7.      testing

Some basic Linux skills are required to follow the above steps. The detailed steps below expect knowledge of the following basic commands:
1.      cp (Copy command)
Example “cp mysql.server /etc/rc.d/init.d”
Copies the file mysql.server from the current directory to the /etc/rc.d/init.d directory. Notice the use of / not \ like in windows.
2.      mkdir (create a directory)
Example: mkdir /sources
3.      cd (Change Directory)
Example: cd /etc/rc.d/init.d
4.      vi (A text editor used to edit configuration files)
Commands: Page-Up and Page-Down and Arrow up and down work as expected
Press “i’ to enter edit mode so you can add or delete text. The backspace key only deletes characters you entered. Use the delete key to delete existing characters.
Press <esc> to enter command mode to save the file and exit vi.
<esc>:wq (to save the file and quit.)
<esc>:q! (to quit vi and abandon edits)
<esc>/enter-some-text<enter> (to find the text you entered)

If you have a networked Windows computer you may want to install Samba (See Soft Designs Samba Installation Tutorial) if you want the flexibility of moving files back and forth between the two computers. For step two you can use

1.      Install RH 6.1 with default packages plus development packages and optionally Samba

2.      ********** Install PostgreSql ***************
3.      copy or download postgresql-6.5.3.tar.gz to /sources
4.      cd /sources
The following command will extract the archived compressed file to the folder /sources/postgresql-6.5.3
5.      tar –xvzf postgresql-6.5.3.tar.gz
The following steps create the postgres user, create directories for installation, changes ownership of directories to the new postgres user and finally edits the environment for the postgres user
6.      adduser postgres
7.      passwd postgres (type in new pw twice, for this example I used postgres for the password and the username.
8.      chown –R postgres:postgres /sources/postgresql-6.5.3
9.      mkdir /usr/local/pgsql
10.      chown –R postgres:postgres /usr/local/pgsql
11.      su – postgres  (there is a space both sides of the –)
12.      vi ~/.bash_profile
13.      Add the following lines then save and exit vi:
14.      exit
15.      su – postgres
16.      cd /sources/postgresql-6.5.3/src
17.      ./configure –with-tcl  (this will take a while and a lot of stuff will scroll the screen.
18.      make (this will take a while and a lot of stuff will scroll the screen)
19.      make install
20.      exit (to get back to root user)
21.      vi /etc/
Add line: /usr/local/pgsql/lib
Save and exit with <esc>wq
22.      /sbin/ldconfig (it takes a few seconds to complete please wait)
23.      exit
24.      u – postgres (there is a space on both sides of the -)
25.      cd /usr/local/pgsql/bin
26.      initdb
27.      ./postmaster –i &
28.      createdb mydb
29.      ./psql mydb (you should get a postgres=> prompt
30.      select datetime ‘now’; (You should get a one row answer)
31.      create table customers (last varchar(30), first (varchar(30));
32.      insert into customers values (‘Jones’,’Mike’);
33.      insert into customers values (‘Smith’,’Susan’);
34.      select  * from customers
35.      \q  (exits psql)
36.      exit (back to root)
37.      cd /sources/postgresql-6.5.3/contrib/linux
38.      sh install  (postgres will start automatically on bootup)
39.      vi /etc/rc.d/init.d/postgres
Change the uncommented PGOPTS line from:
PGOPTS “” # -B 256
PGOPTS “-i” # -B 256

40.      ********* Install mySql  ********************
41.      copy mysql-3.22.32.tar.gz to /sources
42.      tar –xvzf mysql-3.22.32.tar.gz
43.      cd mysql-3.22.32
44.      ./configure --prefix=/usr/local/mysql
45.      make
46.      make install
47.      cd /usr/local/mysql/bin
48.      ./mysql_install_db
49.      ./safe_mysqld &
50.      ./mysqladmin –u root password mydb
51.      ./mysqlshow –p (should output some databases)
52.      ./mysqladmin –u root –p create mydb
53.      ./mysql –u  root –p mydb
54.      show databases; (don’t forget the semicolon)
55.      \q
56.      Create some data.
57.      Create a text file with the following lines in it called dump.txt in the directory /sources: (Notice that there is one line starting with CREATE and three lines starting with INSERT. The lines have to wrap here but should not line wrap in the document you create. If you are reading this in word you can copy the following lines and paste them into a notepad document then move the document to /usr/local/mysql/bin)
CREATE TABLE employees (  id tinyint(4) DEFAULT '0' NOT NULL AUTO_INCREMENT,  first varchar(20),  last varchar(20),  address varchar(255),  position varchar(50),  PRIMARY KEY (id),  UNIQUE id (id));
INSERT INTO employees VALUES (1,'Bob','Smith','128 Here St, Cityname','Marketing Manager');
INSERT INTO employees VALUES (2,'John','Roberts','45 There St , Townville','Telephonist');
INSERT INTO employees VALUES (3,'Brad','Johnson','1/34 Nowhere Blvd, Snowston','Doorman');

58.      cd /usr/local/mysql/bin
59.      ./mysql –u root –p mydb < /sources/dump.txt
60.      ./mysql –u root –p mydb
61.      select * from employees;
62.      \q
63.      cd /sources/mysql-3.22.32/support-files
64.      cp mysql.server /etc/rc.d/init.d/mysqld
65.      chmod a+x /etc/rc.d/init.d/mysqld
66.      chkconfig –add mysqld
67.      chkconfig mysqld on

68.      *************  Install Apache  ******************
69.      copy apache_1.3.12.tar.gz to /sources
70.      cd /sources
71.      tar –xvzf apache_1.3.12.tar.gz
72.      cd /sources/apache_1.3.12
73.      ./configure --prefix=/usr/local/apache \
--enable-module= most \
74.      make
75.      make install
76.      /usr/local/apache/bin/apachectl start  (that’s an L at the end of apachect)
77.      From another computer put the ip address of this computer in find box of a web browser to test if apache is running.
78.      Name the following script httpd and copy it to the /sources directory
# Startup script for the Apache Web Server
# chkconfig: 345 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#        HTML files and CGI.
# processname: httpd
# pidfile: /var/run/
# config: /etc/httpd/conf/access.conf
# config: /etc/httpd/conf/httpd.conf
# config: /etc/httpd/conf/srm.conf

# Source function library.
... /etc/rc.d/init.d/functions

# See how we were called.
case "$1" in
echo -n "Starting httpd: " 
daemon /usr/local/apache/bin/httpd
touch /var/lock/subsys/httpd
echo -n "Shutting down http: " 
killproc httpd
rm -f /var/lock/subsys/httpd
rm -f /var/run/
status httpd
$0 stop
$0 start
echo -n "Reloading httpd: " 
killproc httpd -HUP
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
exit 0
79.       cd /sources
80.      cp httpd /etc/rc.d/init.d
81.      cd /etc/rc.d/init.d
82.      chmod a+x httpd
83.      chown root:root httpd
84.      chkconfig –add httpd  
85.      chkconfig httpd on
86.      vi –b httpd
87.      :1,$s/^M$//   (type Ctrl V Ctrl M to make the ^M)

88.      ********* Install PHP4 Beta *************
89.      If you are given the php4 directory you can copy it to /sources and skip directly to line 101
90.      mkdir /sources/php4
91.      cd /sources/php4
92.      vi ~/.cvsrc (it may create a new file it should start with a period)
93.      Add the following lines: (the P’s are capital)
cvs –z3
update –d –P
checkout –P
diff -u
94.      cvs –d login (login)
95.      phpfi (password)
96.      cvs –d co php4 (download)
97.      cd php4 (you must be in the php4 subdirectory before the next download)
98.      cvs login (login to zend)
99.      zend (password)
100.      cvs co Zend TSRM
101.      Put in RH 6.1 install CD
102.      mount /mnt/cdrom
103.      cd /mnt/cdrom/RedHat/RPMS
104.      rpm –Uvh  libtool-1.3.3-1.noarch.rpm
105.      cd /sources/php4
106.      ./buildconf
107.      ./configure --with-apxs=/usr/local/apache/bin/apxs \
108.      make
109.      make install
110.      vi /usr/local/apache/conf/httpd.conf
111.      /AddType (searches for the AddType Section)
112.      Delete the # before the two AddType  lines after the PHP 4.x Line
113.      /usr/local/apache/bin/apachectl restart
114.      vi /usr/local/apache/htdocs/test.php
115.      Enter one line <?phpinfo()?> and exit
116.      From another networked workstation in browser put http://ip.address/test.php (substitute the ip apddress of you Linux server for ip.address)
117.      You should get a several page info sheet on the PHP installation.

118.      ****** Script to get PostgrSql data ***********
119.      Create the following script called testpgsql.php and place it in the /usr/local/apache/htdocs directory



$dbconn=pg_connect("dbname=$PG_DATABASE host=$PG_HOST port=$PG_PORT user=$PG_USER password=$PG_PASS");
// $dbconn=pg_connect("","","","","postgres");
if (! $dbconn) {
  echo "Error connecting to the database !<br>";
  printf("%s", pg_errormessage($dbconn));
$sqlcom = "select * from customers";
$dbres = pg_exec($dbconn, $sqlcom);
if ( ! $dbres) {
  echo "Error: " + pg_errormessage($dbconn);

 while ($row < $rowmax)
$do = pg_Fetch_Object($dbres, $row);
$s = "<p>$do->first | $do->last\n";



120.      From a web browser put in http://ip.address/testpgsql.php. You should get the list of name you put in earlier

121.      ****** Script to get MySql data ***********
122.      Create the following script called testmysql.php and place it in the /usr/local/apache/htdocs directory
$db = mysql_connect("localhost", "root","mysql");
$result = mysql_query("SELECT * FROM employees",$db);
printf("First Name: %s<br>\n", mysql_result($result,0,"first"));
printf("Last Name: %s<br>\n", mysql_result($result,0,"last"));
printf("Address: %s<br>\n", mysql_result($result,0,"address"));
printf("Position: %s<br>\n", mysql_result($result,0,"position"));
123.      From a web browser put in http://ip.address/testmysql.php. You should get the list of name you put in earlier

davidpmAuthor Commented:
Any errors or sugestions?
davidpmAuthor Commented:
This was so incremental I just picked a random answer to attach the points to.

I know it's boring but if you get a change to critiqe my procedure I would appreciate it.

Don't want to be teaching already disadvantaged NT guys wrong things.

I'm sorry for the delay in responding to your request for a critique. What with the ILOVEYOU virus and its descendants and a telco that did some re-configurations and upgrades of their switch, which broke every one of my T1 lines one at a time and twice for each in the same week... Well it's been more than a bit busy. Now that I've got that out of the way...

Generally I found the directions to be quite lucid and complete. The only general observation that I have is that you tell the reader that anything beginning with "# " is a command to be typed in (as opposed to an instruction). Of course you'd insert a "# " in front of every command. When I modified your instructions that way (and fixed a couple of typos), my 16 year old son was able to use them to install postgres, mysql, apache & php with no coaching on my part (and he knows nothing whatsoever about Unix). So that speaks very highly  for how well the document is written. You've done an exceptionally good job!

Specifics... I did find a couple of things that are probably just typo's or simple omissions.

You don't say after Line 1, but they need to login as root.

Looks like something is missing here:

"Installation Tutorial) if you want the flexibility of moving files back and forth between the two computers. For step two you can use"

Line 24 reads "u - postgres (there..." and should be "su - postgres (there..."

There's a typo at line 116 "apaddress"

That's really all that I found that needed attention. Again, congratulations on an exceptionally good set of instructions.
davidpmAuthor Commented:
We picked up an extra weeks work with "love you" but fortunatly it came at a good time for us.
Thanks I'll fix those items and let it rip.
I cann't believe you enlisted your son to beta test my instructions.
I'll feel really guilty if that ends up costing you more than you expected. <g>
I've got an almost 16 year old that can be quite mercency so I'm worried about you.

Actually, I suspect that I'm pretty safe in that respect. I've just given him a Voodoo 3D 3000 that I no longer needed and have a 4Gb drive and a CD writer that he doesn't yet know about in reserve. The CD writer would be a big hit as he has gotten into downloading audio files off the net and always seems to have a portable cd player within arms length.

Seriously, it's the best way to test a set of instructions that I know of. Give them to someone that hasn't any experience in that subject area and stand back and take notes (at work it's the random secretary that's usually the test subject). When they can't figure out what to do next, or get confused and make mistakes you know where the docs are lacking. I tend to use the boy at home as the wife has entirely too long a memory and is quite fond of dredging up mistakes I made years ago.
All Courses

From novice to tech pro — start learning today.