ITeye博客

deploy php http server

maxer025 · 2026-07-26 21:52 · Web前端 · Markdown

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:

Open in your browser:

http://YOUR_SERVER_IP/info.php

You should see the PHP information page.

  1. 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

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 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.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。