Created
June 3, 2010 09:35
-
-
Save wizmedia/423689 to your computer and use it in GitHub Desktop.
This script allows you to deploy multiple installations of Joomla! using one Joomla! full source directory. Can be very useful for Multiple websites using only one main Joomla! Directory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Define the directory separator. Usually forward slash "/" on UNIX systems */ | |
define('DS','/'); | |
/* Where are the full copies of Joomla located? This can point to the directory where several copies of Joomla Core files are located. */ | |
$source_path = '/WWW/_source/joomla15-latest'; /* e.g. $source_path = '/home/mymane/files/joomlasource'; */ | |
/* Where do you want to install this symlinked instance of Joomla? */ | |
//$install_path = dirname(__FILE__).DS.'homebrew'; /* e.g. $install_path = '/home/mymane/public_html'; */ | |
$install_path = '/WWW'; | |
if( !file_exists($install_path)) | |
{ | |
echo "Warning! Installation path <strong>{$install_path}</strong> does not exist!"; | |
die(); | |
} | |
if( $source_path == '' OR !file_exists($source_path)) | |
{ | |
echo "Warning! Source path <strong>{$source_path}</strong> does not exist!"; | |
die(); | |
} | |
function scan_dir($path, $levels = 1, $include_files = false, $reset = true) | |
{ | |
static $cur_level; | |
if (!is_int($cur_level) OR $reset) | |
$cur_level = 0; | |
$cur_level++; | |
$path = strip_trailing_slash($path); | |
$dirs = array(); | |
if ($handle = opendir($path)) | |
{ | |
while (false !== ($file = readdir($handle))) | |
{ | |
$filepath = $path.DS.$file; | |
if ($file != "." AND $file != ".." AND is_dir($filepath)) | |
{ | |
$dirs[] = $filepath; | |
if ($cur_level < $levels OR $levels === 0) | |
{ | |
$child_dirs = scan_dir($filepath, $levels, $include_files, false); | |
$dirs = array_merge($dirs, $child_dirs); | |
$cur_level--; | |
} | |
}elseif ($include_files AND $file != "." AND $file != ".." AND is_file($filepath)) | |
{ | |
$dirs[] = $filepath; | |
} | |
} | |
closedir($handle); | |
} | |
$reset = true; | |
return $dirs; | |
} | |
function create_symlinks($source, $project_dir) | |
{ | |
$root_dir = scan_dir($source, 1, true); | |
//make symlinks to the core directories | |
foreach ($root_dir as $root) | |
{ | |
$filename = str_replace($_POST['source'].DS, '', $root); | |
exec("ln -s {$root} {$project_dir}{$filename}"); | |
} | |
} | |
function strip_trailing_slash($path) | |
{ | |
if (substr($path, -1, 1) == '/' OR substr($path, -1, 1) == '\\') { | |
$path = substr($path, 0, -1); | |
} | |
return $path; | |
} | |
?> | |
<html> | |
<head> | |
<title>SymLinked Joomla! Installer</title> | |
<style type="text/css"> | |
html{ | |
text-align:center; | |
} | |
body { | |
margin: 0px; padding: 0; | |
background: #F0F0F0; | |
padding-bottom: 1px; | |
font-size: 11px; | |
text-align:left; | |
} | |
a:link, | |
a:visited { | |
color: #0B55C4; | |
} | |
body, td, th { font-family: Arial, Helvetica, sans-serif; } | |
#body-container { | |
width: 960px; | |
margin: 0 auto; | |
background: #fff; | |
border: 1px solid #999999; | |
border-top:none; | |
} | |
#links { | |
text-align:right; | |
} | |
#links a { | |
text-decoration:none; | |
} | |
#contents { | |
padding: 20px; | |
} | |
h1 { | |
background: #0B0B0B; | |
color: #fff; | |
padding: 15px 31px; | |
width: 900px; | |
margin: 0 auto; | |
border-bottom: 8px solid #66A736; | |
} | |
h3 { | |
font-size:15px; | |
color: #0B55C4; | |
} | |
#footer { | |
padding: 20px; | |
text-align:center; | |
} | |
.warning { | |
margin: 20px; | |
border: 1px solid #E7BD72; | |
background: #FFF3A3; | |
padding: 10px; | |
color: #D2761D; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Install a SymLinked Joomla!</h1> | |
<div id="body-container"> | |
<div id="contents"> | |
<div id="links"><a href="http://twitter.com/wizmedia" target="_blank">Follow the Developer on Twitter >>></a></div> | |
<?php | |
if ($_POST['task'] != 'install'): ?> | |
<p><strong>This script allows you to deploy multiple installations of Joomla using one Joomla full source directory.</strong></p> | |
<p>If you're a Joomla Web Developer like us, you probably have a lot of Joomla installations in your local server. Everytime you install Joomla, you have to duplicate the full source files. This is very inefficient if you don't modify the core files anyway. The solution is to use symlinks(symbolic links or aliases). This script will create symlinks to a Joomla source directory. But it doesn't symlink the directories that can have dynamic contents like /components and /modules. This script takes everything in consideration so your symlinked Joomla installations will work as if they are full copies of Joomla.</p> | |
<p>A default Joomla 1.5 installation takes around 45MB of disk space. Using this script, each of your symlinked Joomla! installation directory will occupy only 2MB. It will also make the upgrades easier because you only have to upgrade one directory.</p> | |
<p class="warning"><strong>Warning!</strong> This script was tested to work on a local UNIX environment (Linux and Mac OS X using Apache). Please help us test it for live deployments. This script will not work on Windows.</p> | |
<p class="warning"><strong>Requirements:</strong><br /> Apache 2.x and PHP 5.2+ <br />Apache should be configured with FollowSymLinks on the directory where you want to install a symlinked Joomla! <br />PHP should be able to execute shell commands using exec()</p> | |
<h3>Instructions</h3> | |
<ul> | |
</ul> | |
<ol> | |
<li>Edit symlink-joomla.php and configure $install_path and $source_path</li> | |
<li>Put symlink-joomla.php within your web server's document root. It can be located at any subdirectory of the document root. </li> | |
<li>Run symlink-joomla.php through your web browser.(You are already doing it if you can read this)</li> | |
<li>You can install a symlinked Joomla as a subdirectory of $install_path. Just put something on the "Where do you want to install Joomla?" field. If left blank, it will install the symlinked Joomla to $install_path.</li> | |
<li>Proceed with the installation</li> | |
</ol> | |
<h3>Notes:</h3> | |
<ol> | |
<li>Note that the $source_path can be a directory that contains sub-directories of different Joomla! 1.5 full versions (don't use patch files). If the $source_path contains sub directories, you'll be allowed to choose which one to use.</li> | |
<li>By default, $install_path is the directory where symlink-joomla.php is located</li> | |
<li>/images is not symlinked.</li> | |
<li>All the core extensions are symlinked, but it doesn't symlink the directories that can contain user generated files. e.g /components/com_content is symlinked, but /components is not so that you can install components within a particular installation of symlinked Joomla.</li> | |
</ol> | |
<ul> | |
</ul> | |
<form action="" method="post"> | |
<input type="hidden" name="task" value="install" /> | |
<h3>Select the full copy of Joomla! that you want to use:</h1> | |
<dl> | |
<?php $source_list = scan_dir($source_path); | |
if (in_array($source_path.DS.'administrator', $source_list)) | |
{ | |
echo "<dt><label><input type=\"radio\" name=\"source\" value=\"{$source_path}\" checked=\"checked\" />{$source_path}</label></dt>"; | |
}else{ | |
foreach ($source_list as $source) | |
{ | |
$source_name = str_replace($source_path.DS, '', $source); | |
echo "<dt><label><input type=\"radio\" name=\"source\" value=\"{$source}\" />{$source_name}</label></dt>"; | |
} | |
} | |
?> | |
</dl> | |
<h3>Where do you want to install Joomla?</h3> | |
<p><?php echo $install_path.DS ?><input type="text" name="project" value="" /> <input type="submit" name="submitbutton" value="Proceed >>>" /></p> | |
<p></p> | |
</form> | |
<?php else: | |
$project_dir = $install_path.DS.$_POST['project'].DS; | |
@mkdir($project_dir); | |
create_symlinks($_POST['source'], $project_dir); | |
$dynamic = array( | |
$_POST['source'].DS."administrator", | |
$_POST['source'].DS."administrator".DS."backups", | |
$_POST['source'].DS."administrator".DS."components", | |
$_POST['source'].DS."administrator".DS."modules", | |
$_POST['source'].DS."administrator".DS."templates", | |
$_POST['source'].DS."administrator".DS."cache", | |
$_POST['source'].DS."administrator".DS."language", | |
$_POST['source'].DS."administrator".DS."language".DS."en-GB", | |
$_POST['source'].DS."components", | |
$_POST['source'].DS."modules", | |
$_POST['source'].DS."templates", | |
$_POST['source'].DS."plugins", | |
$_POST['source'].DS."plugins".DS."authentication", | |
$_POST['source'].DS."plugins".DS."content", | |
$_POST['source'].DS."plugins".DS."editors", | |
$_POST['source'].DS."plugins".DS."editors-xtd", | |
$_POST['source'].DS."plugins".DS."search", | |
$_POST['source'].DS."plugins".DS."system", | |
$_POST['source'].DS."plugins".DS."tmp", | |
$_POST['source'].DS."plugins".DS."user", | |
$_POST['source'].DS."plugins".DS."xmlrpc", | |
$_POST['source'].DS."language", | |
$_POST['source'].DS."language".DS."en-GB", | |
$_POST['source'].DS."language".DS."pdf_fonts", | |
$_POST['source'].DS."media", | |
$_POST['source'].DS."cache", | |
$_POST['source'].DS."tmp" | |
); | |
//delete symlinks for dynamic directories, create symlinks for core files inside dynamic directories | |
foreach ($dynamic as $dyn) | |
{ | |
$filename = str_replace($_POST['source'].DS, '', $dyn); | |
unlink($project_dir.$filename); | |
mkdir($project_dir.$filename); | |
create_symlinks($dyn, $project_dir); | |
} | |
//just copy critical files instead of symlinking | |
unlink($project_dir."installation"); | |
unlink($project_dir."images"); | |
unlink($project_dir."index.php"); | |
unlink($project_dir."administrator".DS."index.php"); | |
$img_src = $_POST['source'].DS."images"; | |
$img_dest= $project_dir."images"; | |
$install_src = $_POST['source'].DS."installation"; | |
$install_dest= $project_dir."installation"; | |
exec("cp -R {$img_src} {$img_dest}"); | |
exec("cp -R {$install_src} {$install_dest}"); | |
copy($_POST['source'].DS."index.php", $project_dir."index.php"); | |
copy($_POST['source'].DS."administrator".DS."index.php", $project_dir."administrator".DS."index.php"); | |
$install_uri = str_replace($_SERVER['DOCUMENT_ROOT'], '', $project_dir); | |
$install_url = 'http://'.$_SERVER['SERVER_NAME'].strip_trailing_slash($install_uri); | |
echo "<h3>Installation, done!</h3>"; | |
echo "<p>Based on the information I gathered, I am guessing that the URL of your new Joomla Installation is here: <a href=\"{$install_url}\">{$install_url}</a></p>"; | |
echo "<p>Visit the developer's website at <a href=\"http://www.wizmediateam.com\">www.wizmediateam.com</a></p>"; | |
echo "<p><a href=\"\">< < < Back</a></p>"; | |
endif; ?> | |
</div> | |
</div> | |
<div id="footer"> | |
Written by Israel Dacanay Canasa (raeldc) of <a href="http://www.wizmediateam.com" target="_blank">WizMedia Team</a> | |
</div> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It sound good but how could I use this script?!!