Alpine Linux ile Web Server Kurulumu

Alpine Web Sunucusu Kurulumu

Alpine Linux, hafifliği ve hızıyla bilinen bir dağıtımdır. Bu rehberde, Alpine Linux üzerinde tam işlevsel bir web sunucusu (Nginx, PHP, MariaDB ve PhpMyAdmin) kurulumunu adım adım gerçekleştireceğiz.


Sistem Özeti

Kernel Bilgisi:

bash
Linux localhost 6.12.16-0-lts #1-Alpine SMP PREEMPT_DYNAMIC 2025-02-21 15:23:09 x86_64 Linux

İşletim Sistemi:

bash
PRETTY_NAME=“Alpine Linux v3.21”

CPU Bilgileri:

  • CPU(s): 4
  • Model name: Intel(R) Atom(TM) CPU C2558 @ 2.41GHz
  • Thread(s) per core: 1
  • Core(s) per socket: 4

Bellek Bilgileri:

bash
Mem: 1.9G total, 361.7M used, 1.0G free, 288.0K shared, 572.4M buff/cache, 1.4G available

Disk Bilgileri:

bash
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda
├─sda1 ext4        88d5ddf0-05d3-45a3-87b7-30a6e9aced89    220M    12% /boot
├─sda2 swap        082aabaa-9788-451a-9aa3-b0bf12049aa3                [SWAP]
└─sda3 ext4        24ea414a-1599-4f88-a27b-9af6a599b0b2  202.2G     1% /

İçindekiler

  1. Temel Sistem Kurulumu
  2. Web Sunucusu (Nginx) Kurulumu
  3. PHP Kurulumu
  4. MariaDB (MySQL) Kurulumu
  5. PhpMyAdmin Kurulumu
  6. Virtual Host Yapılandırması

1. Temel Sistem Kurulumu

Hoş Geldin Mesajı Özelleştirme

Hoş geldin mesajını özelleştirmek için /etc/motd dosyasını düzenleyin:

bash
cat > /etc/motd << ‘EOF’
[1;34m
__          __  _     ____                          
\ \        / / | |   / ___|                         
 \ \  /\  / /__| |__| (___   ___ _ ____   _____ _ __ 
  \ \/  \/ / _ \ '_ \\___ \ / _ \ '__\ \ / / _ \ '__|
   \  /\  /  __/ |_) |___) |  __/ |   \ V /  __/ |   
    \/  \/ \___|_.__/|____/ \___|_|    \_/ \___|_|   
[1;32m
    ===========================================
             Alpine Linux Web Server
    ===========================================
[1;36m
     - Apache/Nginx Kralı
     - Load Balancing Ustası
     - SSL/TLS Şampiyonu
     - Performance Muhafızı
[1;33m
    Sistem Yöneticisi: onder
[0m
EOF

2. Web Sunucusu (Nginx) Kurulumu

Nginx Kurulumu

bash
apk add nginx
rc-update add nginx default
service nginx start

Temel Nginx Yapılandırması

Test sayfası oluşturun:

bash
cat > /var/www/localhost/htdocs/index.html << ‘EOF’
<!DOCTYPE html>
<html>
<head>
   <title>Web Server Kralı</title>
</head>
<body>
   <h1>Hoş Geldiniz!</h1>
   <p>Alpine Linux Web Server başarıyla kuruldu.</p>
</body>
</html>
EOF

3. PHP Kurulumu

PHP ve Gerekli Modüllerin Kurulumu

bash
apk add php82 php82-fpm php82-mysqli php82-json php82-curl php82-dom php82-xml php82-iconv php82-session php82-mbstring
rc-update add php-fpm82 default
service php-fpm82 start

PHP Test Sayfası

bash
cat > /var/www/localhost/htdocs/test.php << ‘EOF’
<?php
phpinfo();
?>
EOF

4. MariaDB (MySQL) Kurulumu

bash
apk add mariadb mariadb-client
rc-update add mariadb default
service mariadb setup
service mariadb start
mysql_secure_installation

5. PhpMyAdmin Kurulumu

Paket Kurulumu ve Yapılandırma

bash
apk add phpmyadmin
mkdir -p /var/www/localhost/htdocs/phpmyadmin
cp -r /usr/share/webapps/phpmyadmin /var/www/localhost/htdocs/
chown -R nginx:nginx /var/www/localhost/htdocs/phpmyadmin

Nginx PHP-FPM Yapılandırması

bash
cat > /etc/php82/php-fpm.d/www.conf << ‘EOF’
[www]
user = nginx
group = nginx
listen = 127.0.0.1:9000
listen.owner = nginx
listen.group = nginx
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOF

6. Virtual Host Yapılandırması

Virtual Host Dosyası Oluşturma

bash
cat > /etc/nginx/http.d/onder.local.conf << ‘EOF’
server {
   listen 80;
   server_name onder.local;
   root /var/www/onder.local;
   index index.php index.html index.htm;

   location / {
       try_files $uri $uri/ =404;
   }

   location ~ \.php$ {
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
       include        fastcgi_params;
   }
}
EOF

Host Dizini Oluşturma

bash
mkdir -p /var/www/onder.local
chown -R nginx:nginx /var/www/onder.local
chmod 755 /var/www/onder.local

Test Sayfası

bash
cat > /var/www/onder.local/index.html << ‘EOF’
<!DOCTYPE html>
<html>
<head>
   <title>Onder.local</title>
</head>
<body>
   <h1>Onder.local Virtual Host Çalışıyor!</h1>
</body>
</html>
EOF

Hosts Dosyası Yapılandırması

bash
echo “127.0.0.1 onder.local” >> /etc/hosts

Güvenlik Notları

  1. Güncel Paketler: Her zaman güncel paketler kullanın.
  2. Güçlü Şifreler: Güçlü şifreler belirleyin.
  3. Gereksiz Servisler: Gereksiz servisleri devre dışı bırakın.
  4. Yedekleme: Düzenli yedek alın.
  5. SSL/TLS: SSL sertifikası kullanın.

Sonuç

Bu rehberi takip ederek, Alpine Linux üzerinde tam işlevsel bir web sunucusu kurmuş oldunuz. Sunucu şu özelliklere sahip:

  • Nginx web sunucusu
  • PHP 8.2 desteği
  • MariaDB veritabanı
  • PhpMyAdmin yönetim arayüzü
  • Virtual host desteği

Faydalı Komutlar

bash
# Servisleri yeniden başlatma
service nginx restart
service php-fpm82 restart
service mariadb restart

# Log dosyalarını kontrol etme
tail -f /var/log/nginx/error.log
tail -f /var/log/nginx/access.log

# Nginx yapılandırma testi
nginx -t

Sistem Bilgileri Toplama Scripti

bash
#!/bin/bash
# Sistem Bilgileri Toplama Scripti
# Yazar: Önder

# Renk Tanımları
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m'

# Banner Fonksiyonu
print_banner() {
   echo -e "${BLUE}"
   echo "╔════════════════════════════════════════╗"
   echo "║      Sistem Donanım Bilgi Scripti      ║"
   echo "╚════════════════════════════════════════╝"
   echo -e "${NC}"
}

# Gerekli paketleri kontrol et ve kur
check_packages() {
   echo -e "${YELLOW}Gerekli paketler kontrol ediliyor...${NC}"
   
   PACKAGES="pciutils usbutils lshw lm-sensors dmidecode util-linux"
   
   for pkg in $PACKAGES; do
       if ! which $pkg >/dev/null 2>&1; then
           echo -e "${RED}$pkg kuruluyor...${NC}"
           apk add $pkg
       fi
   done
}

# CPU Bilgisi
get_cpu_info() {
   echo -e "\n${GREEN}=== CPU Bilgileri ===${NC}"
   echo -e "${YELLOW}Processor Detayları:${NC}"
   lscpu | grep -E "Model name|CPU\(s\)|Thread|Core|Socket|MHz"
}

# Bellek Bilgisi
get_memory_info() {
   echo -e "\n${GREEN}=== Bellek Bilgileri ===${NC}"
   echo -e "${YELLOW}RAM Kullanımı:${NC}"
   free -h
}

# Disk Bilgisi
get_disk_info() {
   echo -e "\n${GREEN}=== Disk Bilgileri ===${NC}"
   echo -e "${YELLOW}Disk Bölümleri:${NC}"
   lsblk -f
}

# USB Aygıtları
get_usb_info() {
   echo -e "\n${GREEN}=== USB Aygıtları ===${NC}"
   lsusb
}

# PCI Aygıtları
get_pci_info() {
   echo -e "\n${GREEN}=== PCI Aygıtları ===${NC}"
   lspci
}

# Ağ Bilgileri
get_network_info() {
   echo -e "\n${GREEN}=== Ağ Arayüzleri ===${NC}"
   ip addr
}

# Sensör Bilgileri
get_sensor_info() {
   echo -e "\n${GREEN}=== Sistem Sensörleri ===${NC}"
   sensors 2>/dev/null || echo "Sensör bilgisi bulunamadı"
}

# BIOS Bilgisi
get_bios_info() {
   echo -e "\n${GREEN}=== BIOS Bilgileri ===${NC}"
   dmidecode -t bios 2>/dev/null || echo "BIOS bilgisi alınamadı"
}

# Sistem Özeti
get_system_summary() {
   echo -e "\n${GREEN}=== Sistem Özeti ===${NC}"
   echo -e "${YELLOW}Kernel Bilgisi:${NC}"
   uname -a
   echo -e "\n${YELLOW}İşletim Sistemi:${NC}"
   cat /etc/os-release | grep PRETTY_NAME
}

# Ana fonksiyon
main() {
   print_banner
   check_packages
   
   # Tüm bilgileri topla
   get_system_summary
   get_cpu_info
   get_memory_info
   get_disk_info
   get_usb_info
   get_pci_info
   get_network_info
   get_sensor_info
   get_bios_info
   
   echo -e "\n${BLUE}Bilgi toplama işlemi tamamlandı.${NC}"
}

# Scripti çalıştır
main