views:

186

answers:

4

I am not sure to be enough be by my question... Well i'm developping a CMS in PHP with Zend Framework. I would like to have a nice web gui to install and set up the application after unpacked it somewhere... Some CMS or whatever the application is, offer this way to do by simply entering an 'install url' like 'http://localhost/app/install'

I'd like to do the same but i don't want to let any users to set it up, so i am looking for a way to determine if the application has been set up or no.

Inspired by the pid file in the unix world, i though to do the same with an InstallState file. Writing any boolean value inside and then check could be an idea..

What do you think about that ? Do you have better ideas ?

+1  A: 

You could write a value your database somewhere or simply have the file delete itself after the installation is complete. A lot of software ask users to delete the /install file after it is complete. To force this, you could check if the install directory exists and make the admin delete it before the rest of the script can run.

Sam152
thanks for your answer but i don't think it's the best ideas since i think my application doesn't have to be dependant of the database.I mean especially for its setup step...
Boris Guéry
A: 

Currently a lot of web applications have a config-like file somewhere, where they store stuff like database login info and so on. On a freshly installed application the code might check for existence of config file or some variables in it and if it's not present, redirect to the install script.

Same script could later refuse to work if the config file is present. Also it's common practice to tell the user to delete the install script / folder after setting up. Some even go lengths to force deletion by not working at all if the files are present.

There are other ways to do what you want, but I found this to be the most common among open-source web apps.

frgtn
+3  A: 

Though I upvoted Sam152's answer, I felt the need to give some further clarification (that just didn't really fit in a comment). The practice I use for these situations is as follows:

  1. Let the user run the installer.
  2. Upon successful completion, generate some form of lock file (many applications just create an 'installer.lock' file, with nothing in it). The presence of this file should stop the user running the installer again.
  3. Prevent the main script from executing (even after a successful setup) until the entire installation directory is removed from the server.

This provides safeguards on two levels. It prevents the installer being run again (which may or may not be a problem for your application), and it prevents the product being run. You can use the presence of the locking file to tell the user that they've already compleed the install successfully, they don't need to install again, and that they should remove the directory.

Simple, safe, sorted. :)

James Burgess
I don't get why apps don't just delete the install directory automatically? Why force the admin to do extra work?
Mark
That is a possibility - but there are usually two obstacles to this. Either you don't want to force the user to give liberal permissions to the install script itself, or the user is unable to grant them to the install script (due to host set-up, etc). The best compromise is to try to delete automatically, but to tell them to remove it themselves if not... however, many FTP clients simply don't give suitable permissions by default, and many users would be confused by being asked to change these permissions. Best to keep it simple, even if it's not the "shortest" way to do it.
James Burgess
Of course, the ultimate simplicity would be to put the installer 'in line' with the main application, and then show it the first time... and then create a file or DB entry to say the software is installed. However, this poses a security problem if the DB were to be modified, or the file deleted accidentally, as you then run the risk of displaying the installer to end-users, and that's just asking for trouble. There are other solutions, but they're usually more hassle (for the user, and for the developer) than they're worth.
James Burgess
Great advice James. +1
Sam152
Alix Axel
A: 

Using Drupal's installation script as an example...

if ( ! config_file_exists()) {
    tell_user_to_write_config_file();
} elseif ( ! can_connect_to_db()) {
    tell_user_to_fix_config_file();
} elseif ( ! check_db_if_installed() ) {
    do_install_stuff();
} else {
    tell_user_system_installed()
}

Obviously, the magic happens in do_install_stuff() - in the case of Drupal, it checks for the existance of a row in a settings table (variable) called install_task. As long as that's the last thing written when you do the initial system install, you'd be good to go.

Sean McSomething