🎯 Objective
Learn how to deploy a web application on a Linux server by installing a web server and configuring it to serve application files.
In many environments, applications run on a web server like:
In this example, we will deploy a simple PHP web application using Apache.
# 1️⃣ Install Apache Web Server
Ubuntu / Debian
sudo apt update
sudo apt install apache2 -yRHEL / CentOS / Amazon Linux
sudo yum install httpd -y# 2️⃣ Start and Enable Apache
Start service:
sudo systemctl start httpdEnable at boot:
sudo systemctl enable httpdCheck status:
sudo systemctl status httpd# 3️⃣ Install PHP for Web Application
Install PHP and required modules:
sudo yum install php php-mysqlnd php-fpm php-json php-cli-yRestart Apache:
sudo systemctl restart httpd# 4️⃣ Deploy Web Application
Default Apache web root:
/var/www/html/Create a test application:
sudo nano /var/www/html/index.phpExample code:
<?php
echo"Web Application is Running Successfully!";
?># 5️⃣ Set Correct Permissions
sudo chown -R apache:apache /var/www/html
sudo chmod -R 755 /var/www/html# 6️⃣ Configure Firewall
Allow HTTP traffic:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reloadPorts used:
# 7️⃣ Test Web Application
Open browser:
http://server-ipYou should see:
Web Application is Running Successfully!# 🧠 Web Application Architecture
User Browser
│
▼
Web Server (Apache)
│
▼
Application Code (PHP)
│
▼
Database ServerExample database servers:
# 🧪 Troubleshooting
Check Apache status
sudo systemctl status httpdCheck logs
sudo tail -f /var/log/httpd/error_logTest configuration
sudo apachectl configtest# ✅ Summary