Lamp-quickstart-howto

From Wsms

Jump to: navigation, search

Howto setup and use lamp on Linux.

LAMP is an acronym for Linux-Apache-Mysql-Php (or Python or Perl).

The easiest way set up a lamp server is to install a web application the uses the components you want. One example is Mediawiki.

user pages php homepage setup

Adapted from the page below. You should look at that page for a good explanation and latest changes. I put this info here because I used ubuntu instead of fedora and just in case the referenced page disappears. --Ggeller 07:44, 18 January 2010 (PST)

After you install apache, php and mysql do the following:

Edit /etc/apache2/apache2.conf and add the following line: UserDir public_html

Restart apache:

root@ggeller-wikiplanet:~# apache2ctl graceful

Make sure you are a normal user (not root), then set up you public html directory:

cd $HOME
mkdir public_html
echo "my homepage" > public_html/index.html
chmod a+x $HOME $HOME/public_html
chmod a+r $HOME/public_html/index.html

Add some data to mysql:

ggeller@ggeller-wikiplanet:~$ mysql -u root -p
USE test;
SHOW tables;
CREATE TABLE persons( name VARCHAR(50), email VARCHAR(50) );
SHOW tables;
DESC persons;
INSERT INTO persons VALUES('Tero Karvinen', 'karvinen at-sign iki.fi');
SELECT * FROM persons;
INSERT INTO persons VALUES('Sample Person', 'recycle@nosuch.invalid');
SELECT * FROM persons;
QUIT;

Set up $HOME/public_html/database.php with the following contents:

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", "")
        or die("Could not connect : " . mysql_error());
    print "Connected successfully";
    mysql_select_db("test") or die("Could not select database");

    /* Perform SQL query */
    $query = "SELECT * FROM persons";
    $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 http://localhost/~user/database.php. Use your own login name instead of user.

see also

http://myy.helia.fi/~karte/kurssit/lamp-linux-apache-mysql-php-quickstart.html -- quickstart guide for fedora

Personal tools