LAMP hello world

Quick start/refresher cheat-sheet on setup of fresh LAMP test server on Ubuntu 9.10. Intended for local development only, no security concerns addressed.


apt-get install apache2 libapache2-mod-php5 php5 mysql-server php5-mysql

Login as root user to create a dedicated user and database.

mysql --user root --password
mysql> USE mysql;
mysql> CREATE DATABASE testdb;
mysql> CREATE USER adam@localhost IDENTIFIED BY 'password1234';
mysql> GRANT ALL ON testdb.* TO adam@localhost;

Login in new user and create a table in the database.

mysql --user adam --password
mysql> USE testdb;
mysql> CREATE table test (c CHAR(255));
mysql> INSERT INTO test (c) VALUES ("hello world");

Write some PHP to read the hello world value. Put it at /var/www/hw.php


$link = mysql_connect($db_host, $db_username, $db_password);
mysql_select_db($db_name, $link);

$result = mysql_query("SELECT * FROM test", $link);
$row = mysql_fetch_assoc($result);


Visit http://localhost/hw.php. and you should see the output.

Array ( [c] => hello world )

Leave a comment

Your email address will not be published.