Laravel应用程序的部署有什么问题?我需要一个有效的域而不是在本地环境中使用的虚拟主机吗? [英] What is wrong in the deploy of this Laravel application? Need I an effective domain instead the vhost used on my local environment?

查看:41
本文介绍了Laravel应用程序的部署有什么问题?我需要一个有效的域而不是在本地环境中使用的虚拟主机吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PHP中非常陌生,而且在Laravel中非常陌生,而且我非常渴望尝试在Linux远程服务器上的本地环境中部署可以正常运行的 Laravel 5.4 应用程序.

I am pretty new in PHP and moreover in Laravel and I am pretty desperate trying to deploy a Laravel 5.4 application that works fine on my local environment on my Linux remote server.

所以我认为这与虚拟主机配置有关或类似的内容(可能与 .htaccess 文件有关)

So I think that it is something related to virtual host configuration or something like this (maybe also something related to the .htaccess file)

在我的本地环境中(我在Windows上使用 XAMPP ),我已将此虚拟主机设置为 C:\ xampp \ apache \ conf \ extra \ httpd-vhosts.conf 文件:

In my local environment (I am using XAMPP on Windows) I have setted this virtual host into the C:\xampp\apache\conf\extra\httpd-vhosts.conf file:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/HotelRegistration/public"
    ServerName laravel.dev
</VirtualHost>

因此,打开 laravel.dev URL,我将获得标准的Laravel主页(我尚未将其替换为登录页面).

So opening the laravel.dev URL I obtain the standard Laravel homepage (I have yet not replaced it with a landing page).

然后,如果我打开此URL: http://laravel.dev/registration

Then if I open this URL: http://laravel.dev/registration

我获得了我开发的用户注册页面,这是因为我将这条路径导入了我的 web.php 文件中,并将其导入了我的项目中:

I obtain the user registration page developed by me, this because I have this route into my web.php file into my project:

Route::resource('/registration', 'RegistrationController');

然后进入我的 RegistrationController.php 中,该方法将显示 resources/views/registration/index.blade.php 视图

Then into my RegistrationController.php there is this method showing the resources/views/registration/index.blade.php view

public function index(){

    return view('/registration/index');

}

一切正常.

现在,我已将此Laravel网站上传到远程Linux服务器中的以下文件夹中:/var/www/html/HotelRegistration

Now I have uploaded this Laravel website into my remote Linux server, into this folder: /var/www/html/HotelRegistration

但是现在我的问题是,在此远程环境中,我没有虚拟主机(如果我做错了断言,请更正我:据我了解,虚拟主机用于本地环境中,以模拟Laravel需要对指向 public 文件夹,这是否正确?)

But now my problem is that in this remote environment I have not virtual host (correct me if I am doing wrong assertion: from what I have understand the virtual host is used on the local environment to simulate a domain that Laravel need to point to the public folder, is it this reasoning correct?)

无论如何,这是我的远程服务器上已部署网站的 public 文件夹的URL:

Anyway, this is the URL of the public folder of my deployed web site on my remote server:

http://89.36.211.48/HotelRegistration/public/

如您所见,打开Laravel登陆页面已正确显示,问题是我可以访问上一个注册页面,我发现的唯一方法是打开以下URL:

As you can see opening it the Laravel landing page is correctly shown, the problem is that I can access to the previous registration page, the only way that I have found is to open this URL:

http://89.36.211.48/HotelRegistration/public/index.php/registration

但这很可怕,最重要的是,在提交注册表时,它会向该URL生成POST请求. http://89.36.211.48/registration ,结果出现 404 Not Found 错误.

but it is pretty horrible and above all when the registration form is submitted it is generated a POST request toward this URL http://89.36.211.48/registration that end into a 404 Not Found error.

因此,我认为这取决于以下事实:在此远程服务器中,我无法使用模拟域的虚拟主机(就像我在本地环境中一样),但我不是对此肯定.

So I think that it depend by the fact that in this remote server I can't use a virtual host that simulate a domain (as I have on my local environment), but I am not sure about it.

我该怎么办才能解决这种情况?您是否认为使用有效的域(例如:www.myregistration.com)指向我的远程服务器的该目录 http://89.36.211.48/HotelRegistration/public/ 我可以解决此问题吗?

What can I do to solve the situation? Do you think that using a effective domain (something like: www.myregistration.com) that points to this directory of my remote server http://89.36.211.48/HotelRegistration/public/ I can solve this problem?

推荐答案

您需要在服务器中配置域,并需要重新配置apache.我正在考虑您使用的是apache2服务器,因此您可以在这里进行操作:

You need to configure your domain in your server and need to reconfigure the apache. I'm considering you are having apache2 server so here you can do:

步骤1 转到apache2文件夹 cd/etc/apache2

Step 1 Go to the apache2 folder cd /etc/apache2

第2步,您可以看到站点可用文件夹位于其中 cd站点可用

Step 2 You can see sites-available folder go inside it cd sites-available

第3步,将其命名为 laravel.dev.conf

步骤4 写下以下 sudo nano laravel.dev.conf

第5步:写下以下选项:

<VirtualHost *:80>
     ServerAdmin webmaster@laravel.dev
     ServerName laravel.dev
     ServerAlias www.laravel.dev
     DocumentRoot /var/www/html/laravel.dev/public/
     ErrorLog /var/www/html/laravel.dev/logs/error.log
     CustomLog /var/www/html/laravel.dev/logs/access.log combined
     <Directory /var/www/html/laravel.dev/public/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order allow,deny
        Allow from all
        Require all granted
     </Directory>
</VirtualHost>

步骤6 现在转到此文件夹/创建一个新的 cd/var/www/html/laravel.dev

Step 6 Now go to this folder/create a new one cd /var/www/html/laravel.dev

步骤7 在此处复制/安装laravel应用程序.

Step 7 Copy/Install your laravel application here.

步骤8 现在,您可以通过输入 sudo a2ensite laravel.dev.conf

Step 8 Now you can enable your site by typing sudo a2ensite laravel.dev.conf

步骤9 现在重新启动apache2 sudo服务apache2重新启动

Step 9 Now restart the apache2 sudo service apache2 restart

现在,您可以正确访问您的域了.希望这会有所帮助.

Now you can have proper access to your domain. Hope this helps.

这篇关于Laravel应用程序的部署有什么问题?我需要一个有效的域而不是在本地环境中使用的虚拟主机吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆