3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2009, Control Yourself, 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()
40 if (file_exists(INSTALLDIR.'/config.php')) {
41 ?><p class="error">Config file "config.php" already exists.</p>
46 if (version_compare(PHP_VERSION, '5.0.0', '<')) {
47 ?><p class="error">Require PHP version 5 or greater.</p><?php
51 $reqs = array('gd', 'mysql', 'curl',
52 'xmlwriter', 'mbstring',
55 foreach ($reqs as $req) {
56 if (!checkExtension($req)) {
57 ?><p class="error">Cannot load required extension: <code><?php echo $req; ?></code></p><?php
62 if (!is_writable(INSTALLDIR)) {
63 ?><p class="error">Cannot write config file to: <code><?php echo INSTALLDIR; ?></code></p>
64 <p>On your server, try this command: <code>chmod a+w <?php echo INSTALLDIR; ?></code>
69 if (!is_writable(INSTALLDIR.'/avatar/')) {
70 ?><p class="error">Cannot write avatar directory: <code><?php echo INSTALLDIR; ?>/avatar/</code></p>
71 <p>On your server, try this command: <code>chmod a+w <?php echo INSTALLDIR; ?>/avatar/</code></p>
75 if (!is_writable(INSTALLDIR.'/background/')) {
76 ?><p class="error">Cannot write background directory: <code><?php echo INSTALLDIR; ?>/background/</code></p>
77 <p>On your server, try this command: <code>chmod a+w <?php echo INSTALLDIR; ?>/background/</code></p>
85 function checkExtension($name)
87 if (!extension_loaded($name)) {
88 if (!dl($name.'.so')) {
101 <dl id="page_notice" class="system_notice">
104 <div class="instructions">
105 <p>Enter your database connection information below to initialize the database.</p>
109 <form method="post" action="install.php" class="form_settings" id="form_install">
111 <legend>Connection settings</legend>
112 <ul class="form_data">
114 <label for="sitename">Site name</label>
115 <input type="text" id="sitename" name="sitename" />
116 <p class="form_guide">The name of your site</p>
119 <label for="fancy-enable">Fancy URLs</label>
120 <input type="radio" name="fancy" id="fancy-enable" value="enable" checked='checked' /> enable<br />
121 <input type="radio" name="fancy" id="fancy-disable" value="" /> disable<br />
122 <p class="form_guide" id='fancy-form_guide'>Enable fancy (pretty) URLs. Auto-detection failed, it depends on Javascript.</p>
125 <label for="host">Hostname</label>
126 <input type="text" id="host" name="host" />
127 <p class="form_guide">Database hostname</p>
130 <label for="host">Database</label>
131 <input type="text" id="database" name="database" />
132 <p class="form_guide">Database name</p>
135 <label for="username">Username</label>
136 <input type="text" id="username" name="username" />
137 <p class="form_guide">Database username</p>
140 <label for="password">Password</label>
141 <input type="password" id="password" name="password" />
142 <p class="form_guide">Database password</p>
145 <input type="submit" name="submit" class="submit" value="Submit" />
152 function updateStatus($status, $error=false)
155 <li <?php echo ($error) ? 'class="error"': ''; ?>><?print $status;?></li>
160 function handlePost()
165 $host = $_POST['host'];
166 $database = $_POST['database'];
167 $username = $_POST['username'];
168 $password = $_POST['password'];
169 $sitename = $_POST['sitename'];
170 $fancy = !empty($_POST['fancy']);
172 <dl class="system_notice">
180 updateStatus("No hostname specified.", true);
184 if (empty($database)) {
185 updateStatus("No database specified.", true);
189 if (empty($username)) {
190 updateStatus("No username specified.", true);
194 if (empty($password)) {
195 updateStatus("No password specified.", true);
199 if (empty($sitename)) {
200 updateStatus("No sitename specified.", true);
209 updateStatus("Starting installation...");
210 updateStatus("Checking database...");
211 $conn = mysql_connect($host, $username, $password);
213 updateStatus("Can't connect to server '$host' as '$username'.", true);
217 updateStatus("Changing to database...");
218 $res = mysql_select_db($database, $conn);
220 updateStatus("Can't change to database.", true);
224 updateStatus("Running database script...");
225 $res = runDbScript(INSTALLDIR.'/db/laconica.sql', $conn);
226 if ($res === false) {
227 updateStatus("Can't run database script.", true);
231 foreach (array('sms_carrier' => 'SMS carrier',
232 'notice_source' => 'notice source',
233 'foreign_services' => 'foreign service')
235 updateStatus(sprintf("Adding %s data to database...", $name));
236 $res = runDbScript(INSTALLDIR.'/db/'.$scr.'.sql', $conn);
237 if ($res === false) {
238 updateStatus(sprintf("Can't run %d script.", $name), true);
243 updateStatus("Writing config file...");
244 $sqlUrl = "mysqli://$username:$password@$host/$database";
245 $res = writeConf($sitename, $sqlUrl, $fancy);
247 updateStatus("Can't write config file.", true);
251 updateStatus("Done!");
252 if ($path) $path .= '/';
253 updateStatus("You can visit your <a href='/$path'>new Laconica site</a>.");
259 function writeConf($sitename, $sqlUrl, $fancy)
261 $res = file_put_contents(INSTALLDIR.'/config.php',
263 "if (!defined('LACONICA')) { exit(1); }\n\n".
264 "\$config['site']['name'] = \"$sitename\";\n\n".
265 ($fancy ? "\$config['site']['fancy'] = true;\n\n":'').
266 "\$config['db']['database'] = \"$sqlUrl\";\n\n".
271 function runDbScript($filename, $conn)
273 $sql = trim(file_get_contents($filename));
274 $stmts = explode(';', $sql);
275 foreach ($stmts as $stmt) {
277 if (!mb_strlen($stmt)) {
280 $res = mysql_query($stmt, $conn);
281 if ($res === false) {
289 <?php echo"<?"; ?> xml version="1.0" encoding="UTF-8" <?php echo "?>"; ?>
291 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
292 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
293 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
295 <title>Install Laconica</title>
296 <link rel="shortcut icon" href="favicon.ico"/>
297 <link rel="stylesheet" type="text/css" href="theme/default/css/display.css?version=0.8" media="screen, projection, tv"/>
298 <!--[if IE]><link rel="stylesheet" type="text/css" href="theme/base/css/ie.css?version=0.8" /><![endif]-->
299 <!--[if lte IE 6]><link rel="stylesheet" type="text/css" theme/base/css/ie6.css?version=0.8" /><![endif]-->
300 <!--[if IE]><link rel="stylesheet" type="text/css" href="theme/default/css/ie.css?version=0.8" /><![endif]-->
301 <script src="js/jquery.min.js"></script>
302 <script src="js/install.js"></script>
307 <address id="site_contact" class="vcard">
308 <a class="url home bookmark" href=".">
309 <img class="logo photo" src="theme/default/logo.png" alt="Laconica"/>
310 <span class="fn org">Laconica</span>
316 <h1>Install Laconica</h1>