Apache Web Sunucusu Nasıl Kurulur? Ubuntu ve AlmaLinux Rehberi
Ubuntu 22.04 ve AlmaLinux 9 üzerinde Apache HTTP Server kurulumu, virtual host, mod_rewrite ve SSL yapılandırması rehberi.
Apache HTTP Server Nedir?
Apache HTTP Server (kısaca Apache), Apache Software Foundation tarafından geliştirilen, dünyada en uzun süredir aktif olarak kullanılan açık kaynaklı web sunucusudur. 1995 yılında NCSA HTTPd'nin yamalar birikimi üzerine inşa edilmiştir; adındaki "patchy" (yamalı) kelimesine atıfla "Apache" adını almıştır. Günümüzde World Wide Web'in en yaygın sunucu yazılımlarından biri olmayı sürdürmektedir.
Apache, modüler mimarisi sayesinde inanılmaz esneklik sunar. PHP, Python, Perl gibi diller için yerleşik handler'lar (mod_php, mod_wsgi, mod_perl) barındırır; SSL/TLS için mod_ssl, yeniden yönlendirme için mod_rewrite, kimlik doğrulama için mod_auth_* modülleri mevcuttur. .htaccess dosyaları sayesinde dizin düzeyinde yapılandırma yapılabilmesi, özellikle paylaşımlı hosting ortamlarında Apache'yi vazgeçilmez kılar.
Apache, Ubuntu/Debian sistemlerde apache2, RHEL/AlmaLinux sistemlerde ise httpd paket adıyla gelir. Her iki platform için yapılandırma dosyaları ve dizin yapısı biraz farklılık gösterse de temel konseptler aynıdır.
Temel Özellikler
- Modüler Mimari: Yüzlerce resmi ve üçüncü taraf modül ile işlevsellik genişletilebilir.
- .htaccess Desteği: Dizin düzeyinde yapılandırma; paylaşımlı hosting için idealdir.
- mod_rewrite: URL yeniden yazma ve yönlendirme kuralları oluşturulabilir.
- Virtual Host: Tek sunucuda birden fazla alan adı barındırılabilir.
- mod_ssl: OpenSSL tabanlı HTTPS desteği sağlar.
- Çoklu MPM Desteği: prefork, worker ve event MPM'leri performans ihtiyacına göre seçilebilir.
- CGI / FastCGI: Dinamik içerik üretimi için esnek handler seçenekleri sunar.
- Kapsamlı Kimlik Doğrulama: Basic, Digest, LDAP ile entegre erişim denetimi.
Sistem Gereksinimleri
Desteklenen İşletim Sistemleri
- Ubuntu 20.04, 22.04, 24.04 LTS
- Debian 11, 12
- AlmaLinux 8, 9
- Rocky Linux 8, 9
- RHEL 8, 9
Minimum Donanım Gereksinimleri
- CPU: 1 vCPU
- RAM: 512 MB (üretim için 1 GB+)
- Disk: 10 GB boş alan
İşletim Sistemine Göre Kurulum
🟠 Ubuntu 22.04 Üzerinde Apache Kurulumu
1. Sistemi Güncelleyin
sudo apt update && sudo apt upgrade -y
2. Apache'yi Kurun
sudo apt install apache2 -y
3. Servisi Başlatın ve Aktifleştirin
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl status apache2
4. UFW Güvenlik Duvarını Yapılandırın
sudo ufw allow 'Apache Full'
sudo ufw status
5. Gerekli Modülleri Aktifleştirin
sudo a2enmod rewrite
sudo a2enmod ssl
sudo a2enmod headers
sudo systemctl restart apache2
🔵 AlmaLinux 9 Üzerinde Apache (httpd) Kurulumu
1. Sistemi Güncelleyin
sudo dnf update -y
2. httpd'yi Kurun
sudo dnf install httpd httpd-tools mod_ssl -y
3. Servisi Başlatın ve Aktifleştirin
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl status httpd
4. Firewall Kurallarını Ekleyin
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Virtual Host Yapılandırması
Ubuntu'da Virtual Host
/etc/apache2/sites-available/example.com.conf dosyasını oluşturun:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
<Directory /var/www/example.com/public>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
sudo a2ensite example.com.conf
sudo a2dissite 000-default.conf
sudo apache2ctl configtest
sudo systemctl reload apache2
AlmaLinux'ta Virtual Host
/etc/httpd/conf.d/example.com.conf dosyasını oluşturun:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public
<Directory /var/www/example.com/public>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
sudo apachectl configtest
sudo systemctl reload httpd
mod_rewrite ile .htaccess Yapılandırması
Laravel, WordPress gibi frameworkler için AllowOverride All ayarı aktif olmalıdır. Örnek .htaccess:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
Apache ile PHP-FPM Kullanımı (Event MPM)
sudo a2dismod php8.3
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.3-fpm
sudo systemctl restart apache2
Sık Karşılaşılan Sorunlar
- 403 Forbidden:
AllowOverride AllveRequire all granteddirektiflerini kontrol edin. - mod_rewrite çalışmıyor:
sudo a2enmod rewriteve DirectoryOptions'daAllowOverride Allolduğunu doğrulayın. - Port 80 zaten kullanımda:
ss -tlnp | grep :80ile çakışan servisi bulun. - SELinux engeli (AlmaLinux):
sudo chcon -Rt httpd_sys_content_t /var/www/example.comkomutunu çalıştırın. - apachectl configtest hatası: Sözdizimi hatalarını düzeltin; eksik kapanan tag veya direktif arayın.
İlgili Makaleler
Yorumlar
Henüz yorum yok. İlk yorumu siz yapın!