T3rm1
T3rm1

Reputation: 2582

Structure for a MVC PHP application

I am currently developing a php application using MVC techniques. I started it without thinking about a useful directory structure.
I'm planning to deploy the application to a apache2 server now. This is how it looks right now.
My current layout

I have a httpdocs folder on the server which is accessible from the web. If I copy all files into this directory some files might be accessible that shouldn't. The public folder contains the files that have to be accessible. (I might need to put my index.php there)

My question is: What is the preferred layout for such an application? Should I put all folders except public in the parent folder of httpdocs?

Thanks for your advices!

Upvotes: 4

Views: 3628

Answers (3)

Martin Bean
Martin Bean

Reputation: 39409

The simplest solution would be similar to what CakePHP does, and have your index.php in your public directory and then just have .htaccess files that map all requests to that index.php file.

So in your root directory you would have something like:

RewriteEngine on
RewriteRule ^(.+) /public/index.php/$1 [L,NC]

And then similarly in your public directory:

RewriteEngine on
RewriteRule ^(.+) index.php/$1 [L,NC]

Your PHP scripts would then still be able to access other scripts as normal, as they work on the file system and not via say, HTTP.

Upvotes: 3

Baversjo
Baversjo

Reputation: 3716

Use the public directory as httpdocs. Web root points to public like this:

<VirtualHost *:80>
DocumentRoot /path/to/public
ServerName www.domain.com
...
</VirtualHost>

If you don't have access to the apache configuration you could just use "httpdocs" as the public directory. You move everything from public to httpdocs and keep the rest of the application outside httpdocs. The name of the public directory should not matter as long you know the path to assets ("mydomain.com/javascripts/foo.js") .

Upvotes: 1

yokoloko
yokoloko

Reputation: 2860

http://httpd.apache.org/docs/2.1/vhosts/examples.html

You can have a look there. Setting up a virtual host is always nice so you don't mix your application. And you just give access to your public folder.

<VirtualHost *:80>
DocumentRoot /var/www/mvc_app/public
ServerName www.example.com

<Directory /var/www/mvc_app/public>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

</VirtualHost>

Upvotes: 3

Related Questions