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.
Installation
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; mysql> FLUSH PRIVILEGES;
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
<?php $db_username="adam"; $db_password="password1234"; $db_host="localhost"; $db_name="testdb"; $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); print_r($row); mysql_close($link); ?>
Visit http://localhost/hw.php. and you should see the output.
Array ( [c] => hello world )