Software Development Hub
15.5K views | +0 today
 
Scooped by Srdjan Strbanovic
onto Software Development Hub
March 3, 2014 4:59 PM
Scoop.it!

How To Horizontally Scale a Laravel 4 App with a PostgreSQL Database | DigitalOcean

How To Horizontally Scale a Laravel 4 App with a PostgreSQL Database | DigitalOcean | Software Development Hub | Scoop.it
Introduction



There are two methods to scaling an application, service, server, etc. The first, vertical scaling, calls for more resources to a machine. The second, horizontal scaling, calls for a separation of functionality to create a more piecemeal assembly of parts.

For example, does a machine spit out memory errors in the syslog? It may make sense to just add more RAM or a swapfile. However, let's say the database server is growing to a large amount of entries and the web server alone is starting to increase in traffic – a better idea may be to set up a more controllable environment (not to mention more cost effective). To do so, a separation of the web server and database server into separate machines is the key. That is horizontal scaling.

Requirements




Two droplets each running Debian 7. Each VPS should have completed Initial Server Setup tutorial.
A basic understanding of Linux commands and what they do. See An Introduction to Linux Basics for a good starting point.
You will need to have installed Laravel successfully on one of the droplets. This tutorial will work for NGINX + Laravel 4 (skip the Wrap Up step): Laravel + Nginx


Do not install a database on the same virtual server as your Laravel install

For the sake of simplicity, we will refer to the first droplet with the Laravel and Nginx install as the Laravel droplet with an IP of 192.0.2.5. The second droplet with the PostgreSQL install will be called the database droplet with an IP of 192.0.2.1.

Prepping the Database



Horizontal scaling is a rather simple concept that can be come rather complex when you start thinking about more advanced topics such as database replication and load balancing. However we'll only be covering a basic separation of services: the web server frontend and the database backend. Luckily PostgreSQL and Laravel make this a rather simple process.

First we will need to install PostgreSQL on our database droplet:

sudo apt-get install postgresql

Next, we must create a database and user within the server that will have the proper permissions to interact with the database. To do so, we must log into the PostgreSQL server:

sudo -u postgres psql

First, let's create the database user:

CREATE USER databaseuser WITH PASSWORD 'password';
GRANT CREATE ON SCHEMA public TO databaseuser;
GRANT USAGE ON SCHEMA public TO databaseuser;


Then create the database with the user as the owner and then quit the server:

CREATE DATABASE mydatabase WITH OWNER databaseuser;
\q


Next, the database droplet will need to know that it's okay for the Laravel droplet to connect to it. PostgreSQL has a client authentication file that makes this super easy.

sudo nano /etc/postgresql/9.1/main/pg_hba.conf

Add a line that includes the connection, database name, database user, address to be accepted, and the method of connection:

# IPv4 local connections:
host mydatabase databaseuser 192.0.2.5/32 md5


Save and exit, then open up postgresql.conf and find the line that says "listen_addresses = 'localhost'".

sudo nano /etc/postgresql/9.1/main/postgresql.conf

listen_addresses = '192.0.2.1'


You may also change this value to one that will accept any address:

listen_addresses = '*'


Save, exit, and restart the PostgreSQL server:

sudo service postgresql restart

Configuring Laravel



The first thing that needs to be done is to give PHP some knowledge of how to work with the PostgreSQL server. Do so by installing the php5-pgsql extension.

sudo apt-get install php5-pgsql

sudo service php5-fpm restart

Next we need to tell Laravel where our database server is located and how to access it. If you followed the NGINX + Laravel tutorial, then Laravel should be installed at /var/www/laravel.

sudo nano /var/www/laravel/app/config/database.php

First let's have Laravel use it's PostgreSQL driver:

'default' => 'pgsql',


Next, let's setup information about the PostgreSQL server.

'pgsql' => array(
'driver' => 'pgsql',
'host' => '192.0.2.1',
'database' => 'mydatabase',
'username' => 'databaseuser',
'password' => 'password',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),


Save and exit.

Testing the Connection



To test this connection, let's run a migration in from the command line that will help build our database tables out.

Note: Migrations isn't an extra package to be installed. It comes with laravel and it's a set of commands to interact with our database.

First enter the application directory where artisan is located.

cd /var/www/laravel

Great! Now it's time to install migrations and see if our database connection is working.

php artisan migrate:install

If this command runs successfully without errors you should see a new table in your database called migrations.

Wrapping it Up



As you can see, splitting servers is rather simple. By combining horizontal scaling with vertical scaling, a sysadmin can achieve separation of services and increased performance. Even better these methods require 0 extra software.

Submitted by: Alex Kavon
No comment yet.
Software Development Hub
Model Driven, Domain Specific Languages, Meta Programming
Your new post is loading...
Your new post is loading...
Scooped by Srdjan Strbanovic
December 4, 2011 2:28 PM
Scoop.it!

Create a Language Compiler for the .NET Framework Using C#

Create a Language Compiler for the .NET Framework Using C# | Software Development Hub | Scoop.it
No comment yet.
Scooped by Srdjan Strbanovic
April 2, 2015 3:45 PM
Scoop.it!

Microservices, Node.js, Containers!

Microservices, Node.js, Containers! | Software Development Hub | Scoop.it
Why Microservices, Node.js and Containers are an awesome combination to build highly decoupled and decentralized applications.
No comment yet.
Scooped by Srdjan Strbanovic
March 31, 2015 10:03 AM
Scoop.it!

Towards Heroku for Unikernels: Part 1 - Automated deployment | Amir Chaudhry

Towards Heroku for Unikernels: Part 1 - Automated deployment | Amir Chaudhry | Software Development Hub | Scoop.it
No comment yet.
Scooped by Srdjan Strbanovic
March 27, 2015 2:28 PM
Scoop.it!

Scalable Atomic Visibility with RAMP Transactions

Scalable Atomic Visibility with RAMP Transactions | Software Development Hub | Scoop.it
Scalable Atomic Visibility with RAMP Transactions - Bailis et al. 2014 RAMP transactions came up last week as part of the secret sauce in Coordination avoidance in database systems that contributed...
No comment yet.
Scooped by Srdjan Strbanovic
March 18, 2015 5:33 PM
Scoop.it!

KPIs for APIs (and how API Calls are the new Web Hits, and you may be…

How do you measure API success? What KPIs do APIs need? What mistakes should I avoid? Find out what you should, and shouldn't, be measuring as part of your API…
No comment yet.
Scooped by Srdjan Strbanovic
February 23, 2015 12:17 PM
Scoop.it!

Nginx Optimization: understanding sendfile, tcp_nodelay and tcp_nopush

Nginx Optimization: understanding sendfile, tcp_nodelay and tcp_nopush | Software Development Hub | Scoop.it
This article a is translation by popular request of Optimisations Nginx, bien comprendre sendfile, tcpnodelay et tcpnopush I wrote in French in January. Most ar...
No comment yet.
Scooped by Srdjan Strbanovic
February 11, 2015 5:29 PM
Scoop.it!

Code Project articles | John D. Cook

Code Project articles | John D. Cook | Software Development Hub | Scoop.it
This week's resource post lists some articles along with source code I've posted on CodeProject. Probability Pitfalls in Random Number Generation includes
No comment yet.
Scooped by Srdjan Strbanovic
February 9, 2015 12:45 PM
Scoop.it!

Laws of Programming with Concurrency - Microsoft Research

Laws of Programming with Concurrency - Microsoft Research | Software Development Hub | Scoop.it
No comment yet.
Scooped by Srdjan Strbanovic
February 2, 2015 1:56 PM
Scoop.it!

The Missing Piece in Complex Analytics

The Missing Piece in Complex Analytics: Low latency scalable model management and serving with Velox - Crankshaw et al. 2015. Analytics at scale can be used to create statistical models for making ...
No comment yet.
Rescooped by Srdjan Strbanovic from Docker
January 30, 2015 8:23 AM
Scoop.it!

Intro to Docker Swarm: Part 4 - Demo

Intro to Docker Swarm: Part 4 - Demo | Software Development Hub | Scoop.it
A hands-on demo of Docker Swarm (Vagrant)

Via Docker
No comment yet.
Scooped by Srdjan Strbanovic
January 24, 2015 12:58 PM
Scoop.it!

State Machines and Computation | Chorus.JS

State Machines and Computation | Chorus.JS | Software Development Hub | Scoop.it
No comment yet.
Scooped by Srdjan Strbanovic
April 3, 2015 11:03 AM
Scoop.it!

Towards Heroku for Unikernels: Part 2 - Self Scaling Systems | Amir Chaudhry

Towards Heroku for Unikernels: Part 2 - Self Scaling Systems | Amir Chaudhry | Software Development Hub | Scoop.it
No comment yet.
Scooped by Srdjan Strbanovic
March 31, 2015 12:04 PM
Scoop.it!

7 Unikernel Projects to Take On Docker in 2015 | Linux.com

7 Unikernel Projects to Take On Docker in 2015 | Linux.com | Software Development Hub | Scoop.it
Xen Project Advisory Board Chairman Lars Kurth takes a closer look at the rise of unikernels and several up-and-coming projects to keep close tabs on in the coming months.
No comment yet.
Scooped by Srdjan Strbanovic
March 30, 2015 4:23 PM
Scoop.it!

Graphs in data modeling — is the emperor naked? — Medium

Graphs in data modeling — is the emperor naked? — Medium | Software Development Hub | Scoop.it
Are graphs and graph databases useful in data modeling, and if so, for what and under which circumstances?
No comment yet.
Scooped by Srdjan Strbanovic
March 25, 2015 12:29 PM
Scoop.it!

A unikernel experiment: A VM for every URL

A unikernel experiment: A VM for every URL | Software Development Hub | Scoop.it
No comment yet.
Scooped by Srdjan Strbanovic
March 18, 2015 5:28 PM
Scoop.it!

Modelling game economy with Neo4j | AirPair

Modelling game economy with Neo4j | AirPair | Software Development Hub | Scoop.it
No comment yet.
Scooped by Srdjan Strbanovic
February 18, 2015 7:25 PM
Scoop.it!

The Log: What every software engineer should know about real-time data's unifying abstraction | LinkedIn Engineering

The Log: What every software engineer should know about real-time data's unifying abstraction | LinkedIn Engineering | Software Development Hub | Scoop.it

We're seeking intelligent problem solvers who are inspired and motivated to change the world.

No comment yet.
Scooped by Srdjan Strbanovic
February 9, 2015 7:55 PM
Scoop.it!

Introducing Espresso - LinkedIn's hot new distributed document store | LinkedIn Engineering

Introducing Espresso - LinkedIn's hot new distributed document store | LinkedIn Engineering | Software Development Hub | Scoop.it
We're seeking intelligent problem solvers who are inspired and motivated to change the world.
No comment yet.
Scooped by Srdjan Strbanovic
February 9, 2015 12:43 PM
Scoop.it!

NoSQL Is Dead

NoSQL Is Dead | Software Development Hub | Scoop.it
Eric Redmond explains the differences and commonalities amongst many kinds of databases and takes a stab at the marketing term “NoSQL.”
No comment yet.
Scooped by Srdjan Strbanovic
February 3, 2015 6:37 PM
Scoop.it!

All Models of Learning have Flaws « Machine Learning (Theory)

All Models of Learning have Flaws « Machine Learning (Theory) | Software Development Hub | Scoop.it
No comment yet.
Scooped by Srdjan Strbanovic
January 31, 2015 6:04 PM
Scoop.it!

A MITRE Quick Reference

A MITRE Quick Reference | Software Development Hub | Scoop.it
MITRE‘s mission is to make it easier to secure American infrastructure, which they accomplish mostly through the release of excellent dictionary and metrics projects. It’s hard to keep current with all of them, so I’ve created a list consisting of just the linked name and a one-line description of the project. CVE: Common Vulnerability Enumeration …
No comment yet.
Scooped by Srdjan Strbanovic
January 27, 2015 11:22 AM
Scoop.it!

Exactly-once Messaging Patterns in Kafka

Exactly-once Messaging Patterns in Kafka
No comment yet.
Scooped by Srdjan Strbanovic
January 27, 2015 11:22 AM
Scoop.it!

Doing the Impossible | ben.kirw.in

No comment yet.
Scooped by Srdjan Strbanovic
January 22, 2015 6:04 PM
Scoop.it!

An Encoding Primer

An Encoding Primer | Software Development Hub | Scoop.it
Concepts The Old Way The New Way A Note About “Plain Text” The Standards ASCII Extended ASCII IBM (OEM) Code Pages ANSI (Microsoft) Code Pages Unicode UTF-8/16/32 UCS Encoding UCS-2/4 UTF-7 ISO 8859 FAQ What’s the difference between Unicode and UCS? What is the basic multilingual plane? I’m confused. Which standards encode to which lengths? …
No comment yet.