Setting Up a LAMP Stack on a Linux Server
Setting up a LAMP stack is a fundamental skill for many web developers, system administrators, and IT professionals. A LAMP stack consists of Linux (operating system), Apache (web server), MySQL (database server), and PHP (programming language), and it's a widely used platform for hosting websites and web applications.
2023-08-14 11:39:02 - Kassem Husseine
Introduction
In this tutorial, you'll learn how to set up a LAMP (Linux, Apache, MySQL, PHP) stack on a Linux server. This is a popular configuration used to host web applications and websites. By following these steps, you'll have a fully functioning web server ready to serve your application.
Requirements
- A Linux server running Ubuntu, CentOS, or any other supported distribution
- SSH access to the server
- Basic familiarity with the Linux command line
Step 1 - Installing Apache Web Server
Open a terminal and connect to your server via SSH.
Update your package list with
sudo apt update or sudo yum update.
Install Apache with
sudo apt install apache2
or
sudo yum install httpd.
Start Apache with
sudo systemctl start apache2
or
sudo systemctl start httpd.
Enable Apache to start on boot with
sudo systemctl enable apache2
or
sudo systemctl enable httpd.
Step 2 - Installing MySQL Database Server
Install MySQL with
sudo apt install mysql-server or sudo yum install mysql-server.
Secure your MySQL installation with
sudo mysql_secure_installation.
Follow the on-screen prompts to set a root password and remove unnecessary components.
Step 3 - Installing PHP
Install PHP with
sudo apt install php or sudo yum install php.
Restart Apache to recognize PHP with
sudo systemctl restart apache2
or
sudo systemctl restart httpd.
Step 4 - Testing Your LAMP Stack
- Create a PHP file to test the installation by running
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php.
- Open a web browser and navigate to
http://your-server-ip-address/info.php.
- You should see a PHP information page, confirming that PHP is working.
Conclusion
You've successfully set up a LAMP stack on your Linux server. You can now deploy web applications, create databases, and manage your website's content.
License
MIT
Copyright Notice
This tutorial is provided "as-is" without warranty of any kind. The author or contributors shall not be liable for any claims, damages, or other liabilities arising from the use of this tutorial. This content is exclusively provided for blog.husseine.com and may not be reproduced without permission.