Table of Contents
WebApp Directory structure
Let us use
www.openbook.pub as an illustration of the preferred structure of
PHP WebApps, built upon the Yii Framework. The WebApp has an old version
1.8.2, a current version
2.0.1, while version
2.1 is currently under development.
/openbook.pub/ /openbook.pub/index.php /openbook.pub/ad5min_.php /openbook.pub/... /mydevsite.com/ /mydevsite.com/index.php /mydevsite.com/ad5min_.php /mydevsite.com/... /openbook.app/ /openbook.app/1.8.2/ /openbook.app/1.8.2/frontend/ /openbook.app/1.8.2/backend/ /openbook.app/1.8.2/common/ /openbook.app/1.8.2/vendor/ /openbook.app/1.8.2/.git/ /openbook.app/2.0.1/frontend/ /openbook.app/2.0.1/backend/ /openbook.app/2.0.1/common/ /openbook.app/2.0.1/vendor/ /openbook.app/2.0.1/.git/ /openbook.app/2.3/
The entry scripts are very simple. The public will access the frontend via
Maintenance can be done by the administrator on the backend via
/openbook.pub/ad5min.php. We have chosen the odd
ad5min_.php filename to make the entry harder to guess for hackers.
Development is done via
Each version of the webapp is complete and independent of other versions. It has its own
vendor/ with the Yii framework and other dependencies. Once the version has been published
vendor/ will remain unchanged.
Each version also has its own
git registry. It can be changed and committed without affect other versions.
The above structure achieves the following
- Development, testing and production run on the same server.
- DT&P are separated as to never interfere.
- It is easy and to upgrade to a next version, or even to revert back to a previous version.
Note that frontend and backend are two separated webapps. When possible, they will share code in
common/. But a
LoginForm.php may be different, and each will have it in their own
On the other hand, the differences between running an app in development or production mode are limited.
development.phpas entry script.
- These entry scripts will set different values for environment variables like
- These entry script will include identical
config/params.phpfiles, but they may configure differently per
- No other differences; the modes share identical code.
A bare-bones sample application may be copied from
/x0data.app/1.0. For example by
cp -r x0data.app/1.0 riverbankneighborhood.app/2.0. The Yii manual specifies the following to-do list for this bare-bones webapp:
- Create a new database and adjust the components['db'] configuration in common/config/main-local.php accordingly.
- Apply migrations with console command yii migrate.
- Set document roots of your web server: for frontend /path/to/yii-application/frontend/web/ and using the URL http://frontend/ for backend /path/to/yii-application/backend/web/ and using the URL http://backend/ (We will not set the document roots because we have chosen a different structure; as per above.)