I have decided to start coding using OOP and a PHP framework. I have successfully installed Yii on a development server and created a webapp. Now, I would like to move the protected folder to a level outside the document root for security reasons. My question is how to do this when there are multiple subdomains that I will also be using Yii with.
I have experience with PHP, but not in an OOP style and this is my initial step into OOP and frameworks. Also, I have a LAMP system installed on Ubuntu for development.
My path structure is below, which matches the production server. I have a top level site and multiple other top level sites and subdomain sites for one of the top level sites.
top level site – /home/mark/public_html/{website one files}
top level site – /home/mark/public_html/website-two.com/{website-two files}
top level site – /home/mark/public_html/website-three.com/{website-three files}
my sub domains – /home/mark/public_html/sub1.website-three.com/{sub files}
my sub domains – /home/mark/public_html/sub2.website-three.com/{sub2 files}
my sub domains – /home/mark/public_html/sub3.website-three.com/{sub3 files}
I have Yii installed at: /home/mark/Yii
I have created a webapp at: /home/mark/public_html/sub1.website-three.com and access the Yii webapp locally at http://sub1.website-three/ ….I don’t use http://localhost since I have virtual hosts and sub domains. All of this works, and will be creating more webapps at other subdomains under website-three.
Can I rename the protected folder to sub_protected and place it at /home/mark, and then for my next webapp, name the protected folder sub2_protected and so on? Should I use a different path structure??? Also, I believe I will need to edit the protected/config/main.php for each site to reflect the changes???
Any assistance would be greatly appreciated. Can’t wait to get this configured so I can dive further into Yii …looks very intriguing so far.
You can name the protected folder whatever you want and put it anywhere on your file system that your webserver user has access to, so, yes /home/mark/sub*n*_protected scheme would work.
However, particularly if your sites are similar and have any shared code, it might be more efficient to use one protected folder and set up an array of urlManager rules in your main config file and load the appropriate rules base on the host name. You can then have dedicated controllers for each host as well as views directories. I’ve often done this for mobile versions where you can also add mobile detection to the mix.
If the sites are distinct, using separate protected directories might sense as well. E.g., I’ll use a separate protected directory for admin tools based on the Gii-generated scaffolding.
If the sites are very similar, you also might want to check out Themes:
http://www.yiiframework.com/doc/guide/1.1/en/topics.theming