Maintenance

  • Home
  • Log in
  • « Dell monitor RMA
  • Hard drive failure »

Setting up a PHP/PostgreSQL development environment on VirtualBox

Posted by gregster on 03 Dec 2015 in Servers, Activity log

I needed a decent development sandbox for PHP/PostgreSQL and didn't want to muck up my desktop install, so I made one in VirtualBox. Here's how I did it.

New VM with Ubuntu 14.04 server (8GB RAM/120GB HDD/NAT, with Port-forwarding)
Port-forwarding set up with 2 rules (note that you may need to adjust the IP to whatever IP the VM gets).
Rule 1
Protocol: TCP
Host IP: 127.0.0.1
Host Port: 8888
Guest IP: 10.0.2.15
Guest Port: 80

Rule 2
Protocol: TCP
Host IP: 127.0.0.1
Host Port: 2222
Guest IP: 10.0.2.15
Guest Port: 22

Take snapshot of VM!

Once the OS is installed you should be able to ssh in to it like this:
ssh myusername@127.0.0.1 -p 2222
and we can install PostgreSQL 9.4, PHP5.6, and PHPpgAdmin

Add repos
PG 9.4: add 'deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main' to /etc/apt/sources.list
PHP5.6: add-apt-repository ppa:ondrej/php5-5.6

Import PG signing key
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

Install everything
apt-get update && apt-get install postgresql-9.4 phppgadmin php5 php5-curl
** note that installing php5 installs apache as well

Set up PostgreSQL
Set “postgres” user password
============================
Login to postgresql prompt:
sudo -u postgres psql postgres

and set postgres password with following command:
postgres=# \password postgres
Enter new password:
Enter it again:
postgres=# \q

To install PostgreSQL Adminpack, enter the command in postgresql prompt:
==============================================
sudo -u postgres psql postgres
postgres=# CREATE EXTENSION adminpack;
CREATE EXTENSION
Type \q in the psql prompt to exit from posgresql prompt, and return back to the Terminal.

Create New User and Database
============================
To create a new user called “kahuna” with password “bigwheel”, and database called “mydb”.

sudo -u postgres
postgres=# psql template1
template1=# CREATE USER kahuna WITH PASSWORD 'bigwheel';
template1=# CREATE DATABASE mydb;
template1=# GRANT ALL PRIVILEGES ON DATABASE "mydb" to kahuna;
template1=# \q

Configure PHPpgAdmin
====================
Edit /etc/apache2/apache2.conf and add the following line to it:
Include /etc/apache2/conf.d/phppgadmin

To access phppgadmin remotely:
sudo nano /etc/apache2/conf.d/phppgadmin
Comment out the line "allow from 127.0.0.0/255.0.0.0 ::1/128" and uncomment the line below it, "allow from all".
sudo apache2ctl restart

Should now be able to access phppgadmin on host OS at http://127.0.0.1:8888/phppgadmin

Take snapshot of VM!

I'm trying out PHPStorm as an IDE. Here's how I'm configuring my environment:
* install same version of php on my local machine as on the VM (5.6) along with xdebug.
* follow excellent docs on JetBrains website for getting IDE talking to underlying php/xdebug
* use 'new project' wizard to connect to vm over ssh
* check that debugging works (ctrl+f5)

This entry was posted by Greg and filed under Servers, Activity log.

Maintenance

This blog is the location for all work involving software and hardware maintenance, updates, installs, etc., both routine and urgent.
  • Home
  • Recently
  • Archives
  • Categories

Search

Categories

  • All
  • Announcements
  • Hit by a bus
  • Labs
    • Activity log
    • Documentation
  • Notes
  • R & D
    • Activity log
    • Documentation
  • Servers
    • Activity log
    • Documentation
  • Tasks

All blogs

  • Academic
  • AdaptiveDB
  • Admin
  • Announcements
  • CanMys
  • Cascade
  • CGWP
  • ColDesp
  • Depts
  • DVPP
  • Endings
  • HCMC Blogs
  • Landscapes
  • LEMDO
  • Linguistics
  • Maint
  • LondonMap
  • Mariage
  • MoM
  • Moses
  • Pro-D
  • Projects
  • ScanCan
  • HumsSites
  • Wendat

This collection ©2026 by admin • Help • b2evo