What is the easiest and quickest method to deploy

2020-05-06 07:53发布

问题:

After finishing a Laravel website, I realized it doesn't work like work like WordPress, where you can deploy it directly from localhost to live server. How do I do it?

回答1:

Here's how you can deploy your laravel site to different kinds of hostings:

Shared Hosting:

First, it is well discouraged to use a shared hosting for your laravel app. There are very cheap VPS web hosting providers starting from $5/month that you can use but still if you are using shared hosting here is how to get your laravel site live:

  • For shared hostings with SSH access: Major shared hosting providers (like goDaddy, 1&1 hosting) have composer pre installed and all you have to do is upload your laravel project to your shared hosting and run the installation (using SSH) using composer and then setup the key with php artisan. Also you will have change the root directory for your website to WEBSITE_LOCATION_ON_SERVER/public and also make sure the directory indexing is off.

    If your hosting provider doesn't provide composer pre installed then will have to install composer first and then do the setup.

    P.s There are some hosting providers that won't let you download composer using SSH as well, you can use the method below in that case.

  • For shared hosting without SSH access: Many shared hosting providers don't give you SSH access which means no composer and no php artisan commands, in that case you will have to make the same environment (Apache, Php, MySQL and OS) as the hosting provider's on your local machine and then upload the project to the live server.

    P.s This is the worst case as you will have to setup everything on your local machine and also you won't be able to use php artisan on the live server and if you make changes in your project you will have to upload the complete project again.

Dedicated / VPS hosting:

This is the most recommended hosting method for laravel site, as you will have full access of your hosting. To deploy the app, first, you will have to install composer and then upload your files to the server and then run the installation and make sure the directory indexing in off. Then, change the root directory to WEBSITE_LOCATION_ON_SERVER/public and then run the following commands to give your laravel app all the required permissions to run:

sudo chown -R www-data:www-data /PATH_TO_LARAVELAPP

.

sudo usermod -a -G www-data YOUR_USERNAME

.

sudo find /PATH_TO_LARAVELAPP -type d -exec chmod 755 {} \;

.

sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

Hope this answers your question well, for questions drop a comment.



回答2:

i would recommend to use cpanel as shared host.

-copy all files to public_html folder.

  • copy .env file that have proper configuration of your database on host

  • vendor folder

  • change PHP version to 7.2

  • in your public_html folder add .htaccess file that contains below codes :

<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] </IfModule>