Yazı Boyutu:

GİRİŞ: Apache Nedir?

Apache HTTP Server, dünyanın en yaygın kullanılan açık kaynaklı web sunucusudur. Modüler yapısı, esnekliği ve geniş topluluk desteği ile Linux tabanlı sistemlerde en çok tercih edilen web sunucularından biridir.


BÖLÜM 1 – Kurulum Öncesi Hazırlıklar

1.1 Sistem Gereksinimleri

  • Linux Dağıtımı: Ubuntu 20.04+, Debian 10+, CentOS 7+, AlmaLinux 8+

  • Minimum: 1 GB RAM (PHP-FPM için en az 2 GB önerilir)

  • Root veya sudo yetkisi

1.2 Paket Güncellemeleri

sudo apt update && sudo apt upgrade -y # Ubuntu/Debian sudo yum update -y # CentOS/AlmaLinux

BÖLÜM 2 – Apache Kurulumu

2.1 Apache Web Sunucusunu Yükleme

Ubuntu/Debian:

sudo apt install apache2 -y

CentOS/AlmaLinux:

sudo yum install httpd -y

2.2 Apache’yi Başlatma ve Etkinleştirme

sudo systemctl start apache2 # Ubuntu/Debian sudo systemctl enable apache2 sudo systemctl start httpd # CentOS sudo systemctl enable httpd

BÖLÜM 3 – PHP Kurulumu (PHP-FPM ve FastCGI Yapısı)

Apache ile PHP entegrasyonu için iki ana yöntem vardır:

Yöntem Açıklama
mod_php Apache'ye gömülü PHP modülü (kolay ama performansı düşüktür)
PHP-FPM Apache'nin PHP işlemlerini bir havuzda yönettiği, daha performanslı yöntem
FastCGI FPM’e benzer yapı, ama daha esnek yapılandırma ve bazı sistemlerde daha verimli

BÖLÜM 4 – PHP-FPM ile Apache Yapılandırması

4.1 PHP-FPM Kurulumu

Ubuntu/Debian:

sudo apt install php php-fpm php-cli php-mysql php-curl php-mbstring php-xml -y

CentOS/AlmaLinux:

sudo yum install php php-fpm php-cli php-mysqlnd php-gd php-xml php-mbstring -y

4.2 Apache Modüllerini Aktif Et

sudo a2enmod proxy_fcgi setenvif sudo a2enconf php8.2-fpm # PHP versiyonuna göre değişebilir sudo systemctl restart apache2

4.3 Virtual Host Ayarı (PHP-FPM ile)

sudo nano /etc/apache2/sites-available/site.conf
 
ServerName siteadi.com DocumentRoot /var/www/siteadi.com SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost" ErrorLog ${APACHE_LOG_DIR}/site_error.log CustomLog ${APACHE_LOG_DIR}/site_access.log combined

Aktifleştir:

sudo a2ensite site.conf sudo systemctl reload apache2

BÖLÜM 5 – FastCGI Kullanımı (Alternatif)

5.1 mod_fcgid Kurulumu

sudo apt install libapache2-mod-fcgid -y # Ubuntu/Debian sudo a2enmod fcgid

CentOS’ta:

sudo yum install mod_fcgid -y

5.2 FastCGI VirtualHost Örneği

ServerName siteadi.com DocumentRoot /var/www/siteadi.com AddHandler fcgid-script .fcgi <Directory "/var/www/siteadi.com"> Options +ExecCGI AllowOverride All

BÖLÜM 6 – PHP-FPM Havuz Yapılandırması

6.1 PHP-FPM Ayar Dosyasını Düzenle

sudo nano /etc/php/8.2/fpm/pool.d/www.conf

Ayarlanabilecek önemli parametreler:

pm = dynamic pm.max_children = 20 pm.start_servers = 5 pm.min_spare_servers = 2 pm.max_spare_servers = 8

Not: Sunucunun RAM miktarına göre bu değerleri ayarlayın.

6.2 PHP.ini Optimizasyonu

sudo nano /etc/php/8.2/fpm/php.ini

Önerilen değerler:

memory_limit = 512M upload_max_filesize = 128M post_max_size = 128M max_execution_time = 300

BÖLÜM 7 – Güvenlik ve Performans Ayarları

7.1 gzip Aktifleştirme

sudo a2enmod deflate

/etc/apache2/conf-available/deflate.conf dosyasına aşağıyı ekleyin:

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript

7.2 HTTP/2 Aktifleştirme

sudo a2enmod http2

Virtual host içine şunu ekleyin:

Protocols h2 h2c http/1.1

7.3 KeepAlive Ayarları

sudo nano /etc/apache2/apache2.conf

Değiştirin:

KeepAlive On MaxKeepAliveRequests 100 KeepAliveTimeout 3

BÖLÜM 8 – Apache Performans Modülleri

8.1 mod_cache

Sayfa önbelleklemesi sağlar:

sudo a2enmod cache cache_disk

VirtualHost içine ekleyin:

CacheQuickHandler off CacheEnable disk / CacheRoot "/var/cache/apache2/mod_cache_disk"

8.2 mod_expires

Tarayıcı önbelleği:

sudo a2enmod expires

VirtualHost içinde:

<IfModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 1 month" </IfModule>

BÖLÜM 9 – Güvenlik Ayarları

9.1 Server Signature ve Token Gizleme

sudo nano /etc/apache2/conf-available/security.conf

Şu satırları düzenleyin:

ServerTokens Prod ServerSignature Off

9.2 .htaccess Güvenliği

.htaccess> Order Allow,Deny Deny from all

BÖLÜM 10 – SSL ve HTTPS Kurulumu

Let’s Encrypt (Certbot)

sudo apt install certbot python3-certbot-apache -y sudo certbot --apache -d siteadi.com -d www.siteadi.com

Otomatik yenileme kontrolü:

sudo certbot renew --dry-run

BÖLÜM 11 – Apache Performans Testi

Apache Bench (ab)

ab -n 1000 -c 100 http://localhost/

htop / atop ile İzleme

htop

FPM işlemleri için RAM ve CPU gözlemleyin.


SONUÇ

Apache ile birlikte PHP-FPM veya FastCGI kullanmak, klasik mod_php’ye göre çok daha iyi kaynak yönetimi ve performans sunar. Özellikle:

  • PHP-FPM ile yüksek trafikte daha az RAM tüketilir

  • FastCGI ile esnek handler ayarları yapılabilir

  • gzip, expires ve cache modülleri ile cevap süresi azaltılır

  • HTTP/2 ve KeepAlive gibi ayarlarla daha modern protokoller desteklenir

  • Certbot entegrasyonu ile kolay SSL kurulumu sağlanır