We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11190
    • 109 Posts
    Hello, all. Web hosting is not our principle business but we do make empty CMS based web sites available to our clients. They can then hire us or use their own web designers to build their sites. We are planning to begin using MODx Revolution.

    After spending many hours installing plugins, snippets, templates, etc., and then configuring the site, we'd really like to not have to do that for every client setup! We'd like to be able to clone a template site that has a sensible default configuration and has many useful plugins, snippets, templates installed.

    After a few hours of searching the Internet and the MODx forums, I'm beginning to believe there is no easy way of doing this. Any recommendations?

    We thought about using PackMan and simply adding all the addins as a single transport package. However, it looks like there is no way to mass add items so adding them one at a time is rather time consuming. I'm assuming the created packages are editable so I suppose we could easily add new add-ins to the package. My biggest concern is the settings. I assume a transport package will not port the settings for the site, will it? For example, we rearrange the Component menu, set up FURLs, etc.

    We thought about a file copy and database dump as per http://rtfm.modx.com/display/revolution20/Moving+Your+Site+to+a+New+Server but we are concerned about the Extras section. When we look in Namespace, sure enough, there are tons of paths to be edited. If we knew it was all in the file system, we could simply run sed and edit all the files in place but, if anything is in the database and especially in custom tables, I'm concerned about missing something.

    So, again, how does one use a template site with add-ins and tweaked settings to create many other empty sites in a multi-tenant environment? Thanks - John

    PS - very glad to be back on MODx after being away for several years.
      http://www.spiritualoutreach.com
      Making Christianity intelligible to secular society
      • 3749
      • 24,544 Posts
      Yes, you can definitely do settings in a transport package (in fact, you can do anything if you can figure out how).

      You might try installing the GetMyComponent package. It installs MyComponent, which creates a working transport package and has examples of almost everything you'd want to do.

      There's a tutorial here: http://bobsguides.com/mycomponent-tutorial.html.

      As you're probably already aware, building a transport package, even with the support of MyComponent, is not a trivial job.

      Welcome back. smiley
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 11190
        • 109 Posts
        Thanks, Bob. I need to read it more carefully but it seems more geared toward creating my own components rather than repackaging the settings and installed components for a template site so they can be deployed on a new site. Still digging. Thanks again - John
          http://www.spiritualoutreach.com
          Making Christianity intelligible to secular society
          • 3749
          • 24,544 Posts
          It takes a while to figure out, but you can really package anything with it. And you can give the user options during the install.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 11190
            • 109 Posts
            I took several hours to work through the MyComponent component. It was most impressive but we elected not to use it. Duplicating the customized settings looked pretty straightforward. Renesting the menus and moving them around looked a little more challenging but the killer was the subpackages. If I read the script correctly, they would be downloaded but not installed. Since we have well over 100 installed, I did not want to have us clicking on scores of Install buttons to set up a new client.

            Instead, we developed this procedure. Would anyone care to cast an eye on it to see if we got it right. As a caveat from the beginning, the script will need to be adapted, e.g., pacifera.com www.pacifera.com are two separate sites right now (we are re-evaluating that decision) so we do not make any domain dependent changes to .htaccess but we do rename it to something else for security reasons. Thus, there is no reference to .htaccess in the script.

            It assumes all clients are peers of the base installation in the file system, that the web server runs as the user apache, and several settings in the preferences such as site_name=MODXBase and [email protected].

            Here is the (expunged) procedure and script from our internal documentation:

            This procedure will create a client MODx instance for either public or private access from a template MODx installation.

            Enter the manager interface for the base site (http://modx.mycompany.com/manager)
            Clear the cache: Site --> Clear Cache
            clear the error log: Reports --> Error Log
            and clear sessions: Security --> Flush All Sessions

            We next need to run the client creation script. One will need the following information:
            database user name
            database user password
            database name
            web site host name, e.g., www.mycompany.com
            web site name, e.g., MySite
            email contact address
            database administrator password

            Once we have that information, we can run the script:
            cd /usr/local/modx
            ./newclientmodx <client ID> , e.g., ./newlicentmodx clientA
            Once this is finished, go to the web site setup URI for the site, e.g., www.mycompany.com/setup and run it as an upgrade. Check the delete setup files on the last page.
            Change the client's administrator user username and password
            Make any customizations to the settings.

            Here is the newclientmodx script:

            #!/bin/bash
            # Copyright 2011 - John A. Sullivan III / Pacifera, LP
            # newclientmodx creates a new client instance of MODx from a MODx template site
            
            # Collect the information; the Client ID is optionally passed on the command line
            DBHOST="-h mysql.mycompany.com "
            CID=${1}
            if [ -z "${CID}" ];then
                    read -p "Please enter the client ID: " CID
            fi
            echo
            read -p "Please enter the database user name: " DBUSER
            echo
            match=0
            while [ ${match} -eq 0 ]
            do
                    read -s -p "Please enter the database user password (characters will not display): " DBPW
                    echo
                    read -s -p "Please re-enter the database user password for confirmation (characters will not display): " DBPW2
                    echo
                    if [ "${DBPW}" = "${DBPW2}" ]; then
                            match=1
                    else
                            echo "Passwords do not match; please try again."
                            echo
                    fi
            done
            echo
            read -p "Please enter the database name: " DBNAME
            echo
            read -p "Please enter the web site host name, e.g., www.pacifera.com : " URL
            echo
            read -p "Please enter the web site name, e.g., Pacifera: " SNAME
            echo
            read -p "Please enter the email contact address: " EMAIL
            echo
            # Setup the database
            echo "Please enter the database administrator password when prompted.  This will happen three times."
            mysqldump ${DBHOST}-u root -p -e --single-transaction modxbase > ${CID}.sql
            if [ $? -ne 0 ];then
                    echo "I could not dump the base database."
                    exit 4
            fi
            sed -i -e "s/\(\usr\/local\/modx\/\)modx\//\1${CID}\//g" -e "s/admin@mycompany\.com/${EMAIL}/g" -e "s/MODXBase/${SNAME}/g" ${CID}.sql
            echo "Please enter the database administrator password again when prompted."
            mysql ${DBHOST}-u root -p -e "create database ${DBNAME};grant all on ${DBNAME}.* to ${DBUSER} identified by '${DBPW}';"
            if [ $? -ne 0 ];then
                    echo "I could not create the new database or grant needed permissions."
                    exit 4
            fi
            echo "Please enter the database administrator password for the last time when prompted."
            mysql ${DBHOST}-u root -p ${DBNAME} < ${CID}.sql
            if [ $? -ne 0 ];then
                    echo "I could not import the new client database."
                    exit 4
            fi
            
            # Create the file system
            cp -a modx "${CID}" && chown -R apache:apache "${CID}"
            if [ $? -ne 0 ];then
                    echo "I could not create the new client file system or set proper permissions."
                    exit 4
            fi
            cd "${CID}"
            sed -i -e "s/^\(\$database_user = '\).*;/\1${DBUSER}\';/" -e "s/^\(\$database_password = '\).*;/\1${DBPW}\';/" -e "s/^\(\$dbase = '\).*;/\1${DBNAME}\';/" -e "s/\(;dbname=\)[^
            if [ $? -ne 0 ];then
                    echo -e "I could not edit the new client file system;\nit is not safe to use the system until the new client\nfile system is destroyed and recreated without errors."
            fi
            IFSORIG=${IFS}
            IFS=$'\n'
            sed -i "s/\(\usr\/local\/modx\/\)modx\//\1${CID}\//g" $(grep -rl *)
            if [ $? -ne 0 ];then
                    echo -e "I could not edit the new client file system;\nit is not safe to use the system until the new client\nfile system is destroyed and recreated without errors."
            fi
            IFS=${IFSORIG}
            echo
            echo "Please now point a browser to ${URL}/setup and run the upgrade routine."
            echo
            

              http://www.spiritualoutreach.com
              Making Christianity intelligible to secular society
              • 3109 ☆ A M B ☆
              • 894 Posts
              The way we have it setup is using MODX to host multiple sites so all sites reside on one install and all chunks, snippets and tpls can be shared with all contexts.

              We created a site with all options blogging, archiving, slider, gallery and all other features as a context ready to be duplicated when a new site needs to be created then based on site settings that we would fill out as a form enable these options and get sites up and running very, very quickly.

              Now if hosting on the same server is an issue then I have nothing else to suggest but it can be done and it works.

              Good Luck.
                Benjamin Marte
                Interactive Media Developer
                Follow Me on Twitter | Visit my site | Learn MODX
                • 11190
                • 109 Posts
                Very interesting, thank you. We were delighted to see the addition of contexts as now it means we can have a single MODx instance per client and they can put all their web sites in different contexts. Since we are a multi-tenant environment, we were hesitant to use a single context between clients for security reasons - to separate the databases, database and manager admin accounts, file system, etc.

                I wouldn't mind being told that's unnecessary smiley We are thinking about how do we maintain hundreds of different instances when an upgrade comes through. I'm wondering if that is what the Advanced installation is for - sharing the core while creating different databases per client - but I haven't investigated it yet.

                Any other tips for supporting and maintaining a multi-tenant environment are welcome. I'm sure I'll find many as I work my way through the forum and documentation. Thanks again - John
                  http://www.spiritualoutreach.com
                  Making Christianity intelligible to secular society
                  • 3109 ☆ A M B ☆
                  • 894 Posts
                  We use the same database for all contexts on our install, upgrading shouldn't be a problem unless they change the core drastically, maybe a few plugins will break here or there.

                  The way I see it if it ain't broke don't fix it there's no need to upgrade unless you want to take advantage of new features or security issues.

                  Hosting multiple sites does have it's drawbacks though the manager can get pretty hectic if you make multiple templates also if you don't have a good backup plan you risk loosing all your info if something goes wrong, performance wise we haven't had any issues yet and we are hosting 20 sites on Windows 2008 server (ugh) and that number will keep growing.

                  The benefits is you can share chunks, snippets and plugins throughout all context reducing development time drastically once you got the framework built out its a matter of styling and making new tpls for each site if needed.

                  You can give clients to the manager to specific areas with resource groups so they don't see other contexts they're not supposed to although setting it up is quite confusing I'm still trying to grasp it myself or you can use NewsPublisher so they can edit their sites via the front end of the website.

                  The possibilities are endless of what you can do with MODX you just gotta put a little elbow grease and make stuff if it doesn't exist and hopefully share it with the community.

                  Good Luck.
                    Benjamin Marte
                    Interactive Media Developer
                    Follow Me on Twitter | Visit my site | Learn MODX