Giter Site home page Giter Site logo

simplephp's Introduction

Setting Up a LAMP Stack on Linux and Hosting a Simple Website

In this document, we will walk through the steps required to set up a LAMP stack on a Linux machine and host a simple website that displays the visitor's IP address and current time. We will also explain basic networking concepts such as IP address, MAC address, switches, routers, and routing protocols.

Sub-task #1: Linux Server Simulation

  1. Install Apache, MySQL, and PHP on the Linux machine using apt-get or another package manager of your choice.
sudo apt-get update
sudo apt-get install apache2 mysql-server php libapache2-mod-php -y
sudo apt-get install php-mysqli
  1. Configure Apache to serve the website from the /var/www/html/ directory.
sudo nano /etc/apache2/sites-available/000-default.conf

Modify the file to add the following lines:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
  1. Create a simple website that displays the message "Hello World!" when accessed through a web browser. Create the file /var/www/html/index.php with the following contents:
<?php
echo "Hello World!";
?>
  1. Configure MySQL to create a new database, user, and password for the website.
sudo mysql_config_editor set --login-path=local --user=root --password

Create a new database:

CREATE DATABASE users;

Create a new user and grant privileges:

sudo mysql --login-path=local -e "CREATE USER 'ubuntu'@'localhost' IDENTIFIED BY '$DATABASE_PASS'"
sudo mysql --login-path=local -e "GRANT ALL PRIVILEGES ON users.* TO 'ubuntu'@'localhost'; SET PASSWORD FOR 'ubuntu'@'localhost' = '$DATABASE_PASS';"
  1. Modify the website to use the newly created database to display a message that includes the visitor's IP address and the current time. Modify the /var/www/html/index.php file to include the following PHP code:
<?php
$ip_address = $_SERVER['REMOTE_ADDR'];
$current_time = date('Y-m-d H:i:s');

$conn = mysqli_connect('localhost', 'ubuntu', 'Admin@123', 'users');
if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
}
mysqli_select_db($conn, 'users');

$sql = "INSERT INTO visitors (ip_address, visit_time) VALUES ('$ip_address', '$current_time')";
if (mysqli_query($conn, $sql)) {
  echo "Hello World! Your IP address is $ip_address and the current time is $current_time.";
} else {
  echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>
  1. Test the website by accessing it through a web browser and verifying that it displays the expected message.

Sub-task #2: Git & GitHub

  1. Initialize a new Git repository on your local machine.
git init
  1. Create a .gitignore file to exclude any sensitive files (like configuration files with passwords).
# .gitignore
config.php
  1. Commit your Markdown documentation file in the Git repository.
git add README.md
git commit -m "Initial commit"
  1. Create a new repository on GitHub and push your local repository to GitHub.
git remote add origin <github-repo-url>
git push -u origin master

Sub-task #3: Networking Basics

IP address

An IP address is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. It is used to identify and locate devices on the network. There are two types of IP addresses - IPv4 and IPv6.

MAC address

A MAC address is a unique identifier assigned to a network interface controller. It is used to identify devices on a physical network and is different from an IP address. MAC addresses are assigned by the manufacturer of the network interface controller.

Switches

Switches are network devices that connect multiple devices together and filter and forward data to their destination. They operate at the data link layer (layer 2) of the OSI model and use MAC addresses to forward data.

Routers

Routers are network devices that connect multiple networks together and route data between them. They operate at the network layer (layer 3) of the OSI model and use IP addresses to forward data.

Routing protocols

Routing protocols are used to determine the best path for data to travel between networks. They are used by routers to exchange information about network topology and determine the optimal path for data to reach its destination.

SSH process for connecting to a cloud instance

To connect to a cloud instance from a remote machine, you can use SSH (Secure Shell) to securely access the Linux machine. First, retrieve the public IP address of the cloud instance. Then, open a terminal on theremote machine and enter the following command:

ssh username@public-ip-address

Replace "username" with the username of the Linux machine and "public-ip-address" with the public IP address of the cloud instance. You will be prompted to enter the password for the user account.

Once you have successfully logged in, you can perform administrative tasks on the Linux machine through the terminal. To exit the SSH session, enter the following command:

exit

Conclusion

In this document, we have demonstrated how to set up a LAMP stack on a Linux machine and host a simple website that displays the visitor's IP address and current time. We have also explained basic networking concepts such as IP address, MAC address, switches, routers, and routing protocols. Additionally, we have detailed the steps required to connect to a cloud instance from a remote machine using SSH.

simplephp's People

Contributors

abdelrhmanaf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.