Last updated: July 20, 2019
What is a PHP Framework?
A PHP framework is a suite of tools and templates for developing software applications.
It includes a methodology for organizing the code and designing the system architecture.
What is the Model-View-Controller Paradigm?
Laravel is a PHP framework built on the Model–View–Controller (MVC) paradigm. This is an approach towards application structuring that maintains the data, display, and business logic separately.
|Model||Defines data object types|
|View||Templates that present the data in a specific way|
|Controller||Controls application logic|
The Model is the data model. This is the code that defines the types of data objects the system will keep track of, as well as their attributes and relationships to each other.
The code in the model (along with basic utility classes in the core of Laravel) specifies how the application will interact with the database.
Laravel provides a “database abstraction layer,” which is a generic coding interface to a number of different supported database systems. Because of this, the primary data model (the Object Relational Model) is written directly into the application code, not in SQL.
An Interface With Purpose
The Model also provides an interface for updating the data associated with any object. It also syncs those updates to the database or other data persistence layer. This interface is accessed primarily by the Controller.
The View is a system of templates that present data from the model in a specified way, including:
- An HTML page viewable from a web browser
- A public data API
- An RSS feed
- Email templates, and
- Printed documents.
How Does The View Present Data?
The View does not manipulate data, it merely receives it from the Model and displays it as specified. This ensures that if you are (for example) looking at an analysis of site traffic, the data is exactly the same whether you view it as a list, a graph, or a pie chart.
This is an excerpt of PHP for logging into Homestead via SSH. Homestead is Laravel’s pre-packaged Vagrant box that comes loaded with 16 different software packages, including Ubuntu, Nginx, Apache, MariaDB, Redis, Memcached and 4 versions of PHP itself.
The Controller handles all the application logic. This begins with the connection between the Model and the View, as well as the connection to the web server or some other source of requests.
The Controller also handles any special conditional features. For example, if you want an email to be sent when a specific action occurs, that email is triggered by the Controller. (The Controller will no doubt receive information about the contents and recipient of the email from the Model. In turn, the View will provide the template for the actual message.)
When building a new web application in PHP, there are a number of common features that need to be included no matter what the application’s core functionality is.
This “boilerplate” development includes complex activities, such as user and session management. It also includes fundamental utility code, such as connecting with a database.
Very few developers really enjoy coding these types of features. It’s a lot of complicated and exacting work.
This is where PHP frameworks like Laravel come in handy.
Laravel and Basic App Features
Laravel modules provide all the core features that every web application needs, such as a database abstraction layer and user login.
Laravel takes this a step further and offers additional modules for commonly needed functionalities, including event listeners and the Laravel Cashier module for payment processing.
Even better, because Laravel uses Composer for package management, it is easy for developers to create, and for other developers to include generalized feature sets.
This is especially useful for software development teams building multiple apps in a related industry; domain-specific features can easily be modularized and included in multiple projects.
Developers building a new web application have an almost unlimited number of ways of designing the system and organizing their code. This complete freedom is the source of the great potential of software — anything is possible.
But this is also the source of many project failures and delays — anything bad is likewise possible. Rarely will a developer need to build an application for such an incredibly novel function that an entirely new approach is needed; rarer still will such an app be coded in PHP.
So it makes sense that a good web app framework would provide exactly what its name implies: a frame of an application that works for most developers, most of the time.
Laravel is strongly oriented toward best practices and a logically sensible architecture. Proof of this can be found in Artisan, Laravel’s command-line interface. Artisan automatically provides developers with helpful commands while coding
It isn’t just boilerplate features that require the use of a boilerplate code. The development of new functionality can often be equally tedious.
For example, imagine you are building a management application for an auto repair shop. You’ll want to create a class of data objects that keep track of vehicles. But you don’t just have to create a new class. You’ll also need to create the following:
- A View for Vehicles, as you’ll surely want to display a screen that shows the details of any specific vehicle;
- An index View to see a list of multiple vehicles at the same time;
- A route in the Controller for each of these, since their existence will be moot if your user can’t get to them;
- And finally, a way to confirm that all these different pieces of code all work together properly, so that you don’t misspell “vehicle” in one file or use the singular when you should have used the plural.
How Much Coding Is There To Do?
The Laravel framework provides a command line interface (CLI) that allows you to scaffold up code quickly.
All you do is declare the new model; the framework creates the various files and code blocks that are needed.
Of course, you still have to fill these in with the real code, but all the elements and the connections between them are pre-built.
Laravel Web Hosting
There are multiple considerations and tasks involved in provisioning and managing servers and deploying your app optimally.
Deploy PHP Apps Fast with Forge
You can provision and manage cloud servers in seconds with Laravel’s Forge service.
We provisioned a custom VPS server in under 60 seconds with a few clicks.
Forge also enables you to have SSH keys added automatically to every server you create. And you can connect to GitHub, GitLab, or Bitbucket and push to deploy — straight from the Forge dashboard.
Deploying PHP Apps Without Forge
If you’re not a Forge user, the critical issue for developing and hosting a Laravel application will be your ability to install and configure software on your server yourself.
Enable SSH Access
First, enable SSH access on your server. You can do this through the control panel. This lets you quickly add the framework and associated tools.
MCrypt and Databases
Laravel runs on PHP 5.4+ and requires the MCrypt Extension.
Depending on the type of application you are building, you will need a database management system of some sort. The exact choice is up to you, although several are supported.
Moreover, you will need to think about which applications need to be installed on your server.
Consider which tools you’ll use when deploying Laravel applications on your server; these tools will dictate which host is ultimately right for you.
How Do I Install Laravel?
You can install Laravel in one of two ways: manually or through the Softaculous installer software. Related applications, libraries, and dependencies will then be handled by the Composer dependency management tool that Laravel requires.
You will also need SSH access in order to sync your Git repository to your server. With each of these three essential pieces enabled for your PHP workflow, you’ll be able to build, test, and deploy projects more easily.
Do I Need VPS or a Dedicated Server?
Note that not all shared hosting plans provide this level of control and access to the server environment. As a result, you may need to use a VPS account or run your own dedicated server to code with the Laravel web app framework.
Top Hosting Providers for Laravel Framework
A web host needs to provide several minimum requirements in order to provide the ideal working environment for the Laravel framework.
For starters, SSH access is a must. Without it, you won’t be able to install Laravel, Composer, or Git on your server. Each of these is necessary for your coding workflow.
Secondly, it must operate at top speed. When you’re using a PHP framework that’s so elegantly composed, you don’t want to throw all that away by compromising on how well it deploys to your site. Therefore, an Apache or NGINX server, or other speed-enhancing tools, are likewise necessary.
InMotion Hosting for Laravel.
My #1 hosting recommendation for Laravel web development is InMotion Hosting. InMotion’s support professionals provide fantastic service and assistance to Laravel developers in getting the framework up and running.
Cloudways hosting for Laravel.
Alternatively, Cloudways hosting may be an excellent choice for developers who spend a lot of time writing code in Git as well as in staging.
So, if you need a server environment built to support easy deployment from one app to another instead of just focusing on the end results, Cloudways is the best option.
WebHostface hosting for Laravel.
Finally, WebHostFace has Laravel-specific hosting plans available that cover everything you’ll need for working safely and quickly with the framework.
Plans include services for installation, security, and Laravel update maintenance.
Laravel Hosting Summary
Sophisticated syntax and model-view-controller organized structuring make the Laravel framework a powerful weapon in your coding arsenal.
Not every web hosting company or plan type will be suitable for working with the Laravel framework. Start by defining your goals carefully, then choose a web hosting plan that best aligns with them.
Other features in Languages and Frameworks
- .NET Framework
- Ruby on Rails
- Server Side Includes
- PHP 5
- PHP 7
Laravel Frequently Asked Questions
- What is Laravel?
Laravel is a PHP web application framework. It’s a set of tools designed to make building a web application with PHP easier and faster, and produce a final product that is secure and follows best practices.
- What’s the benefit of using a programming framework?
A good framework like Laravel will take care of a lot of the boilerplate work that goes into creating virtually any web application and also help you avoid certain coding pitfalls.
Frameworks are designed to help you save time and to encourage the following of development best practices.
- Do I need to use a programming framework?
You don’t have to use a framework. As a matter of fact, some purists, who tend to be extremely good developers, consider frameworks to incur unnecessary overhead and add unnecessary dependencies and encourage other developers to avoid using them.
- Do I need to know PHP to use Laravel?
You need to be an intermediate PHP coder and understand the basics of object-oriented programming (OOP) before you try to jump into Laravel.
However, you don’t need to be an expert. Because Laravel encourages best practices, it may actually provide a bigger boost to beginner and intermediate developers than experienced professional PHP developers.
- What are the Laravel installation requirements?
The exact requirements your server will need to meet before running Laravel vary a bit from on version of Laravel to the next.
In general, you will need to be running a currently supported version of PHP and you’ll need to have the ability to install PHP extensions in the event that any required extensions are missing.
Further, you need to install Composer on your server before you attempt Laravel installation.
- Can I run Laravel on a Windows server?
Yes, you can install Laravel on a Windows server.
Keep in mind that the large majority of Laravel users are working with Linux servers. So if you run into trouble running Laravel on a Windows server you will have a harder time finding help than if you set up Laravel on a Linux server.
- How do I get and install Laravel?
Laravel is easiest to install by executing a series of commands via command line. So you’ll need to use SSH to access the server where you’ll be running Laravel and then execute this series of commands.
If you aren’t comfortable using SSH, then this is the perfect opportunity to learn to use SSH because any competent web developer needs to master this skill.
- How much does Laravel cost?
Laravel is free and open-source.
- Can I use Laravel on shared hosting?
Laravel developers report mixed results when trying to set up Laravel on shared hosting.
The bottom line is that Laravel isn’t really intended to work on shared hosting.
You can probably get it working if you work on it hard enough, but you’ll be better served to get it set up on a small and inexpensive VPS if you’re just setting up Laravel for the first time.
- What kind of applications can you build with Laravel?
Laravel is designed to build web applications based on a model-view-controller (MVC) architecture. That leaves the door open to a lot of different types of web-based applications.
For example, Laravel can be used to build reservation systems like AirportParkingReservations.com, classified listing sites like HomeListingsFinder.com, ecommerce sites like rv.CampingWorld.com, and directories like ExploreGeorgia.org.
Basically, any web application that deals with data that can easily be broken into consistent objects is a candidate for Laravel.
- Is Laravel getting more popular?
According to Built With, Laravel was used by less than 3500 of the top one million sites at the beginning of 2016 but more than 5000 of the top one million sites one year later.
Although no one can predict the future, that’s a pretty sizable installed base, suggesting Laravel is reasonably well established and should be around for years to come.
- Why should I avoid using Laravel?
Not all PHP developers like Laravel.
The most common complaint leveled at Laravel is regarding a Laravel feature called facades. Improperly used, facades can obscure what is going on under the surface and lead inexperienced programmers to write overly complex code, ironically while trying to write simple code.
If you want to learn more about this issue check out Stop Using Facades as well the response from Laravel creator Taylor Otwell, Response: Don’t Use Facades.
- What are some alternatives to Laravel?
There are lots of PHP frameworks you could consider if you’re looking for an alternative to Laravel. Start your search by researching CodeIgniter, Symfony, Zend, and CakePHP.
- What are Laravel packages?
Let’s say you’re building an application with Laravel and find yourself developing a part of the application that will send messages to Slack. Then you think to yourself, “Surely someone else has already done this and I could save a lot of time if I could use their code.”
In that instance, what you’re looking for is a package: a pre-built bit of code you can use to take care of a task that another developer has already created.
- Where can I find Laravel packages?
Laravel packages can usually be found in one of two places: Github or Packalyst. Start at Packalyst. There you’ll find thousands of Laravel packages which you can sort by popularity or age, and search by keyword or tag.