r/PHPhelp • u/810311 • Jul 04 '26
Directory structure for vanilla PHP blog/project CMS
Can you take a look if this directory structure is good for vanilla PHP blog/project CMS ? I was curious if I can build my own CMS for blog posts, blog archives and projects. Before I had a WordPress site with those features which I built using Underscores. Please see here directory structure
5
Upvotes
4
u/colshrapnel Jul 04 '26
Well, for a first project it's OK. Just keep on with your project. Nothing beats the actual developing experience
8
u/dabenu Jul 04 '26
It looks like the entire structure is web accessible? That's bad practice. Ideally only your static files and index.php are accessible, the rest of the project should be outside the webroot.
You are now 1 webserver misconfiguration away from leaking your entire codebase including secrets to the world. This is very easy to prevent.
3
u/equilni Jul 04 '26 edited Jul 04 '26
Ideally you want to separate the public code from the internal PHP system. The public folder would have the 1 index.php that calls the system and sends the response.
https://github.com/php-pds/skeleton
https://www.nikolaposa.in.rs/blog/2017/01/16/on-structuring-php-projects/
From what you provided, it looks like everything points to direct file links - ie admin/login.php and with this, I would suggest remapping to relative urls like
/admin/loginor?section=admin&action=loginas doing the above, direct file links become inaccessible.1
u/optimusprimepluto Jul 04 '26
As strucure is for you to see, edit a dn reuse your own components effectively. You will have your own idea when you do more projects. So, asking whether a structure is fine is amteurish. You can onyl figure out your own structure when you do more projects.
There is no universal stucture. Even when i use frameworks like laravel, i follow my own structure because i find it easier to handle. It doe not mean i dont use laravel features. I use all laravel features inside my structure. We can all classes and functions anywhere.
WHen I use core php, then also i use the same structure. But i came structure after many years of doing code. I may even change it if i think some chnages in the structure will do good. So, it is a ongoing process.
-1
u/Temporary_Practice_2 Jul 04 '26
Generally good. But I think Claude or ChatGPT would propose an elegant solution