Automatic pre-installed PHP Script

Discussion in 'Plugins/Modules/Addons' started by lollollollol, Sep 9, 2013.

  1. lollollollol

    lollollollol Member

    Hi,
    I needed to have a php script in my sites to simplify the installation of my cms (Wordpress for now)
    So I wrote a small plugin to copy a file on all new sites created.

    You place the plugin in /usr/local/ispconfig/server/plugins-available then you make a symlink to /usr/local/ispconfig/server/plugins-enabled

    You place the install.php file in the /usr/local/ispconfig/server/conf/index

    Now at every site creation with IspConfig3 interface, the install.php file will be present.

    If you're interested, I can put the deployment file for Wordpress ...

    I hope it will helps some of you guys!

    Laurent.
     
  2. lollollollol

    lollollollol Member

    The code...

    Code:
    <?php
    
    /*
    Use at your own risk
    Adapted from code with the following copyright claim:
    
    Copyright (c) 2007, Till Brehm, projektfarm Gmbh
    All rights reserved.
    
    Redistribution and use in source and binary forms, with or without modification,
    are permitted provided that the following conditions are met:
    
        * Redistributions of source code must retain the above copyright notice,
          this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright notice,
          this list of conditions and the following disclaimer in the documentation
          and/or other materials provided with the distribution.
        * Neither the name of ISPConfig nor the names of its contributors
          may be used to endorse or promote products derived from this software without
          specific prior written permission.
    
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
    OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    */
    
    class web_add_file_plugin {
    	
    	var $plugin_name = 'web_add_file_plugin';
    	var $class_name = 'web_add_file_plugin';
    	var $min_uid = 499;
    	
    	//* This function is called during ispconfig installation to determine
    	//  if a symlink shall be created for this plugin.
    	function onInstall() {
    		global $conf;
    		
    		if($conf['services']['web'] == true) {
    			return true;
    		} else {
    			return false;
    		}
    		
    	}
    	
    	// This function is called when the plugin is loaded
    	function onLoad() {
    		global $app;
    		
    		//	Register for the events
    		$app->plugins->registerEvent('web_domain_insert',$this->plugin_name,'insert');
    	}
    	
    	// This is called when a new web site is created (event 'web_domain_insert')
    	function insert($event_name,$data) {
    		
    		global $app, $conf;
    		
    		$app->log("INSERT FUNCTION START",LOGLEVEL_DEBUG);
    		$app->uses('system');
    		$web_folder = $data['new']['web_folder'];
    		$web_folder = "web";
    		$app->log("DECLARE web_folder : ".$web_folder,LOGLEVEL_DEBUG);
    		
    		if(!is_dir($data['new']['document_root'].'/' . $web_folder)) {
    			$app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder);
    		}else{
    			$app->log($data['new']['document_root'].'/ ALREADY EXIST',LOGLEVEL_DEBUG);
    		}
    		
    		
    		if(is_file($conf['rootpath'] . '/conf/index/install.php')){		
    			exec('cp ' . $conf['rootpath'] . '/conf/index/install.php '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
    			
    			$app->log("INSTALL FILE EXIST",LOGLEVEL_DEBUG);
    			$username = escapeshellcmd($data['new']['system_user']);
    			$app->log("DEFINE USERNAME : " . $username,LOGLEVEL_DEBUG);
    			
    			$groupname = escapeshellcmd($data['new']['system_group']);
    			$app->log("DEFINE GROUPNAME : " . $groupname,LOGLEVEL_DEBUG);
    			
    			$app->log("CHMOD install.php 0644",LOGLEVEL_DEBUG);
    			$app->system->chmod($data['new']['document_root'].'/' . $web_folder . '/install.php',0644);
    			
    			$app->log("CHOWN install.php",LOGLEVEL_DEBUG);
    			$app->system->chown($data['new']['document_root'].'/' . $web_folder . '/install.php',$username);
    			
    			$app->log("CHGRP install.php",LOGLEVEL_DEBUG);
    			$app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/install.php',$groupname);
    		}else{
    			$app->log("INSTALL FILE MISSING. rootpath :" . $conf['rootpath'] . '/conf/index/install.php',LOGLEVEL_DEBUG);
    		}
    	}
    	
    } // end class
    
    ?>
     
    Last edited: Sep 10, 2013
  3. v1ktor

    v1ktor New Member

    Hey, I know it's been 2 years but do you still have deployment file for wordpress? Would love to see it, would save me a ton of time. Thanks.
     
  4. lollollollol

    lollollollol Member

    Hi V1ktor,
    Yes, still in production!

    Two files:
    1) install.php (you'll just have to rename install.txt) is for installing a custom wordpress which is on your server (I need it to get my installations made in French, and with all my plugins already installed...). I wrote a bash script to automatically built my custom WP if you are interested...
    2) install.php (install2.txt) is for installing latest Wordpress directly from Worpress.org...

    You just have to customize path/text in the install.php to match your needs.

    [​IMG]

    I hope it will help.
    Laurent
     

    Attached Files:

    till likes this.
  5. v1ktor

    v1ktor New Member

    Thanks a lot Laurent, this saves me time for sure trying to figure out how to put files when website is created in ISPConfig.
     
  6. lollollollol

    lollollollol Member

    Hi V1ktor,

    install.php is automatically copied in the root directory of each new website you'll created.

    Then you have to visit http://yousite.com/install.php and launch the wordpress install (clic on the install button).
    The install.php will get the wordpress.tar.gz (in your server at /var/www/html or at wordpress.org depending which way you choose), extract the files, delete index.html and finaly delete the install.php.
    You'll be redirected to the classic wordpress install.

    I hope it was clear...
    Laurent.
     
  7. victortruica

    victortruica New Member

    An alternative is to use the APS installer that's now integrated in ISPConfig3.
     
  8. lollollollol

    lollollollol Member

  9. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    FYI, it is in ispconfig 3.1, using a newer APS version. For the older one you can install the outdated wordpress then just update it as soon as it's installed.
     
  10. lollollollol

    lollollollol Member

    Good to know but FYI
    I don't run unstable versions on my servers (even if it's quite well).

    Incidentally with my method I download once the WP files (without having to download update behind...)
    With your method, I have to download every time the WP file and I have to download every time the update... :-D

    I let everyone choose his method. I'm lazy and stingy: I save my actions and my bandwidth ...
    So I'll continue with my scripts...
     

Share This Page