How to Install LAMP with PostgreSQL and PostGIS on Ubuntu

Welcome to EDIS Global VPS Hosting’s comprehensive guide on setting up a LAMP environment but with a twist - we’re swapping out the MySQL component for PostgreSQL and its spatial extension, PostGIS.

Prerequisites:

  1. An active EDIS Global VPS Hosting account.
  2. A VPS running Ubuntu 20.04 or later.
  3. Basic knowledge of terminal operations.

Step-by-step Installation:

1. System Update:

Always ensure your server is up-to-date with the latest packages:

sudo apt update && sudo apt upgrade -y

2. Apache Installation:

Begin by installing the Apache web server:

sudo apt install apache2 -y

To check Apache’s status:

sudo systemctl status apache2

3. PHP Installation:

To install PHP and necessary extensions:

sudo apt install php libapache2-mod-php php-pgsql -y

Verify the PHP installation:

php -v

4. PostgreSQL and PostGIS Installation:

Install PostgreSQL along with some contrib packages:

sudo apt install postgresql postgresql-contrib -y

Check the status of PostgreSQL:

sudo systemctl status postgresql

Now, install PostGIS:

sudo apt install postgis postgresql-<VERSION>-postgis-3 -y

Note: Replace <VERSION> with your PostgreSQL version, e.g., 13 for PostgreSQL 13.

5. Database Setup:

Switch to the postgres user and enter the PostgreSQL environment:

sudo -u postgres psql

Now, create your database and enable PostGIS on it:

CREATE DATABASE your_database_name;
\c your_database_name
CREATE EXTENSION postgis;

(Optional) To create a new user:

CREATE USER your_user_name WITH ENCRYPTED PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE your_database_name TO your_user_name;

6. Securing Your Installation:

While setting up, always remember to secure your installations:

  • For Apache: Set up firewalls, disable directory listings, and use SSL certificates.
  • For PostgreSQL: Change default PostgreSQL user passwords, restrict remote access, and regularly backup your database.
  • Regularly update all components of your stack.

Conclusion:

You’ve successfully set up a LAMP stack with PostgreSQL and PostGIS on your EDIS Global VPS! This hybrid setup allows you to harness the power of traditional web hosting with the spatial capabilities of PostGIS. Always ensure to monitor, maintain, and back up your server for optimal performance and safety.

Remember, EDIS Global is here to support you every step of the way. For more tutorials and support, visit our knowledge base or contact our dedicated support team.