Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 629
T3rm1 Avatar asked Sep 16 '25 13:09

T3rm1


2 Answers

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>
like image 75
yokoloko Avatar answered Sep 18 '25 03:09

yokoloko


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.

like image 37
Martin Bean Avatar answered Sep 18 '25 03:09

Martin Bean



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!