Questions
(Questions)
November 29, 2024, 8:40am
1
Hello,
We have hosted or Yii 2 applications on shared hosting server. Both of the Yii 2 applications has vendor folder that contains same extensions. Now we want that the second application should access the first app’s vendor folder instead of having its own in order to optimize the disk space of the server. How to do this
The project structure is
folder 1
- assets/
- commands/
- config/
- controllers/
- models/
- views/
- vendor/
folder 2
- assets/
- commands/
- config/
- controllers/
- models/
- views/
- vendor/
public_html
app1 --> contents from the web directory of app1 (Contains index.php)
app2 --> contents from the web directory of app2 (Contains index.php)
Now the index.php from app1
require __DIR__ . '/../../folder1/vendor/autoload.php';
require __DIR__ . '/../../folder1/vendor/yiisoft/yii2/Yii.php';
$config = require __DIR__ . '/../../folder1/config/web.php';
Now the index.php from app2
require __DIR__ . '/../../folder2/vendor/autoload.php';
require __DIR__ . '/../../folder2/vendor/yiisoft/yii2/Yii.php';
$config = require __DIR__ . '/../../folder2/config/web.php';
Where should I make changes in order that the app2 can use the vendor folder of app1 to reduce the disk space
evstevemd
(Stefano Mtangoo)
December 2, 2024, 5:10am
2
You didn’t post folder structure and how the two are placed in the file system. Expect zero answer until you do!
Questions
(Questions)
December 2, 2024, 7:02am
3
This is how the folders are on the shared hosting server.
folder 1 contains all the directories and files except web directory. Similarly for folder 2
so on the file manager of the shared hosting server contains 3 things
folder 1
folder 2
public_html -
contains app1 folder that contains web directory files and folders of 1st project (folder 1)
contains app2 folder that contains web directory files and folders of 2nd project (folder 2)
Which folder structure should I am supposed to post? Please can you tell
evstevemd
(Stefano Mtangoo)
December 2, 2024, 7:43am
4
Can you put full paths of folder1, folder2 and vendor directories?
Questions
(Questions)
December 2, 2024, 7:49am
5
Please can you tell which paths, I am not getting what are you asking
app1 and app2 are the subdomains
These are all on live server not on my local server.
Questions
(Questions)
December 2, 2024, 8:46am
6
should I post the config/web.php file?
folder 1
- assets/
- commands/
- config/
- controllers/
- models/
- views/
- vendor/
folder 2
- assets/
- commands/
- config/
- controllers/
- models/
- views/
- vendor/
public_html
app1 --> contents from the web directory of folder 1 (Contains index.php)
app2 --> contents from the web directory of folder 2 (Contains index.php)
evstevemd
(Stefano Mtangoo)
December 2, 2024, 10:37am
7
I mean something like
AppA: /www/appa/
AppB: /www/appb/
vendor: /www/appa/vendor
Questions
(Questions)
December 2, 2024, 12:54pm
8
There is 1 folder public_html which is a web accessible folder
In my File Manager I have like this below which contains 3 folders
folder 1 (contains all the files of project 1 other than web directory)
folder 2 (contains all the files of project 2 other than web directory)
public_html
So folder 1 contains
folder1/assets
folder1/commands
folder1/controllers/
folder1/models
folder1/views
folder1/vendor
folder1/widgets
Similarly folder2 contains
folder2/assets
folder2/commands
folder2/controllers/
folder2/models
folder2/views
folder2/vendor
folder2/widgets
Now in public_html folder I have the following structure
public_html
app1
- assets
- css
- js
- plugins
- index.php
app2
- assets
- css
- js
- plugins
- index.php
Now the index.php of app1 contains the following
require __DIR__ . '/../../folder1/vendor/autoload.php';
require __DIR__ . '/../../folder1/vendor/yiisoft/yii2/Yii.php';
$config = require __DIR__ . '/../../folder1/config/web.php';
Now the index.php of app2 contains the following
require __DIR__ . '/../../folder2/vendor/autoload.php';
require __DIR__ . '/../../folder2/vendor/yiisoft/yii2/Yii.php';
$config = require __DIR__ . '/../../folder2/config/web.php';
evstevemd
(Stefano Mtangoo)
December 2, 2024, 5:22pm
9
It should work. If it is not, it is because require folder hierarchy is not correct. try putting absolute path to require instead of relative one
Questions
(Questions)
December 3, 2024, 9:42am
10
It is working. That is not the problem
I want that the second application should use the vendor of the first application. So that instead of uploading the vendor folder again for the second application which would waste the disk space of the server unnecessary.
So where should I make changes so that the second application should use the vendor directory of the first application
So if I make the changes to the index.php of app2 like below, it does not work. it gives error
require __DIR__ . '/../../folder1/vendor/autoload.php';
require __DIR__ . '/../../folder1/vendor/yiisoft/yii2/Yii.php';
$config = require __DIR__ . '/../../folder1/config/web.php';
tri
(tri - Tommy Riboe)
December 3, 2024, 12:56pm
11
1 Like