Several Yii2 apps on the same domain

Hello everyone.

Pleas help me.

I created two yii2 basic applications. And I run them on the same domain. The problem is:

when I start first one

localhost/app1/web - I go to app1. It’s Ok.

But when after that I start another one

localhost/app2/web - I go to app1 again. That is in my browser url is correct (localhost/app2/web) bu the content is from the app1.

What can be the problem and how to fix it?

@Viter usually it not happen.

Maybe you have a .htacces file in you www or you create a rule in apache to redirect it.

No, it’s session/cookie problem. I googled a lot but nothing helps. :(

It happens both on my local machine and on my server. I created on my server subdomain to separate my apps but the problem remains the same.

How is your structure directory?

I have this structure…

/var/www/html/appYii1

/var/www/html/appYii2

/var/www/html/appYii3

And no apache configuration. I acces it like localhost/appYii1 or localhost/appYii2 and each app runs separated.

My structure is the same. My yii1.1 apps work well but yii2 have problems like I described above.

I’ve just tried to run my apps on my home computer and have the same problems again.

Very very strange @Viter. I don’t know what happens.

I even created basic app from archive file and did not do any changes to it but after I ran in browswer localhost/basic/web instead of default index page I got the one of another app. I’m in despair and don’t know what to do. The strange thing is that this happens on three different computers.

Looks like I solved it. Shame on me but it was all about runtime and web/assets folders permissions.

I’m afraid it was to early for me to joy. The problems remain and I don’t know what to do. :(

Since you haven’t really given much, if any, information about exactly what you are doing, it is hard to tell what you are doing wrong. :)

I create two basic apps: /var/www/html/app1 and /var/www/html/app2.

I change the content of index file of the first app to ‘app1’ and the content of the second app to ‘app2’.

Then in my browser I run localhost/app1/web and it shows me string ‘app1’.

Then in another tab of the same webbrowser I run localhost/app2/web and it shows me again ‘app1’ though apparently it should show me ‘app2’.

How can this be?

I have only run Yii using virtual hosts.

Highly recommend that you do that instead of dropping projects in your webroot :)

Virtual hosts means that the sites gets domain/subdomain and it means that cookies can be set individually (cookies follows the domain).

But I never had such problems with yii1.1. Is it a bug of yii2 ?

Yii1 and Yii2 are quite different beasts…

Generally what you are doing should not be a problem, but I have some thoughts…

  1. You said you are using url: localhost/app1/web.

With basic app, it should normally be localhost/app1/basic/web I think.

Can you try this and see what happens?

  1. Virtual hosting is a better way to do this. When you deploy, that is what

your configuration will look like and you get a better dev/test environment.

What server are you using?

  1. It looks like cookies might be involved, so can you try clearing your browser

cache and cookies between each run and see what difference that makes?

-John

Look at the section ‘independent sessions on the same domain’ at this page: http://yii2-user.dmeroff.ru/docs/usage-with-advanced-template