How to put a Laravel App into Production

How to put a Laravel App into Production

Putting a Laravel App into Production: Manually deploying your Laravel project to a live web server

Introduction

You’ve been developing your new Laravel project locally for some time, you’ve hit your feature milestones and the app has passed testing. Everything is checked in to your git master branch, so now it’s time to deploy it to a live server and let your end customers access it.

Whilst there are a number of tools to help automate or simplify the deployment process, such as Laravel Forge, we believe it’s beneficial to go through the process of manually deploying a Laravel project at least once, as it helps with understanding the architecture and can make for smoother updates and easier troubleshooting in the future.

In this guide we’ll be doing just that, we’re not going to focus heavily on the server configuration side of things as this can vary depending on your host but instead on the steps required to get your app from your local environment into your production environment.

Prerequisites

We’ll assume you have access to a web server configured with the LAMP (Linux, Apache, MySQL, PHP) or LEMP (Linux, Nginx, MySQL, PHP) stack, with (at time of writing for Laravel 5.8, the following specs:

  • PHP >= 7.1.3
  • BCMath PHP Extension
  • Ctype PHP Extension
  • JSON PHP Extension
  • Mbstring PHP Extension
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

You’ll also need SSH access to run terminal commands as part of the deployment process.

We like DigitalOcean for quickly spinning up a server instance and getting everything configured (use this link to get a 30 day free trial with $50 credit to get you up and running). There’s some good guides on their site explaining these setup steps, and an example server configuration for Nginx in the Laravel docs.

Finally, we’ll assume you’ve checked your code into your git repository and you have all the necessary credentials to access it from your server.

Putting your Laravel app into production

Using the example server config file from the Laravel docs above, on your web server you will have an /example.com/ directory with a /public/ directory inside (depending on your specific server configuration this could be a /public_html/ directory or something else).

So first of all we’ll clone our project into the /example.com/ directory from our git repository. That directory is not publicly accessible and therefore maintains the security of the project files. Then we’ll create a symlink between our project’s /public/ directory and the /example.com/public/ directory.

So from inside the /example.com/ directory, run

git clone http://[GIT_SERVER]/your-app.git

You should see your project files in the /example.com/your-app/ directory now.

To link the /example.com/your-app/public/ directory to your /example.com/public/ directory run the following commands:

mv public public_bak
ln -s your-app/public public

Check that the paths in the following two lines in your index.php in /your-app/public/ are correct relative to the location of your project files:

require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';

If your app requires a database make sure you have a suitable database set up and have the credentials to hand.

Now we need to update the project’s .env file. These are usually not checked into git repositories by default as they can contain sensitive password information and local and production deployments will require different settings.

There should be an .env.example file in your project which you can rename to .env. The key areas to edit now are the database settings if a database is being used, and this section:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

Set APP_DEBUG to false and APP_ENV to production, and update the APP_NAME and APP_URL accordingly. If you leave APP_DEBUG as true, in the event of errors you’ll be displaying sensitive debug information to the world (see our Seaborne Freight article), so make sure you change it!

We need to set some folder permissions so they are writeable, specifically the /storage/ and /bootstrap/cache/ folders. These commands may vary depending on your server configuration, but the following commands should set the necessary folder permissions:

chmod -R o+w storage
chmod -R o+w bootstrap/cache

Now we need to install Composer, so run the following:

composer install — optimize-autoloader — no-dev

We need to generate an application key (the APP_KEY setting from the .env file above), to do this, run:

php artisan key:generate

Laravel uses this key for (amongst other things) encrypting cookies.

If you have any database migrations that need to be run to structure your tables, then run the following:

php artisan migrate

If you have seed data to populate your tables with, then run:

php artisan db:seed

That’s basically it! You should be able to go to your new site and see your Laravel project default page. Test out some of your app’s features and make sure the database is working as expected.

To cache the site config, run:

php artisan config:cache

To cache the routes, run:

php artisan route:cache

We hope this article has been a helpful overview of what’s involved with deploying Laravel based websites and web apps. If you need help with a deployment don’t hesitate to get in touch.

Hire PHP Developer and Web Developer for your Online Business

Hire PHP Developer and Web Developer for your Online Business

PHP is widely used open-source scripting language it helps in making dynamically easy your websites and web application. Mobiweb Technology is your best technical partner and offering you solution for any kind of website and application...

PHP is widely used open-source scripting language it helps in making dynamically easy your websites and web application. Mobiweb Technology is your best technical partner and offering you solution for any kind of website and application development. To hire PHP developer and web developer at affordable prices contact Mobiweb Technology via [email protected]

Laravel Framework Development Services | Laravel Web Development

CMARIX is leading Laravel Web application Development Service Provider with the track record of implementing diverse high-performance Laravel web applications with skilled Laravel developer team for clients across the globe<a href="https://www.cmarix.com/laravel-framework-development-services.html?utm_source=SB" target="_blank">.Continue</a>

CMARIX is leading Laravel Web application Development Service Provider with the track record of implementing diverse high-performance Laravel web applications with skilled Laravel developer team for clients across the globe.Continue

Which is the best PHP Web Development Company in India?

Which is the best PHP Web Development Company in India?

Many experienced players prefer to give it a go ahead with PHP for their web development needs because of the simplicity that PHP provides. PHP is loaded with features that many other languages lack and those pre-defined features can bring new functionalities and finishing touch to your existing or new website that you are looking forward to create. Wouldn’t it be great to get the best PHP Web Development Company for your project; we have a reputation as few of the leading firms in IT industry when it comes to PHP development.

Perks you should keep an eye out for before considering to outsource project to any web development company:

1. Company’s Reputation- It is very important to know about the previous projects that the company has delivered and the success rate of those products. You can visit company’s website for client testimonials or can google reviews given to them by genuine clients. We follow transparency, you can contact our previous clients and let them tell you how their experience was while working with us.

2. Technical Skill set and Expertise- You should select a company that has multiple resource pool of expert and technically sound developers. Our developers are experienced with different PHP frameworks and are exceptionally good with writing bug free codes. You can also hire PHP developer in India from us, as our developers have on hand experience in PHP development (core and frameworks)

3. The Budget- Costing has always played as one of the most important roles in every business deal. We provide competitive pricing with no hidden cost guaranteed. With us you can expect your project to be in best quality with no compromise to be made even with the best price in the market.

Why Data EximIT is the best PHP web development company in India?

Here are some of the features that might love about Data EximIT:

 Reputation of Data EximIT is wonderful among the previous clients.

 We have around 87% of retention ratio of clients.

 We were time committed, means every milestone was achieved before or on time.

 Data EximIT follows Agile development so it was the best possible methodology.

 We have huge team with different expertise over multiple PHP frameworks, so you are provided with ample to options to choose from.

 We are very active in communication part. Method or time of communication was never an issue at Data EximIT.

 We have some of the best designers to ensure that your project not only functions but also looks and feels fabulous.

 We provided customers with best costing without compromising on the quality at all.

 We also provide dedicated PHP developer or team of PHP developers on hire for your project.

Data EximIT is where customers feel confident to come up with idea and leave with fully functioning & best in quality projects. You can also avail our developers at your requested site location if you decide to hire PHP developers in India from us.

Feel free to contact our experts and let success reach you by working with the best PHP web development company.