Separated another script,in another folder & using another DB? For security

For a website, sometime we used more than a script that separated, yes separated and dont have connection at all each other

for example
domain.com is a forum, using vbulletin
domain.com/blog is a blog, using wordpress
domain.com/store is ecommerce, using oscommerce
domain.com/article is article cms, using joomla
etc

so for security best practice, like if one of the script get hacked or get something wrong,
another script files in another folder,
and another mysql database,
is still secure

can we do that? if so how to do that actually? its looks like simple and basic, but i am still not sure how to do it

if there is tutorial link please let me know too, still cant found it