简体   繁体   English

Laravel通过Envoyer部署到Cpanel

[英]Laravel deployment via Envoyer to Cpanel

I have a VPS running WHM and Cpanel. 我有一个运行WHM和Cpanel的VPS。 I have multiple domains hosted there. 我在那里托管了多个域名。 Say one of them is example.com 说其中一个是example.com

What I am intending to do is have two versions of the application. 我打算做的是有两个版本的应用程序。 Production: example.com > /public_html/ Development: staging.example.com > /public_html/staging/ 制作: example.com > /public_html/开发: staging.example.com > /public_html/staging/

Right now, I am trying to deploy my application to the development environment, ie to the staging folder. 现在,我正在尝试将我的应用程序部署到开发环境,即staging文件夹。

Envoyer, with a lot of struggle with my hosting provider, is working fine. 与我的托管服务提供商进行了大量斗争的Envoyer工作正常。 It's uploading the files as expected. 它按预期上传文件。 The only issue now is the symbolic link current 现在唯一的问题是符号链接current

Right now the folder structure is: 现在文件夹结构是:

-staging
    - releases
        -release1
        -release2
    - current

My subdomain clearly points out to the staging folder, which will lead it to display all the contents of the folder rather than the application. 我的子域清楚地指出了staging文件夹,它将导致它显示文件夹的所有内容而不是应用程序。

Since the application is inside the release folder, how do I make sure that my application runs when we hit the subdomain. 由于应用程序位于发布文件夹中,如何确保在我们点击子域时运行我的应用程序。

Do I have to modify my virtual hosts file in Apache? 我是否必须在Apache中修改我的虚拟主机文件?

Laravel requires the root for the domain (configured in the relevant apache vhost conf file) to be it's 'public' folder. Laravel要求域的根(在相关的apache vhost conf文件中配置)为它的'public'文件夹。 This is where it's entry point index.php is. 这是它的入口点index.php。

Edit the apache vhosts conf file as per below 编辑apache vhosts conf文件,如下所示

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot "/home/user/public_html/public"
    <Directory "/home/user/public_html/public">
        Options Indexes FollowSymLinks
        AllowOverride all
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName staging.example.com
    DocumentRoot "/home/user/public_html/staging/public"
    <Directory "/home/user/public_html/staging/public">
        Options Indexes FollowSymLinks
        AllowOverride all
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

For example.com you install your laravel application into /home/user/public_html folder. 对于example.com,您可以将laravel应用程序安装到/ home / user / public_html文件夹中。

As part of the laravel install it will create the 'public' folder. 作为laravel安装的一部分,它将创建“公共”文件夹。

For staging.example.com you install your laravel application into /home/user/public_html/staging folder. 对于staging.example.com您安装laravel申请到/ home / user中/的public_html /临时文件夹。

Don't forget to restart the web server so it picks up the new configuration. 不要忘记重新启动Web服务器,以便它获取新配置。

If you do not have the ability to change the vhost configuration mentioned above, you can use .htaccess file in your public_html folder (note the leading full stop which makes it a hidden file). 如果您无法更改上面提到的vhost配置,则可以在public_html文件夹中使用.htaccess文件(请注意前导句点,使其成为隐藏文件)。 The following is dependant on your hosting provider allowing .htaccess overrides. 以下内容取决于您的托管服务提供商允许.htaccess覆盖。

Add the following to the .htaccess file: 将以下内容添加到.htaccess文件中:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

If domain has been set up correctly by the host to point to /home/username/public_html when entering http://example.com then it should automatically call public/index.php. 如果主机在进入http://example.com时已正确设置域指向/ home / username / public_html,则应自动调用public / index.php。

You will need to do the same in public_html/staging folder. 您需要在public_html / staging文件夹中执行相同的操作。

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

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