How To Configure Laravel Project For Production - FreeCodeBlog

Last updated: Dec 05, 2021

Want to deploy laravel project on live server, shared hosting, vps server, production? Wait a minute, have you configured the Laravel project for production? Laravel configuration for production! Yes. Before deploy laravel project on live server, shared hosting, vps server, production you need to configuration some laravel setting. Well tell me what kind of information do I need change for configuration before I put Laravel in production? Okay listen friends laravel project for production you need to configuration autoloader, debug mode, view cache, config cache, session, sitemap, timezone, app name, app env, route cache and more. So in this tutorial I will explain you how we can configure laravel project before deployment.

 

How To Configure Laravel Project For Production
How To Configure Laravel Project For Production.

 

1. Create Laravel Project.

You need to create a laravel simple project to configure before deployment. I already created a simple laravel project. If you do not know how to create a simple Laravel project, feel free to read how to create a simple laravel crud project tutorial.

 

2. Laravel Autoloader.

When deploying to production, make sure that you are optimizing Composer's class autoloader map so Composer can quickly find the proper file to load for a given class.

 

composer install --optimize-autoloader --no-dev

 

3. Laravel Config Cache.

Laravel configuration cache can save to your laravel project. So you should remove the configured cache from the Laravel project before placing it in production. You should make sure that you execute the configuration cache command before deploy on production.

 

php artisan config:cache

 

4. Laravel View Cache.

When placing your application in production, you need to make sure that you delete the view cache from your laravel project. Laravel view files can save cache in your laravel project.

 

php artisan view:cache

 

5. Laravel Debug Mode.

Your Laravel project APP_DEBUG should false when in production. You can edit APP_DEBUG mode before or after deploy on production. I recommend that you edit the app debug mode before deployment.

 

APP_DEBUG=false

 

6. Laravel Timezone.

You need to change the timezone according to your country. You will get timezone option in config app file. I live in Bangladesh so I will change the Laravel timezone according to my country.

 

'timezone' => 'Asia/Dhaka',  

 

7. Laravel Session.

Laravel session can be problem on production. Especially when you use the laravel file session. You may encounter database or file session errors in production. So you need to clear laravel session from your project before deploy. You need to remove app key from env file then run key generate command to regenerate laravel app key to clear laravel session.

 

APP_KEY=
php artisan key:generate

 

8. Laravel App Name.

Change laravel app name according to your domain name or whatever you want to use. My website domain name freecodeblog, so I will configure laravel app name according to my website domain name.

 

# for single word
APP_NAME=FreeCodeBlog
# for multiple words
APP_NAME="Free Code Blog"

 

9. Laravel App Env.

Actually you need to change the Laravel app env local to production from the env file before or after deployment. You can also change it on production.

 

APP_ENV=production

 

10. Laravel Route Cache.

If you are building a large application with many routes, you should make sure that you are running the route cache Artisan command during your deployment process.

 

php artisan route:cache

 

11. Files Completion For Production.

If you use vue js or react js or bootstrap or tailwind css or others then you need to compile your CSS and js file for production. If you don't know much about completion then read how to compile laravel css and js files tutorial. Don't forget to minify css and js files before deploy on production.

 

npm run prod

 

12. Laravel Sitemap.

Want to rank your website on search engine? You need to create a sitemap for laravel website before deploy it on live server. Want to make a sitemap in laravel? Yes. Okay then you need to read generate a laravel sitemap dynamically complete tutorial to create a sitemap in laravel. Make sure that you added most useful site URL in laravel sitemap.

 

13. Laravel Store Link.

Did you upload the image to the Laravel Storage folder? Yes. You may get storage link error on production. So you need to make sure you use the correct image storage path.

 

php artisan storage:link

 

14. Laravel Robot File.

Have a robot file in the Laravel project? You can add sitemap link in laravel robot file before putting on production. This step will help to rank your website on search engine.

 

Sitemap: sitemap-url

 

It is strong that if you configure the Laravel project before putting it into production then you can get less errors in production after deploy Laravel. Now what if you get some errors on production? Actually we have a solution for this condition. We already made a tutorial about configure laravel project after deploy on shared hosting cpanel

 

Okay so this is for today. See you again next tutorials. Thanks

Post Tags
Post Writer
masum7323
Masum Biswas (@masum7323)

My name is Masum Biswas. I'm a full stack developer. I live in Bangladesh and I love to write tutorials and tools that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, MySQL, VueJS, Tailwind CSS and Bootstrap from the early stage.

Follow Me On
Related Posts
Laravel Project Upload To Cpanel Using Private Github Repository

Private GitHub repository for laravel uploading! Yes, You can easily upload your laravel project to shared hosting cpanel using private GitHub... Read More

Show And Hide Password In Laravel Vue

make show and hide password in laravel vue using laravel ui package. Sometimes, we may require to show hide password input field so, user can see w... Read More

Use Laravel Socialite Package To Make A Login With Facebook

You can easily create login with facebook system in laravel using laravel first party package (laravel socialite). In this tutorial I will show you... Read More

Install Laravel Breeze Authentication First Party Package

You can use laravel breeze first party authentication in laravel 8 or other version. In this tutorial I will show you how we can install laravel br... Read More

Deploy Laravel Via Ftp On Shared Hosting Cpanel

Deploy laravel via ftp on cpanel! Want to deploy laravel on shared hosting cpanel via ftp? Yes. But why? Because I can't access cpanel public_HTML... Read More