实时部署Laravel Web应用程序最简单,最快的方法是什么?

实时部署Laravel Web应用程序最简单,最快的方法是什么?

问题描述:

完成Laravel网站后,我意识到它的工作方式不像WordPress,您可以在其中将其直接从localhost部署到实时服务器.我该怎么办?

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?

以下是将laravel网站部署到不同类型主机的方法:

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

共享主机:

首先,我们不建议为您的laravel应用程序使用共享托管.有非常便宜的VPS网络托管服务提供商,您可以使用每月5美元起的价格,但是如果您使用共享托管,仍然可以在这里找到如何启动您的laravel网站:

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:

  • 对于具有SSH访问权限的共享主机: 主要的共享托管服务提供商(例如goDaddy,1& 1托管)已预先安装了composer,而您所要做的就是将laravel项目上传到共享托管并使用composer和(使用SSH)运行安装然后使用php artisan设置密钥.另外,您还将网站的根目录更改为WEBSITE_LOCATION_ON_SERVER/public,并确保目录索引已关闭.

  • 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有些托管服务提供商也不允许您使用SSH下载作曲家,在这种情况下,您可以使用下面的方法.

用于没有SSH访问权限的共享主机: 许多共享的托管服务提供商没有为您提供SSH访问权限,这意味着没有作曲家,也没有php artisan命令,在这种情况下,您将必须创建与(Apache,Php,MySQL和OS)相同的环境(Apache,Php,MySQL和OS)在本地计算机上托管提供商,然后将项目上传到实时服务器.

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.

Ps这是最坏的情况,因为您将必须在本地计算机上设置所有内容,而且您将无法在实时服务器上使用php artisan,并且如果您在项目中进行更改,您将拥有再次上传整个项目.

专用/VPS托管:

这是laravel网站最推荐的托管方法,因为您将拥有托管的完全访问权限.要部署该应用程序,首先,您必须安装作曲家,然后将文件上传到服务器,然后运行安装程序,并确保关闭目录索引.然后,将根目录更改为WEBSITE_LOCATION_ON_SERVER/public,然后运行以下命令,以使您的laravel应用程序具有运行所需的所有权限:

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.