3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2009, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 define('INSTALLDIR', dirname(__FILE__));
29 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
36 function checkPrereqs()
38 if (file_exists(INSTALLDIR.'/config.php')) {
39 ?><p class="error">Config file "config.php" already exists.</p>
44 if (version_compare(PHP_VERSION, '5.0.0', '<')) {
45 ?><p class="error">Require PHP version 5 or greater.</p><?php
49 $reqs = array('gd', 'mysql', 'curl',
50 'xmlwriter', 'mbstring',
53 foreach ($reqs as $req) {
54 if (!checkExtension($req)) {
55 ?><p class="error">Cannot load required extension "<?php echo $req; ?>".</p><?php
60 if (!is_writable(INSTALLDIR)) {
61 ?><p class="error">Cannot write config file to "<?php echo INSTALLDIR; ?>".</p>
62 <p>On your server, try this command:</p>
63 <blockquote>chmod a+w <?php echo INSTALLDIR; ?></blockquote>
68 if (!is_writable(INSTALLDIR.'/avatar/')) {
69 ?><p class="error">Cannot write avatar directory "<?php echo INSTALLDIR; ?>/avatar/".</p>
70 <p>On your server, try this command:</p>
71 <blockquote>chmod a+w <?php echo INSTALLDIR; ?>/avatar/</blockquote>
79 function checkExtension($name)
81 if (!extension_loaded($name)) {
82 if (!dl($name.'.so')) {
92 <p>Enter your database connection information below to initialize the database.</p>
93 <form method='post' action='install.php'>
95 <ul class='form_data'>
97 <label for='sitename'>Site name</label>
98 <input type='text' id='sitename' name='sitename' />
99 <p>The name of your site</p>
103 <label for='host'>Hostname</label>
104 <input type='text' id='host' name='host' />
105 <p>Database hostname</p>
108 <label for='host'>Database</label>
109 <input type='text' id='database' name='database' />
113 <label for='username'>Username</label>
114 <input type='text' id='username' name='username' />
115 <p>Database username</p>
118 <label for='password'>Password</label>
119 <input type='password' id='password' name='password' />
120 <p>Database password</p>
123 <input type='submit' name='submit' value='Submit'>
129 function updateStatus($status, $error=false)
140 function handlePost()
145 $host = $_POST['host'];
146 $database = $_POST['database'];
147 $username = $_POST['username'];
148 $password = $_POST['password'];
149 $sitename = $_POST['sitename'];
152 updateStatus("No hostname specified.", true);
157 if (empty($database)) {
158 updateStatus("No database specified.", true);
163 if (empty($username)) {
164 updateStatus("No username specified.", true);
169 if (empty($password)) {
170 updateStatus("No password specified.", true);
175 if (empty($sitename)) {
176 updateStatus("No sitename specified.", true);
181 updateStatus("Starting installation...");
182 updateStatus("Checking database...");
183 $conn = mysql_connect($host, $username, $password);
185 updateStatus("Can't connect to server '$host' as '$username'.", true);
189 updateStatus("Changing to database...");
190 $res = mysql_select_db($database, $conn);
192 updateStatus("Can't change to database.", true);
196 updateStatus("Running database script...");
197 $res = runDbScript(INSTALLDIR.'/db/laconica.sql', $conn);
198 if ($res === false) {
199 updateStatus("Can't run database script.", true);
203 foreach (array('sms_carrier' => 'SMS carrier',
204 'notice_source' => 'notice source',
205 'foreign_services' => 'foreign service')
207 updateStatus(sprintf("Adding %s data to database...", $name));
208 $res = runDbScript(INSTALLDIR.'/db/'.$scr.'.sql', $conn);
209 if ($res === false) {
210 updateStatus(sprintf("Can't run %d script.", $name), true);
215 updateStatus("Writing config file...");
216 $sqlUrl = "mysqli://$username:$password@$host/$database";
217 $res = writeConf($sitename, $sqlUrl);
219 updateStatus("Can't write config file.", true);
223 updateStatus("Done!");
229 function writeConf($sitename, $sqlUrl)
231 $res = file_put_contents(INSTALLDIR.'/config.php',
233 "\$config['site']['name'] = \"$sitename\";\n\n".
234 "\$config['db']['database'] = \"$sqlUrl\";\n\n");
238 function runDbScript($filename, $conn)
240 $sql = trim(file_get_contents($filename));
241 $stmts = explode(';', $sql);
242 foreach ($stmts as $stmt) {
244 if (!mb_strlen($stmt)) {
247 $res = mysql_query($stmt, $conn);
248 if ($res === false) {
258 <title>Install Laconica</title>
259 <link rel="stylesheet" type="text/css" href="theme/base/css/display.css?version=0.7.1" media="screen, projection, tv"/>
260 <link rel="stylesheet" type="text/css" href="theme/base/css/modal.css?version=0.7.1" media="screen, projection, tv"/>
261 <link rel="stylesheet" type="text/css" href="theme/default/css/display.css?version=0.7.1" media="screen, projection, tv"/>
267 <h1>Install Laconica</h1>