apache-lamp-config

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Apache & LAMP Config

Apache & LAMP 配置

When to use this skill

何时使用本技能

  • Configuring local development environments (MAMP, XAMPP, Docker + Apache).
  • Managing
    .htaccess
    files.
  • Troubleshooting rewrite rules.
  • 配置本地开发环境(MAMP、XAMPP、Docker + Apache)。
  • 管理
    .htaccess
    文件。
  • 排查重写规则问题。

1. Virtual Hosts

1. 虚拟主机

  • Structure: One file per site in
    sites-available
    , symlinked to
    sites-enabled
    .
  • DocumentRoot: Point to the
    public/
    directory, not the project root (security).
  • Directory: Allow overrides:
    apache
    <Directory "/var/www/site/public">
        AllowOverride All
        Require all granted
    </Directory>
  • 结构:每个站点对应
    sites-available
    目录下的一个文件,并创建符号链接到
    sites-enabled
    目录。
  • DocumentRoot:指向
    public/
    目录而非项目根目录(出于安全考虑)。
  • Directory:允许覆盖配置:
    apache
    <Directory "/var/www/site/public">
        AllowOverride All
        Require all granted
    </Directory>

2. .htaccess Best Practices

2. .htaccess 最佳实践

  • Rewrites: Standard pattern for front controllers (Laravel/Symfony):
    apache
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
  • HTTPS: Force HTTPS if not handled by a reverse proxy.
  • 重写规则:适用于前端控制器(如Laravel/Symfony)的标准模式:
    apache
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
  • HTTPS:若未通过反向代理处理,则强制使用HTTPS。

3. PHP-FPM

3. PHP-FPM

  • Timeouts: Increase
    max_execution_time
    and
    memory_limit
    only for specific heavy jobs, not globally.
  • Opcache: Enable Opcache in production for performance.
  • 超时设置:仅针对特定重负载任务增加
    max_execution_time
    memory_limit
    ,而非全局修改。
  • Opcache:在生产环境中启用Opcache以提升性能。