(如何)使用 FTP 部署 Laravel

2023-10-30php开发问题
2

本文介绍了(如何)使用 FTP 部署 Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我建立了一个 laravel 项目,我通常使用 localhost 和命令php artisan serve"来测试我的项目

I built a laravel project and I normally use localhost with the command "php artisan serve" to test my project

但是现在,我想在服务器上托管.我使用 FileZilla 成功连接了我的服务器.我测试了我可以放一个简单的 abc.html 文件,并且可以通过 ___.com/abc.html 访问

But now, I want to host on server. I successfully connected my server with using FileZilla. and I tested I can put a simple abc.html file and can be accessed with ___.com/abc.html

如何将我的 laravel 项目部署到我的服务器上?我可以将整个 laravel 项目上传到服务器然后无需任何命令即可访问吗?还是必须通过 SSH 远程安装一些东西?

How to deploy my laravel project to my server? Can I just upload the whole laravel project to server then can access without any command? or must need to remote with SSH and install something?

谢谢!

推荐答案

部署到共享主机:

压缩您的项目并将其上传到 public_html 并提取它

Zip your project and upload it to public_html and Extract it

在 mysql 数据库中创建数据库(在 cPanel 中)

Create Database in mysql databases ( in cPanel )

从本地phpmyadmin导入.sql文件到在线托管

Import .sql file from local phpmyadmin to online hosting

现在转到public_html并编辑.env文件,更改以下内容

Now go to public_html and edit .env file, change the following

DB_DATABASE=yourdatabasename
DB_USERNAME=database username
DB_PASSWORD=database password

现在只需打开 yourwebsite.com,您的应用就会出现!

and now just open yourwebsite.com and your app will be there !

在云主机上部署

首先去你的站点或host/phpmyadmin创建新数据库并上传你的sql数据库文件(你可以从本地phpmyadmin导入)

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 )

创建 Drop 并上传所有文件

点击create new droplet并从应用程序选项卡中选择LAMP,现在通过filezilla将所有文件上传到您的droplets文件夹(/var/www/html)

Click on create new droplet and select LAMP from applications tab , now upload all files to your droplets folder (/var/www/html) through filezilla

注意:请确保您在上传前更改了 .env 中的数据库用户名、密码和名称

Note : Make sure you changed database username , password and name in .env before uploading

通过 SSH (Putty) 连接到 droplet现在通过 putty 连接到 droplet 并运行以下命令

Connect to droplet through SSH (Putty) Now connect to droplet through putty and run below commands

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

启用模块

运行以下命令以启用 mod_rewrite 模块

Run below command to enable mod_rewrite module

sudo a2enmod rewrite

现在打开 000-default.conf

Now open 000-default.conf

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

在下面添加以下行

 AllowOverride all 

现在重启apache2服务器

Now restart apache2 server

sudo service apache2 restart 

就是这样,现在转到您的 site.com,应用程序将在那里跳舞.

That's it now go to your site.com and app will be dancing there.

这篇关于(如何)使用 FTP 部署 Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17