Skip to content

Instantly share code, notes, and snippets.

@cadreoneseven
Last active April 28, 2022 06:03
Show Gist options
  • Save cadreoneseven/9f97385325574cec010558da0e378954 to your computer and use it in GitHub Desktop.
Save cadreoneseven/9f97385325574cec010558da0e378954 to your computer and use it in GitHub Desktop.
Installation of Wordpress on PostgreSQL database backend. In case you want some more robust that mysql
#Step 1: Download Wordpress
# Point to your webserver root - typically
$ cd /var/www/html
$ wget https://wordpress.org/latest.tar.gz
# Then untar
$ tar xzf latest.tar.gz
# There will a folder named wordpress
#Step 2: Create Database in postgresql e.g wp1
$ sudo su - postgres
$ psql
$ create database wp1;
$ create user adminwp1 with password 'secret123';
$ grant all privileges on database wp1 to adminwp1;
$ \q
#Step 3: Edit config file with Database from step2
# Using sed to edit the file
$ sed -e 's/database_name_here/wp1/g' -e 's/username_here/adminwp1/g' -e 's/password_here/secret123/g' -i ./wp-config.php
# that will make the following changes in wp-config.php
define( 'DB_NAME', 'wp1' );
define( 'DB_USER', 'adminwp1' );
define( 'DB_PASSWORD', 'secret123' );
#Step 4: only if setting up development environment
$ sed 's/\(def.*WP_DEBUG.*,\) true/\1 false/g' -i ./wp-config.php
#That will make the following changes in wp-config.php
define( 'WP_DEBUG', true );
#Step 5: Install PostgreSQL driver called Pg4wp
#Go into wp-content subfolder
$ cd wp-content
#Download the repository of the driver code
$ git clone https://github.com/kevinoid/postgresql-for-wordpress.git
$ mv postgresql-for-wordpress/pg4wp Pg4wp
$ cp Pg4wp/db.php db.php
#Alternative driver code - This is actually faster - better perhaps
$ wget https://downloads.wordpress.org/plugin/wppg.1.0.1.zip
$ unzip -q wppg.1.0.1.zip
# or get fresh copy from git clone https://github.com/qodrorid/wppg.git
$ cp wppg/pg4wp/db.php .
$ mv wppg plugins
#Confirm Driver is set to postgresql (pgsql)
$ grep DB_DRIVER db.php
# this will reture the following
# define('DB_DRIVER', 'pgsql'); // 'pgsql' or 'mysql' are supported for now
#Clean up if necessary
$ rm -rf postgresql-for-wordpress
$ rm ../../latest.tar.gz
#Finally complete the installation via web browser
https://<webserver>/wordpress/wp-admin/install.php
@cadreoneseven
Copy link
Author

Known Bug

$wpdb->insert_id not working, for get last id use "select max(id) from table_name"

@phpdevoloper
Copy link

It's not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment