问题
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:
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:
- Let the user run the installer.
- 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.
- 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. :)
回答2:
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.
回答3:
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.
回答4:
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.
来源:https://stackoverflow.com/questions/843763/how-to-determine-if-a-web-application-has-been-installed-and-set-up