Skip to content

Instantly share code, notes, and snippets.

@shirro
Created April 12, 2012 13:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shirro/2367159 to your computer and use it in GitHub Desktop.
Save shirro/2367159 to your computer and use it in GitHub Desktop.
Quick RAMP
# This is not the way to run a production web server
#
# It is a quick and easy way to get php and a database working
# on a low end machine for educational purposes.
#
# This will require Debian Wheezy for PHP 5.4
# I think that is coming to the Raspberry Pi soon
sudo apt-get install php5-cli php5-sqlite sqlite3
# check php version needs to be 5.4 (eg Debian Wheezy)
php -v
# make a document root for the website
mkdir -p app/doc_root
cd app
# create our database
sqlite3 pi.db << "EOD"
create table pimodels (name, usb, nic, ram, price);
insert into pimodels values ('A', 1, 0, 256, 25);
insert into pimodels values ('B', 2, 1, 256, 35);
EOD
# Create our PHP web page
cd doc_root
cat << "EOD" > index.php
<?php
$db = new SQLite3('../pi.db');
$results = $db->query('select * from pimodels');
echo <<< EOD
<!doctype html>
<head>
<title>Easy as Pi</title>
</head>
<body>
<table>
<thead><tr><th>Name</th><th>USB</th><th>NIC</th><th>RAM</th><th>USD</th></tr></thead>
<tbody>
EOD;
while ($row = $results->fetchArray(SQLITE3_NUM)) {
echo '<tr>';
foreach ($row as $field) {
echo "<td>$field</td>";
}
echo '</tr>';
}
echo '</tbody></table>';
EOD
# start the server
php -S localhost:8080
# open your Pi's web browser to http://localhost:8080/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment