Bilkent - Links and Notes
Free software - benefits for business
Get Ubuntu Linux
Download ISO image (about 700 MB).
Burn it to CD using “Burn image” or “Burn ISO” feature of your CD burning program.
Using Live CD
Start computer, insert CD. Press F8 for CD boot. “English”, “Try...”
Applications: Accessories: Terminal
Turkish keyboard map:
$ setxkbmap tr
Apache Web Server
$ sudo software-properties-gtk -e universe $ sudo apt-get update
Apache, the most popular web server
$ sudo apt-get install apache2
Open firefox, surf to http://localhost . If you get a page with text “It works!”, you have installed the most popular web server in the world.
MySQL Database Server
$ sudo apt-get install mysql-server phpmyadmin
“While not mandatory ... New password for the MySQL “root” user:” k3nsFsll2_11
“Please choose the web server that should be automatically configured”: apache2. Use tab and enter to select OK.
Open Firefox and surf to http://localhost/phpmyadmin/ . If you got PhpMyAdmin login page, you have installed a database and a configuration tool.
To log in with full priviledges, use username: root and the password you gave when installing mysql-server.
User Homepages
$ sudo a2enmod userdir $ sudo /etc/init.d/apache2 restart
And for any user wanting homepages
$ cd $ mkdir public_html $ echo "Tero" > public_html/hello.html
Use Firefox to surf to http://localhost/~ubuntu . Click your document “hello.html”. If you see the text “Tero”, you have enabled user homepages.
Places: Home Folder
Open public_html with a double click. Edit hello.html: right click, choose “Open with Text Editor”. Write some text and save.
Then browse again to your page and refresh. Do you see your changes?
PHP Programming
We have already installed php support when we installed phpmyadmin.
Rename your hello.html to hello.php. In graphical file manager, right click, “Rename...”, give new name.
Tero Karvinen <?php print(2+2) ?>
Open firefox and browse to your page. If you see number 4, you have run some PHP code.
Read Database from PHP
Save this as your code. Change password (”3nlsdu8FB32_fn2o”) and database name (”customers”) and table name (”customers”).
PHP database example - http://iki.fi/karvinen. <br> <?php /* database.php - Use mysql database from php * (c) 200309 Tero.Karvinen <at-sign> iki.fi, adapted from php.net * See http://iki.fi/karvinen Linux Apache MySQL PHP tutorial. */ /* Connect to database */ $link = mysql_connect("localhost", "root", "3nlsdu8FB32_fn2o") or die("Could not connect : " . mysql_error()); print "Connected successfully"; mysql_select_db("customers") or die("Could not select database"); /* Perform SQL query */ $query = "SELECT * FROM customers"; $result = mysql_query($query) or die("Query failed : " . mysql_error()); /* Print results in HTML */ print "<table>\n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { print "\t<tr>\n"; foreach ($line as $col_value) { print "\t\t<td>$col_value</td>\n"; } print "\t</tr>\n"; } print "</table>\n"; mysql_free_result($result); /* Close connection */ mysql_close($link); ?>
Browse to your page http://localhost/~ubuntu/hello.php with firefox. If you see the contents of your database, congratulations!