---
title: "deploy php http server"
author: "maxer025"
date: "2026-07-26T21:52:54Z"
tags: []
categories: ["Web前端"]
slug: "deploy-php-http-server"
draft: false
lastmod: "2026-07-26T21:52:54Z"
id: 2540569
url: "https://maxer025.iteye.com/blog/2540569"
---

If you want to deploy a PHP website using Apache HTTP Server, here's a straightforward setup guide.

1. Install Apache
Ubuntu/Debian
sudo apt update
sudo apt install apache2
CentOS/RHEL
sudo dnf install httpd
sudo systemctl enable --now httpd

Verify Apache is running:

sudo systemctl status apache2    # Ubuntu
sudo systemctl status httpd      # CentOS
2. Install PHP
Ubuntu
sudo apt install php libapache2-mod-php php-cli php-mysql
CentOS/RHEL
sudo dnf install php php-cli php-mysqlnd
sudo systemctl restart httpd

Check PHP:

php -v
3. Deploy Your PHP Application

Apache's default document root is:

Ubuntu:

/var/www/html

CentOS:

/var/www/html

Copy your application:

sudo cp -r my-php-app/* /var/www/html/

Example:

/var/www/html
├── index.php
├── css/
├── js/
└── images/
4. Set Permissions
sudo chown -R www-data:www-data /var/www/html    # Ubuntu

or

sudo chown -R apache:apache /var/www/html        # CentOS

Set appropriate permissions:

sudo find /var/www/html -type d -exec chmod 755 {} \;
sudo find /var/www/html -type f -exec chmod 644 {} \;
5. Test PHP

Create a test file:

sudo nano /var/www/html/info.php

Add:

<?php
phpinfo();
?>

Open in your browser:

http://YOUR_SERVER_IP/info.php

You should see the PHP information page.

6. Configure a Virtual Host (Recommended)

Example:

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/myapp/public

    <Directory /var/www/myapp/public>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/myapp-error.log
    CustomLog ${APACHE_LOG_DIR}/myapp-access.log combined
</VirtualHost>

Enable the site:

sudo a2ensite myapp.conf
sudo systemctl reload apache2
7. Enable URL Rewriting (for Laravel, CodeIgniter, etc.)
sudo a2enmod rewrite
sudo systemctl restart apache2

Ensure the VirtualHost contains:

<Directory /var/www/myapp/public>
    AllowOverride All
    Require all granted
</Directory>
8. Open Firewall

Ubuntu:

sudo ufw allow "Apache Full"

CentOS:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
9. Verify

Open:

http://YOUR_SERVER_IP/

or

http://your-domain.com/

Your PHP application should load.

Typical Production Stack
Operating System: Ubuntu Server 24.04 LTS
Web Server: Apache HTTP Server 2.4
PHP: PHP 8.2 or 8.3
Database: MySQL or MariaDB
HTTPS: Let's Encrypt (Certbot)
Optional: OPcache, Redis, Composer

This configuration is a common and reliable choice for hosting PHP applications in production.