问题描述
我建立了一个 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!