Ass1_SW lab-III
Ass1_SW lab-III
ASSIGNMENT 1
• WRITING JAVA PROGRAM TO STORE AND FETCH STUDENTS DATA FROM DATABASE
TASK1-CREATE A WEBSITE USING LAMP
STACK
• “LAMP” stack is a group of open-source software that is typically installed
together to enable a server to host dynamic websites and web apps.
• This term is actually an acronym.
• LAMP Stack is just Linux OS, Apache server, MySQL database query language,
PHP web programming language.
WEBSITE USING LAMP STACK
• “Some popular
alternatives are MERN
Stack and MEAN Stack.
• MERN:
MongoDB +
Express Js +
( Angular / React JS )+
Node JS
APACHE WEB SERVER
• .htaccess
• IPv6
• FTP
• HTTP/2
• Perl, Lua, and PHP
• Bandwidth throttling
• WebDAV
• Load balancing
• URL rewriting
• Session tracking
• Geolocation based on IP address
DEPLOY WEBSITE ON LOCAL UBUNTU
MACHINE USING LAMP STACK COMMAND
• Step 1 : Installing Apache And Updating The Firewall Configuration
• Step 2 : Installing MySQL
• Step 3 : Installing PHP
• Step 4 : How To Setup Virtual Host In Apache
• Step 5 : Testing PHP Processing on your Web Server Configuration
• Step 6 : Testing Database Connection from PHP
STEP 1 : INSTALLING APACHE AND UPDATING THE
FIREWALL CONFIGURATION
• exit ##from database after confirmation of getting the following above output##
STEP 3 : INSTALLING PHP
PHP IS THE COMPONENT OF YOUR SETUP THAT WILL PROCESS CODE TO DISPLAY DYNAMIC CONTENT
• sudo apt install php libapache2-mod-php php-mysql ## PHP code can run under
the Apache server and talk to
your MySQL database
• php –v
• #Apache will first look for a file called index.html. We want to tell the web server to prefer PHP
files over others, so make Apache look for an index.php file first.
STEP 4 — CREATING A VIRTUAL HOST FOR YOUR WEBSITE
• <html> • Note :
• <head> • You need to tell apache to give index.php higher
• <title>your_domain website</title> precedence than index.html
• </head> • You can do that by opening
• ‘/etc/apache2/mods-enabled/dir.conf’ file and adding
<body>
index.php at the following location.
• <h1>Hello World!</h1>
• <IfModule mod_dir.c>
• <p>This is the landing page of • DirectoryIndex index.php index.html index.cgi index.pl
<strong>your_domain</strong>.</p>
index.xhtml index.htm
• </body> • </IfModule>
• </html> • And then reload Apache : systemctl reload apache2
STEP 5 — TESTING PHP PROCESSING ON YOUR WEB SERVER
NOW THAT YOU HAVE A CUSTOM LOCATION TO HOST YOUR WEBSITE’S FILES AND FOLDERS
• Create a new file named info.php inside your custom web root folder:
• /your_domain/info.php
• Add the following text, which is valid PHP code, inside the file\
• <?php
• phpinfo();
• To test this script, go to your web browser and access your server’s
domain name or IP address
• http://server_domain_or_IP/info.php
STEP 6 — TESTING DATABASE CONNECTION FROM
PHP
• $ sudo mysql #First, connect to the MySQL console using the root account:
• mysql> CREATE DATABASE example_database;
• mysql> CREATE USER 'example_user'@'%' IDENTIFIED WITH mysql_native_password BY
'password';
• mysql> GRANT ALL ON example_database.* TO 'example_user'@'%’; # user
permission
• mysql> exit
• mysql> SHOW DATABASES;
• mysql> CREATE TABLE example_database.todo_list (item_id INT AUTO_INCREMENT,
• content VARCHAR(255), PRIMARY KEY(item_id));
• mysql> INSERT INTO example_database.todo_list
(content) VALUES ("My first important item");
• mysql> SELECT * FROM
example_database.todo_list;
• mysql> exit
• Now you can create the PHP script that will connect
to MySQL : /your_domain/todo_list.php
• http://your_domain_or_IP/todo_list.php (web
browser)
RESOURCES- LAMP
• https://lakebrains.com/how-to-deploy-single-website-using-lamp-on-ubu
ntu-server/
• https://www.digitalocean.com/community/tutorials/how-to-install-linux-
apache-mysql-php-lamp-stack-on-ubuntu-20-04
TASK2- LOAD BALANCING IN APACHE
WHY WE NEED LOAD BALANCING IN APACHE
• This server will handle all HTTP requests from site visitors. As you
might see, this means even though you run a load balanced system,
using only a single load balancer means you still have a SPOF (single
point of failure). It is also possible to configure an environment where
yet another server will act as the fail-over load-balancer if the first one
fails, but this is outside the scope of this guide.
• To set up our load-balancer, we use the Apache web-server and its
modules mod_proxy, mod_proxy_http and mod_proxy_balancer.
• These are part of most of the Apache web-server distributions.
CONFIGURE APACHE LOAD BALANCER WITH
MOD PROXY
CONFIGURE APACHE LOAD BALANCER WITH MOD PROXY
• The first step to take is to enable the loadbalancing modules. Run the following
commands Use the following commands:
• $ sudo a2enmod proxy
• $ sudo a2enmod proxy_http
• $ sudo a2enmod proxy_balancer
• $ sudo a2enmod lbmethod_byrequests
• $ sudo a2enmod headers
• Run all the above commands then restart Apache to obtain the effect of changes we have
made.
• $ sudo service apache2 restart
DEFINE APACHE LOAD-BALANCER
• </VirtualHost>
RESOURCES - LOAD-BALANCING-ALGORITHMS
https://httpd.apache.org/docs/2.4/mod/mod_proxy_balancer.html
https://www.inmotionhosting.com/support/server/apache/apache-load-bal
ancer/
https://websistent.com/configure-apache-web-server-load-balancing/
https://kemptechnologies.com/load-balancer/load-balancing-algorithms-
techniques
WHAT DOES MYSQL SERVER DO?
• The default MySQL server configuration file is named mysqld.cnf and can
be found in the /etc/mysql/mysql.conf.d/ directory. Open this file on the
source server with your preferred text editor. Here, we’ll use nano:
• $ sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
• Replace the standard IP address with the IP address of server.
• bind-address = <server ip addr>
• Create new database from slave server and import the above dump file :
• mysql -u root -p newdatabase < /path/to/newdatabase.sql
Now we need to configure the slave configuration in the same way as we did the master.
• Open MySQL config file : ‘ sudo nano /etc/mysql/my.cnf’
• Set server id as 2 : server-id = 2
• Make sure below parameters are set properly
• relay-log = /var/log/mysql/mysql-relay-bin.log
• log_bin = /var/log/mysql/mysql-bin.log
• binlog_do_db = newdatabase
https://www.digitalocean.com/community/tutorials/how-to-set-up-replicati
on-in-mysql
https://phoenixnap.com/kb/mysql-master-slave-replication
https://hevodata.com/learn/mysql-master-slave-replication
https://
wiki.logicaldoc.com/wiki/File:Apache-load-balancer-mod-proxy-http.png
TASK4-WRITING JAVA PROGRAM TO STORE AND
FETCH STUDENTS DATA FROM DATABASE
JAVA DATABASE CONNECTIVITY
• In Java, the mysql jdbc Class jar file needs to be imported into the project. This can be done using Class.forName()
Method.
• Class.forName("com.mysql.jdbc.Driver");
• The connection can be established using DriverManager.getConnection(connection_url, username, password);
• Object returned by above command can be used to create statement and run sql query using execute() method.
Example :
1. Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/dbname",“username","password");
2. Statement statement = con.createStatement();
3. statement.execute(query);
4. ResultSet = statement.executeQuery(query);
JAVA DATABASE CONNECTIVITY’S.
RESOURCES
• https://www.geeksforgeeks.org/student-record-system-using-java-swing
/
• https://www.geeksforgeeks.org/java-program-to-retrieve-contents-of-a-t
able-using-jdbc-connection/
• https://projectsgeek.com/2012/07/write-a-program-in-java-for-student-
details-roll-no-name-etc-to-access-as-a-database-and-write-the-
application-in-jdbc-awt-or-jfame.html