Tutorial - Installation of PostgreSQL, Apache and PHP
원본출처 : http://pgsql.designmagick.com/tutorial.php?id=3
This tutorial is for those who are having problems installing PostgreSQL, PHP, and Apache together. At the moment, this is for
Linux only, I don't have access to Windows NT or Windows 2000 to try and get it going on there. For more information on that,
please see PHP-4-Win.
Also note, this information is for a fresh install of these programs, NOT for an upgrade.
First of all, we need to download the source for the programs. The routine I'm explaining will not work with the RPM's. For RPM's, download the RPM's, then use the standard syntax-
rpm -ivh postgresql-*.rpm
to install them.
Get the programs from-
When you download, please choose a mirror site close to you.
First we'll work on the PostgreSQL installation. Create a PostgreSQL "superuser". This is who "owns" the database. I use the "postgres" user, with the group being "daemon". See your system documentation on how to do this (hint - man useradd). Give the user a home directory of /usr/local/pgsql as this is where PostgreSQL defaults to when it installs.
After downloading the source code, run these commands -
designmagick:/home/tomcat # gunzip postgresql-7_0_2.tar.gz
designmagick:/home/tomcat # tar -xvf postgresql-7_0_2.tar
designmagick:/home/tomcat # mv postgresql-7.0.2/ /usr/src
If you have multiple partitions on your system, and your home directory and the usr directory are on different partitions, you
will get a message like this -
mv: cannot move `postgresql-7.0.2' across filesystems: Not a regular file
Run these commands instead -
designmagick:/home/tomcat # cp -r postgresql-7.0.2/ /usr/src
designmagick:/home/tomcat # rm -r postgresql-7.0.2/
Now that we've unpacked PostgreSQL, we can work on getting it going.
designmagick:/home/tomcat # cd /usr/src/postgresql-7.0.2/src/
designmagick:/usr/src/postgresql-7.0.2/src # ./configure
This basically works out what sort of system you have, and what commands work. When that finishes, run
designmagick:/usr/src/postgresql-7.0.2/src # make
This should give the last line as "All of PostgreSQL is successfully made. Ready to install." The next part, we do as the database superuser we set up before (postgres). So we have to change to this user first.
designmagick:/usr/src/postgresql-7.0.2/src # su - postgres
postgres@designmagick:~ > cd /usr/src/postgresql-7.0.2/src/
postgres@designmagick:/usr/src/postgresql-7.0.2/src > make install
If you have problems with this, you CAN do it as root, then change the owner of the files. Do the "make install" as root, then change the permissions of the files. How?
designmagick:/usr/src/postgresql-7.0.2/src # cd /usr/local
designmagick:/usr/local # chown -R postgres:daemon pgsql
Now we have to tell the system where the PostgreSQL libraries are. Add this line into /etc/ld.so.conf -
designmagick:/usr/local # /sbin/ldconfig
Next we have to set up the PostgreSQL database. Do this as the postgres user, not as root. In fact, PostgreSQL won't start as root.
postgres@designmagick:/usr/local > /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
The "-D" option tells the database where the data is stored. When this finishes, it will tell you you can start the server. This is my script which i call "pgsql". I put it in the /etc/rc.d directory, you can put it wherever you want
su -c '/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >> /usr/local/pgsql/logs/server.log 2>&1' postgres
This puts the output into a log file. As the postgres superuser, make a "log" directory, otherwise it won't work. To make it automatically start when the computer starts, add this line into /etc/rc.d/boot.local (this is for SuSE, for others, check the directory first).
If anyone has any better suggestions for a script, let us know. If you run this script now, it will start the PostgreSQL server.
That should be enough for PostgreSQL for now, we'll move onto PHP and Apache installation.
Now we setup PHP and apache. We need to unpack the source code for these before we can do anything, so we do this -
designmagick:/home/tomcat # gunzip apache-1.3.20.tar.gz
designmagick:/home/tomcat # tar -xvf apache-1.3.20.tar
designmagick:/home/tomcat # gunzip php-4.0.6.tar.gz
designmagick:/home/tomcat # tar -xvf php-4.0.6.tar
Then we move them to the /usr/src directory, as we did before.
designmagick:/home/tomcat # mv apache_1.3.20/ /usr/src
designmagick:/home/tomcat # mv php-4.0.6/ /usr/src
Again, if you get this message -
mv: cannot move `apache_1.3.20' across filesystems: Not a regular file
mv: cannot move `php-4.0.6' across filesystems: Not a regular file
Do this instead -
designmagick:/home/tomcat # cp -r apache_1.3.20/ /usr/src
designmagick:/home/tomcat # rm -r apache_1.3.20/
designmagick:/home/tomcat # cp -r php-4.0.6/ /usr/src
designmagick:/home/tomcat # rm -r php-4.0.6/
Now we actually get into the installation of the programs.
designmagick:/home/tomcat # cd /usr/src
designmagick:/usr/src # cd apache_1.3.20/
designmagick:/usr/src/apache_1.3.20 # ./configure
This gives us a configuration of Apache, PHP needs this for its installation. We'll go back to PHP again now.
designmagick:/usr/src/apache_1.3.20 # cd ..
designmagick:/usr/src # cd php-4.0.6/
We now configure PHP to work with PostgreSQL. This is the configure command I use, it works well -
designmagick:/usr/src/php-4.0.6 # ./configure --with-pgsql --with-apache=../apache-_1.3.20 --enable-track-vars
Next we make it and install it.
designmagick:/usr/src/php-4.0.6 # make
designmagick:/usr/src/php-4.0.6 # make install
Next we make and install Apache.
designmagick:/usr/src/php-4.0.6 # cd ..
designmagick:/usr/src # cd apache_1.3.20/
We have to run the configure command again to tell Apache we want to use the PHP module.
designmagick:/usr/src/apache_1.3.20 # ./configure --activate-module=src/modules/php4/libphp4.a
This file doesn't exist at the moment (libphp4.a), it will be created by the process.
designmagick:/usr/src/apache_1.3.20 # make
designmagick:/usr/src/apache_1.3.20 # make install
The Apache server is now installed. We only have a couple more steps to go through, and then we have a working PostgreSQL, PHP,
and Apache webserver.
We have to tell Apache how to deal with php scripts. We need to add this line to the srm.conf file located in the /usr/local/apache/conf/ directory (this is the default installation directory for Apache).
Addtype application/x-httpd-php .php
The last thing we have to do, is set up a script to start Apache when the computer boots up. You actually get a program to do this, its called "apachectl" and is located in the /usr/local/apache/bin directory. The other thing we have to check is that an older version of Apache doesn't start up. Check for a file in the /etc/rc.d directory called either "apache" or "httpd". If you do have one of these files, backup the file, edit it and change the httpd location to "/usr/local/apache/bin/httpd". If you don't have one of these files, add this line into /etc/rc.d/boot.local :
You can also run this file right now to start the Apache webserver. That should be about it!