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'];
134 updateStatus("No hostname specified.", true);
139 if (empty($database)) {
140 updateStatus("No database specified.", true);
145 if (empty($username)) {
146 updateStatus("No username specified.", true);
151 if (empty($password)) {
152 updateStatus("No password specified.", true);
157 if (empty($sitename)) {
158 updateStatus("No sitename specified.", true);
163 updateStatus("Starting installation...");
164 updateStatus("Checking database...");
165 $conn = mysql_connect($host, $username, $password);
167 updateStatus("Can't connect to server '$host' as '$username'.", true);
171 updateStatus("Changing to database...");
172 $res = mysql_select_db($database, $conn);
174 updateStatus("Can't change to database.", true);
178 updateStatus("Running database script...");
179 $res = runDbScript(INSTALLDIR.'/db/laconica.sql', $conn);
180 if ($res === false) {
181 updateStatus("Can't run database script.", true);
185 updateStatus("Adding SMS carrier data to database...");
186 $res = runDbScript(INSTALLDIR.'/db/sms_carrier.sql', $conn);
187 if ($res === false) {
188 updateStatus("Can't run SMS carrier script.", true);
192 updateStatus("Adding notice source data to database...");
193 $res = runDbScript(INSTALLDIR.'/db/notice_source.sql', $conn);
194 if ($res === false) {
195 updateStatus("Can't run notice source script.", true);
199 updateStatus("Writing config file...");
200 $sqlUrl = "mysqli://$username:$password@$host/$database";
201 $res = writeConf($sitename, $sqlUrl);
203 updateStatus("Can't write config file.", true);
207 updateStatus("Done!");
213 function writeConf($sitename, $sqlUrl)
215 $res = file_put_contents(INSTALLDIR.'/config.php',
217 "\$config['site']['name'] = \"$sitename\";\n\n".
218 "\$config['db']['database'] = \"$sqlUrl\";\n\n");
222 function runDbScript($filename, $conn)
224 $sql = trim(file_get_contents($filename));
225 $stmts = explode(';', $sql);
226 foreach ($stmts as $stmt) {
228 if (!mb_strlen($stmt)) {
231 $res = mysql_query($stmt, $conn);
232 if ($res === false) {
242 <title>Install Laconica</title>
243 <link rel="stylesheet" type="text/css" href="theme/base/css/display.css?version=0.7.1" media="screen, projection, tv"/>
244 <link rel="stylesheet" type="text/css" href="theme/base/css/modal.css?version=0.7.1" media="screen, projection, tv"/>
245 <link rel="stylesheet" type="text/css" href="theme/default/css/display.css?version=0.7.1" media="screen, projection, tv"/>
251 <h1>Install Laconica</h1>