2 define('INSTALLDIR', dirname(__FILE__));
11 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
18 function checkPrereqs()
20 if (file_exists(INSTALLDIR.'/config.php')) {
21 ?><p class="error">Config file "config.php" already exists.</p>
26 if (version_compare(PHP_VERSION, '5.0.0', '<')) {
27 ?><p class="error">Require PHP version 5 or greater.</p><?
31 $reqs = array('gd', 'mysql', 'curl',
32 'xmlwriter', 'mbstring',
35 foreach ($reqs as $req) {
36 if (!checkExtension($req)) {
37 ?><p class="error">Cannot load required extension "<?= $req ?>".</p><?
42 if (!is_writable(INSTALLDIR)) {
43 ?><p class="error">Cannot write config file to "<?= INSTALLDIR ?>".</p>
44 <p>On your server, try this command:</p>
45 <blockquote>chmod a+w <?= INSTALLDIR ?></blockquote>
50 if (!is_writable(INSTALLDIR.'/avatar/')) {
51 ?><p class="error">Cannot write avatar directory "<?= INSTALLDIR ?>/avatar/".</p>
52 <p>On your server, try this command:</p>
53 <blockquote>chmod a+w <?= INSTALLDIR ?>/avatar/</blockquote>
61 function checkExtension($name)
63 if (!extension_loaded($name)) {
64 if (!dl($name.'.so')) {
74 <p>Enter your database connection information below to initialize the database.</p>
75 <form method='post' action='install.php'>
77 <ul class='form_data'>
79 <label for='sitename'>Site name</label>
80 <input type='text' id='sitename' name='sitename' />
81 <p>The name of your site</p>
85 <label for='host'>Hostname</label>
86 <input type='text' id='host' name='host' />
87 <p>Database hostname</p>
90 <label for='host'>Database</label>
91 <input type='text' id='database' name='database' />
95 <label for='username'>Username</label>
96 <input type='text' id='username' name='username' />
97 <p>Database username</p>
100 <label for='password'>Password</label>
101 <input type='password' id='password' name='password' />
102 <p>Database password</p>
105 <input type='submit' name='submit' value='Submit'>
111 function updateStatus($status, $error=false)
122 function handlePost()
127 $host = $_POST['host'];
128 $database = $_POST['database'];
129 $username = $_POST['username'];
130 $password = $_POST['password'];
131 $sitename = $_POST['sitename'];
133 updateStatus("Starting installation...");
134 updateStatus("Checking database...");
135 $conn = mysql_connect($host, $username, $password);
137 updateStatus("Can't connect to server '$host' as '$username'.", true);
141 updateStatus("Changing to database...");
142 $res = mysql_select_db($database, $conn);
144 updateStatus("Can't change to database.", true);
148 updateStatus("Running database script...");
149 $res = runDbScript(INSTALLDIR.'/db/laconica.sql', $conn);
150 if ($res === false) {
151 updateStatus("Can't run database script.", true);
155 updateStatus("Writing config file...");
156 $sqlUrl = "mysqli://$username:$password@$host/$database";
157 $res = writeConf($sitename, $sqlUrl);
159 updateStatus("Can't write config file.", true);
163 updateStatus("Done!");
169 function writeConf($sitename, $sqlUrl)
171 $res = file_put_contents(INSTALLDIR.'/config.php',
173 "\$config['site']['name'] = \"$sitename\";\n\n".
174 "\$config['db']['database'] = \"$sqlUrl\";\n\n");
178 function runDbScript($filename, $conn)
180 $sql = trim(file_get_contents($filename));
181 $stmts = explode(';', $sql);
182 foreach ($stmts as $stmt) {
184 if (!mb_strlen($stmt)) {
187 $res = mysql_query($stmt, $conn);
188 if ($res === false) {
198 <title>Install Laconica</title>
199 <link rel="stylesheet" type="text/css" href="theme/base/css/display.css?version=0.7.1" media="screen, projection, tv"/>
200 <link rel="stylesheet" type="text/css" href="theme/base/css/modal.css?version=0.7.1" media="screen, projection, tv"/>
201 <link rel="stylesheet" type="text/css" href="theme/default/css/display.css?version=0.7.1" media="screen, projection, tv"/>
207 <h1>Install Laconica</h1>