How to Deploy a PHP Project on Apache (Linux)
π 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 updateInstall Apache.
sudo apt install apache2 -yInstall PHP.
sudo apt install php libapache2-mod-php php-mysql -yInstall MySQL.
sudo apt install mysql-server -yβΆοΈ Step 2 β Start Required Services
Start Apache.
sudo systemctl start apache2Enable Apache at boot.
sudo systemctl enable apache2Start MySQL.
sudo systemctl start mysqlEnable MySQL at boot.
sudo systemctl enable mysqlVerify both services.
sudo systemctl status apache2sudo systemctl status mysqlπ Step 3 β Copy the Project
Assume the project is located in:
/home/krose/ArticleWebsiteCopy it to Apacheβs web directory.
sudo cp -r ~/ArticleWebsite /var/www/html/Verify the project.
ls /var/www/htmlExpected output:
ArticleWebsiteGet 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/ArticleWebsiteSet permissions.
sudo chmod -R 755 /var/www/html/ArticleWebsiteποΈ Step 5 β Configure the Database
Login to MySQL.
sudo mysqlCreate 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.phpExample:
<?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/ArticleWebsiteUsing server IP:
hostname -IExample:
192.168.1.120Open 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.logRecords all incoming requests.
/var/log/apache2/error.logRecords 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.








