简体   繁体   English

(如何)使用FTP部署Laravel

[英](How) Laravel Deploy with FTP

I built a laravel project and I normally use localhost with the command "php artisan serve" to test my project 我建立了一个laravel项目,通常使用localhost和命令“ php artisan serve”来测试我的项目

But now, I want to host on server. 但是现在,我想在服务器上托管。 I successfully connected my server with using FileZilla. 我使用FileZilla成功连接了服务器。 and I tested I can put a simple abc.html file and can be accessed with ___.com/abc.html 我测试了可以放一个简单的abc.html文件,并可以通过___.com/abc.html进行访问

How to deploy my laravel project to my server? 如何将laravel项目部署到服务器? Can I just upload the whole laravel project to server then can access without any command? 我可以将整个laravel项目上传到服务器,然后无需任何命令即可访问吗? or must need to remote with SSH and install something? 还是必须使用SSH远程安装某些东西?

Thanks! 谢谢!

Simply drag and drop the root folder to your server's root . 只需将根文件夹拖放到服务器的root即可 Not to the public_html directory. 不到public_html目录。 The only thing that should be in the public_html directory is Laravel's "public" directory (thus you have to rename it, depending on your server's settings). 唯一应该在public_html目录中的是Laravel的“ public”目录(因此,您必须重命名它,具体取决于服务器的设置)。

Do not put your configuration files inside the public_html folder or anyone will be able to access them and steal your data. 请勿将您的配置文件放在public_html文件夹中,否则任何人都可以访问它们并窃取您的数据。

Did you make sure that you pointed the web server to the public/ folder? 您是否确定将Web服务器指向public/文件夹? There is an index.php file in that folder that bootstraps the entire site. 该文件夹中有一个index.php文件,它会引导整个站点。

Deploying to Shared Hosting: 部署到共享主机:

Zip your project and upload it to public_html and Extract it 压缩项目并将其上传到public_html并解压缩

Create Database in mysql databases ( in cPanel ) 在mysql数据库中创建数据库(在cPanel中)

Import .sql file from local phpmyadmin to online hosting 从本地phpmyadmin导入.sql文件到在线托管

Now go to public_html and edit .env file, change the following 现在转到public_html并编辑.env文件,更改以下内容

DB_DATABASE=yourdatabasename
DB_USERNAME=database username
DB_PASSWORD=database password

and now just open yourwebsite.com and your app will be there ! 现在只要打开yourwebsite.com,您的应用程序就会在那里!

Deploying On Cloud Hosting 在云托管上部署

First of all go to your site or host/phpmyadmin and create new database and upload your sql database file ( which you can import from local phpmyadmin ) 首先,进入您的站点或host / phpmyadmin并创建新数据库并上传sql数据库文件(您可以从本地phpmyadmin导入)

Create Drop and upload all files 创建拖放并上传所有文件

Click on create new droplet and select LAMP from applications tab , now upload all files to your droplets folder (/var/www/html) through filezilla 单击“创建新的Droplet”,然后从“应用程序”选项卡中选择“ LAMP”,现在通过filezilla将所有文件上传到您的Droplet文件夹(/var/www/html)

Note : Make sure you changed database username , password and name in .env before uploading 注意:上传之前,请确保您已在.env中更改了数据库用户名,密码和名称

Connect to droplet through SSH (Putty) Now connect to droplet through putty and run below commands 通过SSH(Putty)连接到Droplet现在通过Putty连接到Droplet并运行以下命令

chgrp -R www-data /var/www/html chgrp -R www-data / var / www / html

chmod -R 775 /var/www/html/.env chmod -R 775 /var/www/html/.env

chmod -R 775 /var/www/html/storage chmod -R 775 / var / www / html / storage

chmod -R 775 /var/www/html/bootstrap chmod -R 775 / var / www / html / bootstrap

chmod -R 775 /var/www/html/public/uploads chmod -R 775 / var / www / html / public / uploads

Enable Modules 启用模块

Run below command to enable mod_rewrite module 运行以下命令以启用mod_rewrite模块

sudo a2enmod rewrite

Now open 000-default.conf 现在打开000-default.conf

sudo nano /etc/apache2/sites-available/000-default.conf

Add below lines below 在下面添加以下行

 AllowOverride all 

Now restart apache2 server 现在重启apache2服务器

sudo service apache2 restart 

That's it now go to your site.com and app will be dancing there. 就是这样,现在转到您的site.com,应用将在那里跳舞。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM