Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 一台主机上有两个Laravel应用只有一个应用可以登录_Php_Laravel_Laravel 5 - Fatal编程技术网

Php 一台主机上有两个Laravel应用只有一个应用可以登录

Php 一台主机上有两个Laravel应用只有一个应用可以登录,php,laravel,laravel-5,Php,Laravel,Laravel 5,我在一台主机上有两个Laravel 5.2应用程序,一个用于生产,另一个用于登台。两者都有各自的数据库。问题是,每当我使用一个应用程序登录时,另一个应用程序将无法登录。有人知道怎么处理吗 我找到了答案,但它不起作用 下面是我对session.php的配置 'driver' => env('SESSION_DRIVER', 'file'), 'files' => storage_path('framework/sessions'), 'cookie' => env('SESSIO

我在一台主机上有两个Laravel 5.2应用程序,一个用于生产,另一个用于登台。两者都有各自的数据库。问题是,每当我使用一个应用程序登录时,另一个应用程序将无法登录。有人知道怎么处理吗

我找到了答案,但它不起作用

下面是我对session.php的配置

'driver' => env('SESSION_DRIVER', 'file'),
'files' => storage_path('framework/sessions'),
'cookie' => env('SESSION_NAME', 'laravel_local'),
'path' => '/',
'domain' => null,

用于引用会话的cookie似乎正在两个应用程序之间共享

确保两个应用程序在
config/session.php
config文件中的
cookie
config的值不同

'cookie' => 'laravel_session',
或者,如果您使用.env文件(我注意到您正在使用)来设置cookie名称,请确保为每个应用程序更改.env文件中的相应变量

进行更改后,请确保清除浏览器cookie


如果可能的话,为登台应用程序创建一个子域,如
staging.yoursite.com
,将是一个理想的解决方案,因为这样可以防止两个应用程序之间共享cookie

假设您拥有此应用程序树:

/path/to/web/root
    |_app1
    |   |_all
    |   |_laravel
    |   |_folders
    |   |_and
    |   |_public
    |
    |_app2
        |_all
        |_laravel
        |_folders
        |_and
        |_public
如果您可以管理DNS记录,我建议您创建两个虚拟服务器

第一个,例如,
app1.application.com
,指向
/path/to/web/root/app1/public

第二个,例如
app2.application.com
,指向
/path/to/web/root/app2/public

在您的情况下,您可能需要使用类似于
prod.application.com
staging.application.com


配置虚拟服务器 如果您使用的是apache,您的虚拟服务器配置文件可能如下所示: 配置文件应保存到web服务器配置目录(
/etc/apache2
/etc/nginx
)中,位于
站点可访问的
目录中

然后必须运行
sudoa2ensite
(对于Apache),或
sudoln-s/etc/nginx/sites aviable//etc/nginx/sites enabled/
(对于nginx)

最后,您必须重新启动Web服务器

希望这有帮助


注意。

您使用了什么驱动程序进行会话存储?暂存和生产应用程序是否都访问了正确的数据库?饼干怎么样,只是为了确定一下。然后,尝试在
session.php
中为每个环境编辑
'domain'=>'.yoursite.com'
。仅文件驱动程序,但它存储在单独的路径中,我正在添加我的session.php配置
path
是指相对路径还是绝对路径?所以如果它是“/”那么它就在根上???是的,它应该是你应用的根。尝试检查浏览器cookie,然后查看“域”列。演出和制作之间有什么不同吗?谢谢大家,这很有效。我使用env-var为cookie和域设置了不同的名称
<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName app1.application.com

    ServerAdmin webmaster@localhost
    DocumentRoot /path/to/web/root/app1/public

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

    <Directory /path/to/web/root/app1/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
server {
    listen 80;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /path/to/web/root/app1/public;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name sigesi.tk www.sigesi.tk;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.php?$query_string;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}