I’m trying to setup a new website using Twitter bootstrap as the front-end and PHP as the code behind.
The directory structure I’m using is as follows and fairly standard
c:\xampp\htdocs\app
c:\xampp\htdocs\app\application\configs
c:\xampp\htdocs\app\application\modules
c:\xampp\htdocs\app\data\
c:\xampp\htdocs\app\data\logs
c:\xampp\htdocs\app\data\sessions
c:\xampp\htdocs\public_html\
c:\xampp\htdocs\public_html\css
c:\xampp\htdocs\public_html\js
c:\xampp\htdocs\public_html\img
My Apache config is fairly straight forward and consists of
<VirtualHost *:80>
ServerName vinner.localhost
DocumentRoot C:/xampp/htdocs/app/public_html
SetEnv APPLICATION_ENV "development"
<Directory C:/xampp/htdocs/app/public_html>
DirectoryIndex index.php index.html index.htm \
default.php default.asp default.shtml default.html default.htm \ AllowOverride All
Order allow,deny
Allow from all
</Directory>
Previously I had my PHP code inside the /public_html folder but this obviously isn’t great practise so I’ve moved it to c:\xampp\htdocs\app\application\modules however I can’t figure out how to point either POST queries directly to PHP pages, or to create a generic PHP template/include file so my PHP pages are easily accessible.
You should have a file, usually called “index.php”, in the “public_html” directory. Then your web server rules (e.g. .htaccess or server configuration) points all requests (or perhaps, all requests that aren’t for files that exist in “public_html”) to that “public_html/index.php”. This is usually the only PHP file under “public_html”, but sometimes there may be multiple for different purposes (e.g. a different one for serving images).
From there you can include the rest of your code using relative paths, each of the following is equivalent (code in “public_html/index.php”):
And:
Where “application-code” is an entry point to your application, often named something like “bootstrap.php”.