If you'd like to get PostgreSQL and PHP running on Mac OS X, the following tutorial should help. Please refer to my previous instructions on installing Apache, PHP, MySQL in this web site to make these instruction clearer.
- Vip Malixi.
[Read the rest of the article for the step-by-step instructions]
NOTE: Do not type the "%" sign; it's the indicator for the command prompt, not part of each command...
- Vip Malixi.
[Read the rest of the article for the step-by-step instructions]
NOTE: Do not type the "%" sign; it's the indicator for the command prompt, not part of each command...
- First download the postgres tar ball from the postgresql.org web site. I was successful with this version: postgresql-7.1.2.tar.gz
- Copy it to your main user's Documents folder
- Open Terminal and go to the Home Documents directory:
cd ~/Documents
- Become Root (su), then untar and unzip:
% gzip -dc postgresql-7.1.2.tar.gz | tar xvf -
- Go to the newly created directory:
cd postgresql-7.1.2
- Configure, make and install:
% ./configure
% make
% make install
- exit as Root:
% exit
- Open up System Preferences | Users
- Create a new user called "postgres" with password "postgres" with no admin privileges
- Go back to terminal application and as Root change ownership of /usr/local/pgsql to user postgres:
% chown postgres /usr/local/pgsql
- Become user postgres:
% su postgres
- Initialize postgres databases:
% /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
- Test by running the postgres server:
% /usr/local/pgsql/bin/postmaster -i -S -D /usr/local/pgsql/data &
- Create a test database:
% /usr/local/pgsql/bin/createdb test
- Test running postgres:
% /usr/local/pgsql/bin/psql test
- Try running a SQL command while inside postgres, then when it works, quit:
> select datetime 'now';
> q
- Still as user postgres, create a postgres user for yourself:
First find out your user name:
% whoami
[Editor's question: If you're still user 'postgres', won't this return 'postgres'?]
--let's say your user name is "dalailama":
% /usr/local/pgsql/bin/createuser dalailama
- You're all set. If you want, you can delete the postgres install directory so as not to waste space. First go to Terminal and as Root change ownership of that directory to yourself:
% chown dalailama postgresql-7.1.2
% exit
- You can now trash that directory from Home | Documents
- If you want to be able to access postgres from PHP, referring to my previous instructions on how to install Apache, MySQL, PHP, just modify the PHP configure (also, the latest PHP version works pretty well, no more need to disable pear (php-4.0.6.tar.gz) which you can get from php.net:
% ./configure --with-mysql --with-pgsql --with-dbase --with-apsx --enable-track-vars
- I got an error during the make of PHP on MacOSX (w/c I didn't get when I installed in Linux) with the postgres option which I was able fix (through pure guesswork and trial and error). This is how I fixed the make error: as Root, do the following if you get a "run ranlib" error during php make:
% cd /usr/local/pgsql/lib
% ranlib -sct libpq.a
- After doing this, I was able to complete the php make and make install. Go back to where we were configuring PHP and do the following:
% make
% make install
- There. Now run the postgres server, mysql server, and apache server to test everything. Good luck.
•
[10,897 views]

