Command
sudo apt-get install apache2
Test
Test if default webpage is accessible using browser
In the web browser, type http://localhost and see the apache welcome page is appearing
In the web browser, type http://localhost and see the apache welcome page is appearing
Command
sudo apt-get install mysql-server
Test
Test if mysql server is running
Check that sever is running
lab@deepak:/var/www/html$ ps ax | grep mysql
16977 ? Ssl 0:00 /usr/sbin/mysqld
Connect to mysql using command line
deepak@deepak:~$ mysql
ERROR 1045 (28000): Access denied for user 'deepak'@'localhost' (using password: NO)
deepak@deepak:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.7.13-0ubuntu0.16.04.2 (Ubuntu)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
Command
sudo apt-get install php libapache2-mod-php
Test
Test the installed binary
lab@deepak:/var/www/html$ which php
/usr/bin/php
Test if php is working fine
lab@deepak:/var/www/html$ php -r 'echo "\n\nYour PHP installation is working fine.\n\n\n";'
Your PHP installation is working fine.
Restart server
lab@deepak:/var/www/html$ sudo /etc/init.d/apache2 restart
[ ok ] Restarting apache2 (via systemctl): apache2.service.
lab@deepak:/var/www/html$
Create test PHP page
Create a test file with extension .php (say test.php) with following content
lab@deepak:/var/www/html$ sudo cat test.php
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
Link this page to index.html
<!--
Added by Deepak
-->
<div class="content_section_text">
<div style="color:#0000FF">
<p>Experiment for auto scroll link is here</p>
<a href="test.php">Link</a>
</div>
</div>
You can see the PHP output when executing in browser
Create your own database in MySQL
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> create database deepakdb;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| deepakdb |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> use deepakdb;
Database changed
Create table in this DB
mysql> use deepakdb;
Database changed
mysql> CREATE TABLE MyGuests (
-> id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
-> firstname VARCHAR(30) NOT NULL,
-> lastname VARCHAR(30) NOT NULL,
-> email VARCHAR(50),
-> reg_date TIMESTAMP
-> );
Query OK, 0 rows affected (0.29 sec)
Edit PHP code(test.php) to insert into table
<!DOCTYPE html>
<html>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "deepakdb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<br> id: ". $row["id"]. " - Name: ". $row["firstname"]. " " . $row["lastname"] . "<br>";
}
} else {
echo "0 results";
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
?>
Execute PHP code to verify if records in DB table are accessed properly
http://askubuntu.com/questions/34/whats-the-easiest-way-to-set-up-a-lamp-stack
http://howtoubuntu.org/how-to-install-lamp-on-ubuntu
https://www.youtube.com/watch?v=uqaoGTnxqNw
http://stackoverflow.com/questions/7639271/simple-php-echo-code-not-working
http://www.w3schools.com/php/php_syntax.asp
http://www.w3schools.com/php/php_mysql_create_table.asp
http://www.w3schools.com/php/php_mysql_insert.asp