Sitemap

How to Deploy a PHP Project on Apache (Linux)

4 min readJul 31, 2026

--

Press enter or click to view image in full size

πŸ“ Example Project

Article Management Website

🌐 Introduction

A PHP project must be deployed on a web server before users can access it through a browser. In this guide, we will use an Article Management Website as an example to understand the complete deployment process on Apache Web Server using Linux.

🌍 What is Apache?

Apache is an open-source web server that hosts websites and delivers web pages to users. It receives requests from a browser, processes them, and returns the requested website.

Workflow

Browser
β”‚
β–Ό
Apache Server
β”‚
β–Ό
PHP Project
β”‚
β–Ό
Website Display

🐘 What is PHP?

PHP (Hypertext Preprocessor) is a server-side scripting language used to develop dynamic websites. It processes user requests, communicates with the database, and generates web pages.

πŸ—„οΈ What is MySQL?

MySQL is a relational database management system used to store website data such as users, articles, products, comments, and other information.

πŸ”„ How Apache, PHP & MySQL Work Together

Browser
β”‚
β–Ό
Apache
β”‚
β–Ό
PHP
β”‚
β–Ό
MySQL
β”‚
β–Ό
Website Display

🎯 Objective

Learn how to deploy a PHP project on Apache Web Server, configure the required services, and access the project through a web browser.

πŸ“Œ Project Overview

In this guide, we will deploy an Article Management Website.

Features

  • Users can read articles.
  • Admin can publish and manage articles.
  • Articles are stored in a MySQL database.
  • Images are stored in the project folder.
  • PHP handles the backend logic.
  • Apache serves the website.

πŸ“‚ Project Structure

ArticleWebsite/
β”œβ”€β”€ index.php
β”œβ”€β”€ article.php
β”œβ”€β”€ category.php
β”œβ”€β”€ login.php
β”œβ”€β”€ admin/
β”‚
β”œβ”€β”€ css/
β”œβ”€β”€ js/
β”œβ”€β”€ images/
β”œβ”€β”€ uploads/
β”‚
β”œβ”€β”€ includes/
β”‚ β”œβ”€β”€ config.php
β”‚ β”œβ”€β”€ header.php
β”‚ └── footer.php
β”‚
β”œβ”€β”€ database/
β”‚ └── article_db.sql
β”‚
└── README.md

πŸ› οΈ Step 1 β€” Install Required Software

Update the package list.

sudo apt update

Install Apache.

sudo apt install apache2 -y

Install PHP.

sudo apt install php libapache2-mod-php php-mysql -y

Install MySQL.

sudo apt install mysql-server -y

▢️ Step 2 β€” Start Required Services

Start Apache.

sudo systemctl start apache2

Enable Apache at boot.

sudo systemctl enable apache2

Start MySQL.

sudo systemctl start mysql

Enable MySQL at boot.

sudo systemctl enable mysql

Verify both services.

sudo systemctl status apache2
sudo systemctl status mysql

πŸ“ Step 3 β€” Copy the Project

Assume the project is located in:

/home/krose/ArticleWebsite

Copy it to Apache’s web directory.

sudo cp -r ~/ArticleWebsite /var/www/html/

Verify the project.

ls /var/www/html

Expected output:

ArticleWebsite

Get Kinza’s stories inΒ yourΒ inbox

Join Medium for free to get updates fromΒ thisΒ writer.

πŸ” Step 4 β€” Configure File Permissions

Change ownership.

sudo chown -R www-data:www-data /var/www/html/ArticleWebsite

Set permissions.

sudo chmod -R 755 /var/www/html/ArticleWebsite

πŸ—„οΈ Step 5 β€” Configure the Database

Login to MySQL.

sudo mysql

Create a database.

CREATE DATABASE article_db;

Import the SQL file.

mysql article_db < /var/www/html/ArticleWebsite/database/article_db.sql

βš™οΈ Step 6 β€” Configure Database Connection

Open the configuration file.

nano /var/www/html/ArticleWebsite/includes/config.php

Example:

<?php
$host = "localhost";
$user = "root";
$password = "";
$database = "article_db";
$conn = mysqli_connect($host, $user, $password, $database);?>

Save and exit.

πŸ”„ Step 7 β€” Restart Apache

sudo systemctl restart apache2

🌍 Step 8 β€” Open the Website

Local system:

http://localhost/ArticleWebsite

Using server IP:

hostname -I

Example:

192.168.1.120

Open in browser:

http://192.168.1.120/ArticleWebsite

βœ… Step 9 β€” Verify the Deployment

Check that:

  • Homepage opens successfully.
  • Articles are displayed.
  • Images load correctly.
  • CSS and JavaScript work properly.
  • Database connection is successful.
  • Admin login works.
  • New articles can be added.

πŸ“‚ Important Apache Directories

DirectoryPurpose/var/www/html/Stores website projects/etc/apache2/Apache configuration files/etc/apache2/sites-available/Virtual Host configurations/var/log/apache2/access.logWebsite access logs/var/log/apache2/error.logApache error logs

🚨 Common Problems & Solutions

ProblemSolutionWebsite not openingCheck if Apache is runningPHP code appears in browserInstall PHP and restart ApacheCSS or Images not loadingVerify file paths and copied foldersDatabase connection failedCheck config.php and MySQL credentials404 Not FoundVerify the project exists inside /var/www/html/Permission DeniedSet the correct ownership and permissions

πŸ”„ Deployment Workflow

Receive PHP Project
β”‚
β–Ό
Review Project Structure
β”‚
β–Ό
Install Apache + PHP + MySQL
β”‚
β–Ό
Start Required Services
β”‚
β–Ό
Copy Project to /var/www/html/
β”‚
β–Ό
Configure Permissions
β”‚
β–Ό
Create & Import Database
β”‚
β–Ό
Configure config.php
β”‚
β–Ό
Restart Apache
β”‚
β–Ό
Open the Website
β”‚
β–Ό
Test All Features
β”‚
β–Ό
Deployment Successful

πŸ’‘ SOC Analyst Perspective

After deployment, Apache creates log files for every request made to the website.

Important Log Files

/var/log/apache2/access.log

Records all incoming requests.

/var/log/apache2/error.log

Records server and application errors.

A SOC Analyst Can Detect

  • Failed login attempts
  • SQL Injection attempts
  • Directory Traversal attacks
  • 404 (Not Found) errors
  • 500 (Internal Server Error)
  • Suspicious IP addresses
  • Unusual web requests

These logs are important for security monitoring, troubleshooting, and incident investigation in a SOC environment.

--

--