Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Sunday, November 15, 2009

LAMP server on Ubuntu

Share Orkut

If you want to have a LAMP server on your Ubuntu machine, but found if difficult to install the different components seperately, the geeks (developers) at Ubuntu have literally made it as good as spoon-feed. For the un-initiated, LAMP is a software bundle for Linux, consisting of Apache HTTP server, MySQL (database component), PHP (for scripting).

The result of their efforts is the following command,

sudo apt-get install lamp-server^

Note: The carrot is not a typo-error, its part of the command. It refers to the 'Tasksel packages' for different tasks. If you need to see the complete list type "sudo tasksel" in the console.

Follow the onscreen instructions, you will be prompted to confirm all the packages, reply with 'YES'. While the installation is halfway, you will be prompted to chose a password for the root user on the MySQL database. Enter your password and confirm it.

Thats it, the install is done; now for the configuration part.

1] Apache2: Open "http://localhost/" in a browser window, if you see a page with "It Works" written on it; then you apache2 installation has succeeded.

Open a terminal window, and paste the following into it, to open up apache2.conf;
sudo gedit /etc/apache2/apache2.conf

add an entry to the end of the file; ServerName your-domain.com (you will have to replace your-domain.com)

2] PHP: Open a console, and type
sudo gedit /var/www/phptest.php

here, enter the following code in the gedit document,

<? php phpinfo(); ?>


restart apache2 with the following command
sudo /etc/init.d/apache2 restart


Now open your browser to "http://localhost/phptest.php"; if your PHP install was succesful, this page will list out the details of the PHP installation.

3] MySQL
Open the MySQL configuration,
sudo gedit /etc/mysql/my.cnf


Make sure the following setting is proper.
bind-address = 127.0.0.1


(This is an optional step)
Installing phpMyAdmin
sudo apt-get install libapache2-mod-auth-mysql phpmyadmin

Follow the onscreen instructions to complete the install, you can access it at "http://localhost/phpmyadmin/"

Finally restart the apache2 server;
sudo /etc/init.d/apache2 restart


There you go, your machine is up and running

Monday, August 24, 2009

Anatomy of a simple IP logger in php

Share Orkut

<?php

// IP logger, place file at yourdomain.com/log.php

//This picture variable defines which image to show
$picture = "http://img.infotropic.com/w/w060529_2.jpg";

//Visitor's IP address is stored in the variable '$ip'
$ip = $_SERVER['REMOTE_ADDR'];

//this line tells the logger the name you want to use for the log file.
// if log.txt doesn't already exist, it will be created automatically
$logs = "log.txt";

//here, we open the log.txt for writing to. The 'a' means append to the EOF
$fh = fopen($logs, 'a') or die(" ");

//here we put the ip address into a variable called 'string data'
// the backslash-n starts a new line in the text file, to make it easier to read
$stringData = "$ip \n";

//here we write to the text file what is in the stringdata variable
fwrite($fh, $stringData);

//now we close the file
fclose($fh);


//and finally we echo some html back to the user's browser so they see an image
echo "<img src='$picture'>";

?>


Note:

If you want to learn web technologies, www.w3schools.com is a pretty good website.