Jump to content

Custom Install Profiles


jose
 Share

Recommended Posts

I have been looking over the site-default profile learning how to build a custom profile.  I must confess that it is very straight forward.  I just wanted to make sure that I understood the database creation portion.

During installation site-default is renamed to site, the database is configured and then the site/install/install.sql is run.  After looking it over it seems that it also creates all the tables used by ProcessWire.  This has led me to believe that the best way to build your custom profile is to install the default-profile, overwrite the default templates with your own.  Remove the extra pages from the admin, apply the correct templates to the home page and any other pages you want to leave.  Change fields and templates settings, etc... Delete the images that you don't need from assets.

Once you have your basic site working you dump the database into a install.sql file and replace the install.sql that came with the default site profile. You now have a portable site profile to install anywhere you need(after removing installed.php from assets).

Is this how ProcessWire plans on doing installs in the future or will ProcessWire change to install the tables cleanly in the future(from the core wire folder) and take the user to the admin to start adding pages?  I am just interested in building something future proof.

BTW thanks for making ProcessWire Open Source and sharing with the community.

Link to comment
Share on other sites

During installation site-default is renamed to site,

You can also just call it /site/ if you prefer. We only use /site-default/ initially so that people can continue to keep it cloned easily via Github without worry of it overwriting anything in their /site/ dir. As a result, there is no /site/ dir on the GitHub source (instead it's /site-default/ solely for GitHub).

the database is configured and then the site/install/install.sql is run.

This is correct. Also note that the installer moves /site/install/files/ to /site/assets/files/. So if you were creating a new profile, you would copy your /site/assets/files/ to /site/install/files/ before zipping up your /site/ dir into a new profile.

After looking it over it seems that it also creates all the tables used by ProcessWire.

Also correct. This is so that you can create a site, and then easily export it as a profile just by exporting the database. The installer requires a fairly simple SQL file since ProcessWire uses PHP's MySQL commands to create the DB and insert rows. so things like extended inserts and such probably won't work. So here is the command I use to create a dump for a new profile:

mysqldump --complete-insert=TRUE --add-locks=FALSE --disable-keys=FALSE --extended-insert=FALSE --default-character-set=utf8 -u[user] -p[password] [db_name] > install.sql

After that, I edit the dump file with a good utf8 compliant editor (I use BBEdit/Textwrangler), and remove any extra junk that MySQLdump adds at the top and bottom of the file. This means remove anything that is not a "CREATE TABLE" or "INSERT" statement, unless you specifically want it there.

Then I find the part where the insert statements are for table "users" and I remove all users except guest (ID 1). Likewise, remove all the insert statements for table "users_roles" except for the first one, which assigns role "guest" to user "guest" (1,1,0).

Then your install.sql is ready.  

This has led me to believe that the best way to build your custom profile is to install the default-profile, overwrite the default templates with your own.  Remove the extra pages from the admin, apply the correct templates to the home page and any other pages you want to leave.  Change fields and templates settings, etc... Delete the images that you don't need from assets.

You are correct on all of this. You basically just create the site you want the profile to be. However, you shouldn't need to manually delete any images from assets, as deleting them on the page (or deleting the pages you don't want) will handle deletion of them automatically.

Once you have your basic site working you dump the database into a install.sql file and replace the install.sql that came with the default site profile. You now have a portable site profile to install anywhere you need(after removing installed.php from assets).

This is right, but you can exclude everything from assets other than the dir itself. Your /site/assets/files/ should be copied or moved to /site/install/files/ (as mentioned above) before creating your profile. Why do we do this? Well if you deliver the profile with /assets/files/ already in place, and the file permissions weren't retained for one reason or another (like when they FTPd them or something), then you'd have to tell the user how to make all of the files in /assets/files/ writable. If they don't have shell access, this could be a time consuming process... a lot harder then just making /site/assets/ writable. By making ProcessWire move them from /site/install/files/ to /site/assets/files/, it ensures that there can be no issue with messed up file permissions, since ProcessWire will have created the files. If for some reason, ProcessWire can't move them from /site/install/files/ (like if permissions were lost when the user uploaded the files), then ProcessWire will copy them instead. Either way, it'll be able to complete the install with minimum hassle to the user.

Is this how ProcessWire plans on doing installs in the future or will ProcessWire change to install the tables cleanly in the future(from the core wire folder) and take the user to the admin to start adding pages?  I am just interested in building something future proof.

For the time being, the install profile will include the entire database. But not having made a lot of different install profiles yet, I've not given a lot of thought to doing it differently. It is possible that the core tables will be created/installed separately in the future. If you want to make something future proof, perhaps I should go ahead and make that change now... moving the core table creation outside of the site profile. This won't be too difficult from this end, and I imagine I could have that chance in place within a week.

If it helps, here is my profile creation shell script. It creates a profile from a site that is running, so it goes and moves things around temporarily, creates the zipped profile, then moves them back. You'll see several things that get renamed to a ".old" version. My zip command (and .gitignore file) excludes files ending with ".old", so they are basically removed from the picture temporarily. I run this script after I've already exported the database, and placed it in /site/install/install.sql, using the method mentioned above.

#!/bin/bash
cd /Users/ryan/htdocs/sky/                              <-- sky is the root dir of my PW installation
chmod -R og+rw ./site/assets/*
rmdir ./site/assets/files/*                                  <-- this removes blank directories
mv ./site/assets/files/ ./site/install/files/
mv ./site/config.php ./site/config.php.old         <-- take the live config.php file out of the picture temporarily
mv ./site/config-original.php ./site/config.php  <-- and use a config.php without DB settings in it
mv ./site/assets/cache/ ./site/assets/cache.old/
mv ./site/assets/logs/ ./site/assets/logs.old/
mv ./site/assets/sessions/ ./site/assets/sessions.old/
mv ./site/assets/installed.php ./site/assets/installed.php.old
zip -r -v ./site.zip ./site/* -x@zip_exclude.lst    <-- create the zip file, excluding stuff mentioned in zip_exclude.lst
mv ./site/install/files/ ./site/assets/files/            <-- now move everything back so our site will still work...
mv ./site/config.php ./site/config-original.php
mv ./site/config.php.old ./site/config.php
mv ./site/assets/cache.old/ ./site/assets/cache/
mv ./site/assets/logs.old/ ./site/assets/logs/
mv ./site/assets/sessions.old/ ./site/assets/sessions/
mv ./site/assets/installed.php.old ./site/assets/installed.php

And here is my zip_exclude.lst file, referenced in the "zip" command above. You may not need anything other than the "*.old" and *.old/*" in yours. But I'm running on a Mac and use VIM, so most of these clear up potential files related to those.

.DS_Store
*.DS_Store
*.old
*.old/*
sess_*
*.cache
*.swp
*.sh

BTW thanks for making ProcessWire Open Source and sharing with the community.

Thanks for using it!

Ryan

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...