Instructor: In this lecture,
we will learn about LAMP Stack,
a popular open-source software package for building
and deploying web applications on Linux-based systems.
LAMP stands for Linux, Apache, MySQL, and PHP.
We have already covered Linux, Apache, and MySQL
in previous lectures, right?
If needed, please revisit those topics before continuing.
For now, let's focus on PHP,
a server-side scripting language used
to create dynamic websites.
PHP works with MySQL to manage and display web content
and is widely used for backend tasks
like login systems and forms.
Together, Linux, Apache, MySQL,
and PHP form a secure, stable, and free platform
for hosting web applications.
The LAMP stack originated in the 1990s
and became the standard
for hosting open-source projects like WordPress.
It integrates Linux as the operating system,
Apache as a web server, MySQL for database management,
and PHP for handling dynamic content.
Let's move on and practice.
I have already opened my party session here.
The first step you always do is check who you are,
your route.
My host name is MyFirstLinuxVM,
and the IP address is 192.168.100.192.
All right, this is my IP.
Of course, it might be different in your case,
but confirm you are logged into the right system.
All right, for me, I am logged into the right machine.
Let's start by checking if Apache is running on this machine
by verifying its status.
All right, great.
It's successfully running.
Similarly, we should check if MariaDB, our database,
is running as well.
As you know, MariaDB is a free
and open-source version of MySQL.
All right, it's also running.
Now, in case if it's not running
or installed on your system, you could definitely go ahead
and using the DNF utility to install the database
or Apache or anything that is missing.
All right, for us it's running.
Now we have three important components up and running,
and those are Linux, Apache, and MariaDB.
Now it's time to install PHP,
which is an important part of the LAMP Stack.
To install PHP, run the command that includes PHP,
php-mysql, and php-cli, along with the minus y option
to automatically approve the installation.
Here, php-cli allows you to run PHP commands
from the terminal, and php-mysqlnd allows PHP to communicate
with the MySQL or MariaDB database in our case.
So let's wait for the installation to complete.
All right, beautiful.
Now it's done and ready to be used on our server.
After installing PHP,
make sure that Apache recognizes the new PHP installation.
For this, restart the Apache server.
Next check if PHP is installed and working properly.
For this, navigate to the web directory
where you will place all your web pages and scripts,
including your PHP files.
All right, in our Linux system, the default directory
for the website files is /var/www/html.
All right, let's create a simple PHP test file
called info.php.
In this file, add basic PHP syntax
using the starting and ending tags.
Inside these tags, let's add a simple PHP function, phpinfo,
which will display detailed information
about your PHP configuration when accessed
through a web browser.
All right, let's save the file and exit.
Now to test it, open your web browser
and type http:// followed by your machine's IP address.
And in my case, the IP address is 192.168.100.192.
Add a slash and type the name of the webpage,
which is info.php.
And pressing Enter, you will see a page
displaying important details such as PHP version,
server settings, and enabled modules.
This confirms that PHP is successfully installed
and working, and the LAMP Stack is fully set up
and ready to go.
All right, let's create a scenario
where we write a PHP script to connect to a new database.
First log into MariaDB using the root user
by running the command mysql -u,
and that's minus U for user, and the user is root,
space minus P and entering the root password.
Once logged in, create a test database named testdb
by typing, create database testdb
and followed by the semicolon.
After successfully creating the database,
type exit to leave the Maria database console.
Next, create a PHP file called Database,
underscore connect.php.
Inside this file, define the database connection details,
using variables for the server name, username, password,
and the database name.
The server name is set to localhost, the username is root,
and the database name is test database.
Establish a connection using the built-in mysqli function
and a condition to check if the connection was successful.
If there's an error, display a message, "connection failed,"
followed by the error details.
If successful, display,
"successfully connected to the database,"
save the file and exit.
To test the connection, open the browser again
and replace info.php with the database _connect.php.
If you see an error message about access denial,
update the password variable in the file
with the correct value, save it, and then refresh the page.
All right, once fixed, you will see,
"successfully connected to the database,"
confirming the connection.
Beautiful.
So folks, this is a simple explanation
of how the LAMP Stack works in Linux.
Now if someone asks you any question about LAMP Stack,
then you should be confident enough to remember
that we learned Linux, we have learned Apache,
now, MySQL, which is a database, MariaDB,
you learned that, and PHP was the main part
that we learned in this video.
So now, you know everything about LAMP Stack.
So it's your turn to practice.
Follow the steps carefully, test your file,
troubleshoot errors, and see the LAMP Stack in action,
and I'll see you in the next lecture.