Permalink
Browse files

Revised and expanded to include info about making PostgreSQL a service.

  • Loading branch information...
1 parent 0258d63 commit 037b8b0c3bef532a8ca6647dbaee61cfacc4fa1f @cjmazey cjmazey committed Nov 29, 2012
Showing with 96 additions and 91 deletions.
  1. +96 −91 pages/drupal-pgsql-install/content.md
@@ -1,177 +1,182 @@
-This is a technote with details about installing Drupal on Ububtu. In this project, we use Drupal as a system to post articles and a TelaSocial component, TagVisor, to make the articles become an animated slide experience.
+This is a technote with details about installing Drupal on Ububtu. We're using the latest version as of this writing, 12.10-desktop. All major components are installed and configured from source. In this project, we use Drupal as a platform to post articles, as a TelaSocial component, TagVisor, to make the articles become an animated slide experience.
+## LIVE NOTE—This article has a bounty program associated with it. If you are willing to participate you will get a your name here and also a reward. If you accept the terms and conditions, please visit the project at [Amazon mTurk](https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&requesterId=A2R9MB4V6CG1WY)
-## LIVE NOTE — This article has a bounty program associated with it. If you are willing to participate you will get a your name here and also a reward. If you accept the terms and conditions, please visit the project at [Amazon mTurk](https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&requesterId=A2R9MB4V6CG1WY)
-
-First, let's set up the basic Drupal environment. We will install and configure Apache, PostgreSQL and PHP.
+First, let's set up a basic LAMP-like environment. We will install and configure Apache, PostgreSQL and PHP.
## Apache
-In this project we use the Apache Web Server and build it from the source code.
+In this project we use the Apache Web Server and build it from the source code. You'll need the "Apache Portable Runtime," and from the same page, "APR-util.".
-Download it from
+### Download
+<http://apr.apache.org/download.cgi>
-* http://httpd.apache.org/download.cgi
+<http://httpd.apache.org/download.cgi>
Make sure your system is able to build it:
-* apt-get install build-essentials
+ apt-get install build-essential
-On my system I uncompressed the tarball to the following directory:
+I'd suggest you create a build directory to download and build everything, for instance ~/src. Tarballs almost inevitably extract into separate directories, so you don't have to worry about things getting mixed up.
+
+`cd` into the APR directory and perform the standard install procedure, e.g.
- /home/marcio2/apache/httpd-2.2.22/
+ ./configure
+ make
+ sudo make install
-We need to use the build option '--enable-so'. This will generate an Apache server that can dynamically load .so files--libraries. PHP and its modules will be loaded as .so files later in this article.
+Next do APR-util. You'll need to tell it where APR is:
- cd httpd-2.2.22/
- ./configure --enable-so
+ ./configure --with-apr=/usr/local/apr
make
- make install
+ sudo make install
-## PHP
+__Note__: You should _never_ have to configure or make as root.
-Download it from
+One last thing we'll need, but won't bother compiling from source:
-* http://www.php.net/get/php-5.4.5.tar.gz/from/a/mirror
+ sudo apt-get install libpcre3 libpcre3-dev
-Install a few requirements, build and install it:
+We need to use the build option '`--enable-so`'. This will generate an Apache server that can dynamically load .so files&mdash;libraries. PHP and its modules will be loaded as .so files later in this article.
- apt-get install libxml2
- apt-get install libxml2-dev
- apt-get install zlib1g
- apt-get install zlib1g-dev
- ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-zlib
+ cd httpd-2.4.3/
+ ./configure --enable-so
make
- make install
+ sudo make install
+
+## PostgreSQL
+
+### Download
-You may need to install with libpng so that PHP works with GD:
+<http://www.postgresql.org/ftp/source/>
- apt-get install libpng-dev
+The latest version as of this writing is 9.2.1.
-Since we are installing Drupal 7 we will need to build PHP with the PDO extensions (see [http://php.net/manual/en/ref.pdo-pgsql.php].) This is the infrastructure that will make the connection between PHP and PostgreSQL.
+Readline makes doing things from the console more pleasant. Then build it:
- ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-pgsql --with-zlib --with-gd --with-pdo-pgsql
+ sudo apt-get install libreadline6 libreadline6-dev
+ ./configure
make
- make install
+ sudo make install
-The libphp5.so file will be installed to your Apache installation folder, which is probably /usr/local/apache2/modules. Copy over a default configuration file for PHP:
+Now set up an account that owns the databases and initialize the database:
- cp php.ini-development /usr/local/lib/php.ini
+ sudo adduser --home=/var/lib/pgsql --shell=/bin/bash --disabled-password pgsql
+ sudo -u pgsql /usr/local/pgsql/bin/initdb -D /var/lib/pgsql/db
+ sudo -u pgsql /usr/local/pgsql/bin/postgres -D /var/lib/pgsql/db &
+ sudo -u pgsql /usr/local/pgsql/bin/createdb --encoding=UTF8 --owner=pgsql drupal
-## Apache conf
+If you have problems related to UTF8 and template, add --template=template0 to the createdb line above.
-Edit your Apache configuration file, httpd.conf. It's probably somewhere like /usr/local/apache2/conf/httpd.conf.
+Finally, create a database user for Drupal. You'll be prompted for a password; remember it and the name (here "drupal") you choose here for the Drupal installation:
- <FilesMatch "\.php$">
- SetHandler application/x-httpd-php
- </FilesMatch>
- LoadModule php5_module modules/libphp5.so
+ sudo -u pgsql /usr/local/pgsql/bin/createuser --pwprompt --encrypted --no-createrole --no-createdb drupal
- AddType application/x-httpd-php .php
+See the end of this article for information about making PostgreSQL a "service."
- DocumentRoot "/var/www/html"
+## PHP
-We need AllowOverride All rather than the defualt of None. Drupal needs this to be able to override settings on a per-directory basis later on.
+###Download
- <Directory "/var/www/html">
- Options Indexes FollowSymLinks
- AllowOverride None
- Order allow,deny
- Allow from all
- </Directory>
+<http://us3.php.net/get/php-5.4.9.tar.bz2/from/a/mirror>
-Just replace "None" with "All" there.
+PHP takes awhile to compile. You may need to install libpng so that PHP can use GD (an image manipulation library that Drupal wants.) We will also build with [PDO extensions](http://php.net/manual/en/ref.pdo-pgsql.php). Install a few other requirements, build and install it:
-## PostgreSQL installation
+ sudo apt-get install libpng12-0 libpng12-dev
+ sudo apt-get install libxml2 libxml2-dev
+ sudo apt-get install zlib1g zlib1g-dev
+ ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-pgsql --with-zlib --with-gd --with-pdo-pgsql=/usr/local/pgsql/bin
+ make
+ sudo make install
-Download it from:
+Copy over a default configuration file for PHP:
-* http://www.postgresql.org/ftp/source/v9.1.4/
+ sudo cp php.ini-development /usr/local/lib/php.ini
-Readline make doing things from the console more pleasant. Then build it:
+## Apache configuration
- apt-get install libreadline-dev
- ./configure
- make
- make install
+Edit your Apache configuration file, httpd.conf. It's probably somewhere like /usr/local/apache2/conf/httpd.conf. Search for an "AddType something-or-other" section and add this stuff after it:
-And set up a few things:
+ AddType application/x-httpd-php .php
+ AddType application/x-httpd-php-source .phps
-## PostgreSQL configuration for Drupal
+In case it's not already present somewhere, add (or uncomment) this next to the other LoadModule lines:
- adduser postgres
- cd /usr/local/pgsql
- mkdir data
- chown -R postgres:postgres *
- su - postgres
- ./initdb -D /usr/local/pgsql/data
-
-Create a database for Drupal:
+ LoadModule php5_module modules/libphp5.so
- /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
- ./createdb --encoding=UTF8 --owner=postgres drupal
+Find the DocumentRoot line and change it to:
-If you have problems related UTF8, templates and such, you'll need to pass --template=template0 to createbd (as per their documentation):
+ DocumentRoot "/var/www/html"
- ./createdb --encoding=UTF8 --owner=postgres --template=template0 drupal
+Similarly, change all the &lt;Directory "/some/path"&gt; lines to have "/var/www/html". Do not change other lines, like ServerRoot.
-And. . .a databasse user:
+We need AllowOverride All rather than the defualt of None. Drupal needs this to be able to override settings on a per-directory basis later on. Like this (give or take comments):
+
+ <Directory "/var/www/html">
+ Options Indexes FollowSymLinks
+ AllowOverride None
+ Order allow,deny
+ Allow from all
+ </Directory>
+
+Just replace "None" with "All" there.
- ./createuser --pwprompt --encrypted --no-createrole --no-createdb YOUR_DB_USER
## Drupal Preparation
Get it here:
-* http://drupal.org/project/drupal
+<http://drupal.org/project/drupal>
-Copy the untarred folder to (not in) /var/www/html:
+Copy the _contents_ of the untarred directory to (not in) /var/www/html. If you don't, your site URL will have the directory name included in its path:
- tar -xzvf drupal-7.17.tar.gz
- mv drupal-7.17 /var/www/html
+ tar xzvf drupal-7.17.tar.gz
+ mkdir /var/www
+ sudo mv drupal-7.17 /var/www/html
-Make sure the .htaccess is still present, which it should be if you mv-ed it as above. It might not be if you tried to copy/paste from a file browser or something.
+Make sure the .htaccess is still present in /var/www/html, which it should be if you mv-ed it as above. It might not be if you tried to copy/paste from a file browser or something. It's a security risk, so check.
Check the owner for the files under /var/www/html--if you are going with root (brave) you need to make sure all the files under /var/www/html are root:root.
+ sudo chown -R root:root /var/www/html
+
This is important, so Drupal can record settings during installation:
cd /var/www/html
- chmod a+w sites/default
-
- cp ./sites/default/default.settings.php ./sites/default/settings.php
+ sudo cp ./sites/default/default.settings.php ./sites/default/settings.php
+ sudo chmod -R a+w sites/default
Restart Apache--if you don't have a script in /etc/init.d, you will need to make one, e.g., something like:
#!/bin/bash
/usr/local/apache2/bin/apachectl $@
+and make it executable. Then do
+
+ service script_name restart
+
## Drupal Installation
-Use any browser and go to http://your_host_name:80,
+Use any browser and go to http://localhost or http://your_host_name:80,
It should be pretty self-explanatory.
After the install, be sure to make the settings file unwritable again:
- chmod go-w sites/default/settings.php
- chmod go-w sites/default
+ sudo chmod go-w sites/default sites/default/settings.php
## References
* [Postgresql installation](http://www.postgresql.org/docs/8.0/static/installation.html)
* [Template0 for Postgresql with UTF8](http://www.wetware.co.nz/2010/07/error-new-encoding-utf8-is-incompatible-with-the-encoding-of-the-template-database-sql_ascii/)
-## To be continued - mgalli at telasocial dot com
+## Making PostgreSQL a service
+As it stands, the instructions in this article will have Apache running as a "service," so that it can be set to start and stop automatically with the system, but not so for PostgreSQL. (PHP doesn't need to be started or stopped this way, as it's just called upon as needed.) The answer is simple; we just need a script like the one that was suggested for Apache above. Create the following in /etc/init.d:
-After the Drupal installation.
-
-## Making your PostgreSQL as a service
-
-Instead of compiling PostgreSQL, you can apt-get install it and it already comes as a service.
-
-http://archives.postgresql.org/pgsql-php/2004-03/msg00056.php
-
+ #!/bin/bash
+
+ su -c "/usr/local/pgsql/bin/pg_ctl $@ -D /var/lib/pgsql/db -l /var/lib/pgsql/bd/serverlog" pgsql
+and make it executable.

0 comments on commit 037b8b0

Please sign in to comment.