LAPP part 2: connection issues
Update time. Installing PostgreSQL is relatively easy.
sudo apt-get install postgresql php5-pgsql
I also installed this package, I'm not actually sure if this is necessary.
sudo apt-get install libapache2-mod-auth-mysql
Postgres creates a new user in your OS, and I have no idea what that user's password is. You will need to access the 'psql' executable through that user, as you (your user account) don't have permission to use it.
sudo -u postgres psql
This will open the PostgreSQL command line interface, you will notice that your command prompt has changed from nael@bill-robot~ to postgres=#. Commands in this cli must be ended with a semicolon ';', and multiple commands can be part of the same block. First we're going to change the password for this user to something we've picked...
postgres=#; alter user postgres password 'apassword';
Note that you need to include the single quotes for the command to work. Now when you need to use the rdbms' superuser you'll be able to login. Note that you didn't change the postgres system user's password, I still haven't figured that out, but it doesn't seem important right now. Next we'll create a db user account for ourself.
postgres=# create user myusername createdb createuser password 'mypassword'; postgres=# create database myusername owner myusername;
This has created a user with the capability of creating users and databases. To exit the postgres prompt use the command "\q". Now you can access the postgres cli by simply calling 'psql' from bash.
The next step is to ensure that our php server can connect to the pgsql instance we've set up. I just altered the testphp file I already created to look something like this:
<?php
$dbconn = pg_connect("host=localhost dbname=publisher user=publisherapp password=publisherapp")
or die("Could not connect" . pg_last_error());
$stat = pg_connection_status($dbconn);
if($stat === PGSQL_CONNECTION_OK){
echo 'Connected';
{
else{
echo 'Failed';
}
?>
This results in a charming webpage that looks like this
After doing a lot of ineffective troubleshooting, my housemate showed up and I asked him if he knew anything about PostgreSQL. He said he'd only used MySQL. I asked him if he had any tips, and he pointed my to this little tidbit. If you open the php.ini file [/etc/php/apache2/php.ini] there are two details that you can change. On line 480 and 491 set display_errors = on, and display_startup_errors = on.
This will give you slightly more verbose feedback. Remember to restart the apache server.
sudo service apache2 restart
Now my webpage looks like this
Parse error: syntax error, unexpected 'else' (T_ELSE) in /var/www/testphp.php on line 9
Line 9? Of course you've already spotted the damn curly bracket I put facing the wrong direction in the above code snippet haven't you. After fixing the offending bracket my website looks like this.
Connected
Beautiful.
References that helped me be less of an ignorant clod:
http://community.linuxmint.com/tutorial/view/486
http://www.unixmen.com/201204-howto-install-postgresql-on-ubuntu-and-linuxmint/
http://www.postgresql.org/message-id/[email protected]
http://www.php.net/manual/en/function.pg-connection-status.php
http://www.php.net/manual/en/pgsql.examples-basic.php













