LAMP, Linux, Apache, MySQL and PHP

This is article about basic use of LAMP. All of these are my experiments about using PHP with apache2 and OS is Linux Xubuntu 12,04 64-bit. I try few tricks and tell how you are able to use PHP and HMTL5 as your own tools of ingenuity.

Getting started

If you have free time, why not to do best thinks in life, like create your own websites and make some coding at the same time. Here is list of thinks you need

  • Computer
  • Linux (get version you like to run, because I’m a newbie in this I use Xubuntu 12,04)
  • Internet access (required if you want to publish your creations)
  • Lot’s of time, aspirin and tea/coffee/water to ease the pain when something goes wrong and you try hours and hours to correct the script

So after you have get everything in the list, let’s start making miracles.

Thinks you need from Ubuntu Software Center

First type this on terminal emulator: sudo apt-get update to update your available software update list. Then let’s install apache2 with command sudo apt-get install apache2 . This takes some time but after installation is complete open your browser and type localhost on browsers URL-search bar. If everything is going as it should be you should get message like this: IT WORKS. This is the default web page for this server. The web server is running but no content has been added, yet. To test thinks really goes like planned type this localhost/test . Because nothing should be added you get error message 404 and it saids that there is no such file as test in file in this server . When this happens you ready to go second phase.
Type this to you terminal emulator: sudo a2enmod userdir , this is command that makes you able to actually add content on your servers. You get message that apache must be restarted. Type: sudo service apache2 restart , and you have manually restarted your server.

Adding content

Now we are able to actually add some content in your web service. Type: cd , and then type: mkdir public_html , this is most crucial thinks to type because if this is not typed correctly nothing is actually added on you web service. It  stays in your computer. Now go inside of that folder and type: nano index.html . Then you can type some simple HTML text like this

Hello World!!

Hello World!!

And yo make this you need this kind of script

<!doctype html>
<hmtl>
	<head>
		<title>It works!</title>
		<meta charset='utf-8' />
	</head>
	<body>
		<h1>HELLO WORLD!!!!</h1>
<br>
<br>
		<p> This is easy!</p>
<br>
<br>
		<h2>Have a nice day!!</h2>
	</body>
</html>

Now we are ready to advance next phase of making miracles.

PHP content on your site

Basically what PHP will do you, you’re able to make more dynamic web pages. This means that you can basically add more material in different coding language to your web service, like forms. And who would like forms, they are easy to make and they look very nice on web pages. Because I’m newbie with all of this, my forms are not so good as you have seen in various web pages. But I’m going to show you how it is done

  1. First we are needed to download PHP-module for apache2. Type: sudp apt-get install libapache2-mod-php5
  2. Second we need to make some modifications to our etc-files about PHP-module (THIS IS CRUCIAL PART)
    Type: cd /etc/apache2 , this takes you to dictionary
    Type: grep -r php * , this command searches php context from dictionary
    Type: sudoedit mods-enabled/php5.conf , and comment missing line with #-mark
  3. Restart apache2
  4. go to public_html and change the name of index.html to index.php

Now we are ready to make some cool stuff.
Make calculator that shows you the area of square
First, we need to sites to complete this quest. In the first site we have form where we input our context and the second site shows us the answer. First should look like this

Calculator first site

Calculator first site

And this is the source code to create this masterpice you need to type this to the terminal emulator.
I also recommend to use google search if you are first time experimenting PHP and HTML5 coding language like I’m And you are able to actully see that there are various ways to do simple thinks. I used mixed HTML and PHP to create this site.

<!doctype hmtl>
<html>
	<head>
		<title>Calculator</title>
		<meta charset='utf-8'/>
	</head>
	<body>
		<h1>Excersice 1, calculatea area of square</h1>
<br>
		<form action ="action.php" method="post">
		<p>Lenght of one side (cm):<input type="text" name="lenght" /></p>
		<p><input type="submit" /></p>
		</form>
	</body>
</html>

And then to site two. I typed 4 to be length of one side. And two tell this to everyone to calculate area  square you need this formula a*a is a2  . And here are the results

Calculator, second site

Calculator, second site

And to tell you this, you are unavailable to check this site source code, because when you use PHP it automatically calculates and only display the site after the browser examines resulting page. But nevertheless here is the script that I used to make thinks to happen out there. The hardest part is actually type line3 because this is the key element for your success.

<!doctype hmtl>
<answers is...
<The area of the square is <?php echo htmlspecialchars($_POST['lenght']*$_POST['$_POST['lenght']); ?> cm2
It was nice to help you
<

So basically this is one way to use PHP. There various of more material all around internet so you are able to easy access them.
I end the article here and after I get more experiment about MySQL I add it to article.

MySQL

So what is MySQL? It is one of the most used open source relational database system that provides multi-user access to databases. It’s easy to get, just type sudo apt-get install mysql-server and you are able to get it from Ubuntu Software Center. When you begin to download it in just couple moments later you get a window where you are asked to make password for root (administration) user. Just type your root password and download gets going once again.
After the download is ready you can type this to terminal emulator mysql and you should see the program. To exit type \q; and you have exit. If you don’t success type exit; . Now to fully use this program let’s go to MySQL as a root user. Type this to console mysql-uroot -p and type your password. When you get in type SHOW DATABASES; to see all databases. To create new database type CREATE DATABASE (name of the database); . Now that you have create new database let’s make a new user for it. Thats right, it better to make new user for that database, because it’s safer to use it only being regular user than administrator. Type GRANT ALL ON (name of the database).* TO (database name)@localhost IDENTIFIED BY “password here” and you have succesfully created new user. Now exit and go back to mysql as a new user. Once you get in type show databases and then type use (database name).
Now let’s add couple tablets to your new database. Type create table to make new table. To check what you can do go to MySQL homepage, Google search or some kind of FAQ-site(frequently asked questions). To add only text type CREATE TABLE (table name)( (column name) VARCHAR(255) ) ; ,where 255 states for how many letters you can have there. When you have made your tablets to insert stuffing to them type INSERT INTO (tablet name) VALUES(list of thinks to add); . To only view some information from tablet type SELECT (if looking some spesific) FROM (tablet name) ;, if you don’t know what to search type SELECT * FROM (tablet name) .

 

-Tuomas Törmä

**Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. GNU License 3 (link)**
*Update 1,01 Added MySQL info to article

Leave a comment