Adım Adım WordPress Sunucu Kurulumu ve Yapılandırması

Bu yol haritası, Ubuntu 22.04 üzerinde OpenLiteSpeed, PHP 8.1 ve MariaDB kullanarak çoklu WordPress sitelerin kurulumu, SSL yapılandırması, performans optimizasyonu ve güvenlik önlemlerini adım adım göstermektedir. Her adımda yapılan işlemler ve kısa açıklamalar sayesinde sunucu kurulum sürecini kolayca takip edebilirsiniz.
Not: Bu rehber Emirhan Öztürk tarafından hazırlanmıştır.

Ubuntu 22.04 & OpenLiteSpeed & MariaDB & PHP 8.1 & WordPress

1. Sunucuyu Güncelle

OpenLiteSpeed ve PHP 8.1 Kurulumu

Ubuntu 22.04 sunucusunu güncelledik, wget, curl ve unzip kurduk. Ardından OpenLiteSpeed ve gerekli PHP 8.1 modüllerini yükledik.

### 1.1- Sistemi Güncelle
sudo apt update && sudo apt upgrade -y
sudo apt install wget curl unzip -y

### 1.2- OpenLiteSpeed kur
sudo wget -O - https://repo.litespeed.sh | sudo bash
sudo apt update
sudo apt install -y openlitespeed
sudo apt-get install -y lsphp81 lsphp81-common lsphp81-mysql lsphp81-curl lsphp81-imap lsphp81-opcache lsphp81-imagick lsphp81-memcached lsphp81-redis

### 1.3- OpenLiteSpeed Panel Şifresi (manuel gireceksin)
sudo /usr/local/lsws/admin/misc/admpass.sh

### 1.4- MariaDB Kur
sudo apt install mariadb-server -y
sudo mysql_secure_installation

2. MariaDB Kurulumu

Veritabanı Oluşturma ve Kullanıcı Tanımlama

MariaDB kurulumu gerçekleştirilip güvenlik ayarları yapıldı. orneksite.com sitesi için kullanıcı ve veritabanı oluşturuldu.

### 2.1- Veritabanı Oluştur 
sudo mysql

CREATE DATABASE db_adi;
CREATE USER 'admin_kullanici_adi'@'localhost' IDENTIFIED BY 'admin_sifresi';
GRANT ALL PRIVILEGES ON db_adi.* TO 'admin_kullanici_adi'@'localhost';
FLUSH PRIVILEGES;
EXIT;

### 2.2- WordPress İndir
sudo mkdir -p /usr/local/lsws/vhosts/orneksite.com/www
cd /usr/local/lsws/vhosts/orneksite.com/www
wget https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz --strip-components=1
rm latest.tar.gz

### 2.3- WordPress .htaccess Oluştur (2. Site)
cat << 'EOF' | sudo tee /usr/local/lsws/vhosts/orneksite.com/www/.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
EOF

3. WordPress Kurulumu

wp-config ve .htaccess Yapılandırması

WordPress son sürümü indirildi, wp-config.php ve .htaccess yapılandırıldı. OpenLiteSpeed panelinde sanal host mapping yapıldı.

### 3.1- wp-config.php Hazırla
cp /usr/local/lsws/vhosts/orneksite.com/www/wp-config-sample.php /usr/local/lsws/vhosts/orneksite.com/www/wp-config.php
sudo sed -i "s/database_name_here/db_adi/" /usr/local/lsws/vhosts/orneksite.com/www/wp-config.php
sudo sed -i "s/username_here/admin_kullanici_adi/" /usr/local/lsws/vhosts/orneksite.com/www/wp-config.php
sudo sed -i "s/password_here/admin_sifresi/" /usr/local/lsws/vhosts/orneksite.com/www/wp-config.php
sudo sed -i "/DB_HOST/a define('WP_MEMORY_LIMIT', '512M');\ndefine('WP_MAX_MEMORY_LIMIT', '1024M');" /usr/local/lsws/vhosts/orneksite.com/www/wp-config.php
sudo sed -i "s/^upload_max_filesize\s*=.*/upload_max_filesize = 512M/" /usr/local/lsws/lsphp81/etc/php/8.1/litespeed/php.ini
sudo sed -i "s/^post_max_size\s*=.*/post_max_size = 512M/" /usr/local/lsws/lsphp81/etc/php/8.1/litespeed/php.ini
sudo sed -i "s/^max_execution_time\s*=.*/max_execution_time = 300/" /usr/local/lsws/lsphp81/etc/php/8.1/litespeed/php.ini
sudo sed -i "s/^max_input_time\s*=.*/max_input_time = 300/" /usr/local/lsws/lsphp81/etc/php/8.1/litespeed/php.ini
sudo sed -i "s/^memory_limit\s*=.*/memory_limit = 512M/" /usr/local/lsws/lsphp81/etc/php/8.1/litespeed/php.ini

### 3.2- OpenLiteSpeed Panelde Virtual Host Mapping
echo "İkinci site kurulumu tamamlandı. Panelde yapmanız gerekenler:
1. Listeners → Port 80 ayarla
2. Basic > Virtual Host Name → orneksite_com (Yeni Oluştur)
3. Basic > Virtual Host Root → /usr/local/lsws/vhosts/orneksite.com
4. Basic > Config File → /usr/local/lsws/conf/vhosts/orneksite.com/vhconf.conf
5. Basic > Config File → Enable Scripts/ExtApps * Yes
6. Basic > Config File → Restrained * No
7. Vİrtual Host List'ten Example'ı silmeyin, sadece mapping yapın
8. General > Document Root: $VH_ROOT/www/
9. General > Document Name: orneksite.com
10. Rewrite: Enable + Auto Load .htaccess
11. Virtual Host Mapping (Listener Default):
- Virtual Host: orneksite_com
- Domains: orneksite.com
12. Server Configuration > External App
- lsphp olan kısmı lsphp81 ile değiştir
- uds://tmp/lshttpd/lsphp.sock olan kısmı uds://tmp/lshttpd/lsphp81.sock ile değiştir
- sphp73/bin/lsphp olan kısmı $SERVER_ROOT/lsphp81/bin/lsphp ile değiştir
13. Virtual Host Mapping'e ekle:
- Domains: orneksite.com, SUNUCU_IP
14. Ardından http://orneksite.com üzerinden WordPress kurulum ekranına ulaşabilirsin."

### 3.3- WordPress Dizini Hazırla
sudo chown -R nobody:nogroup /usr/local/lsws/vhosts/orneksite.com/www
sudo find /usr/local/lsws/vhosts/orneksite.com/www -type d -exec chmod 755 {} \;
sudo find /usr/local/lsws/vhosts/orneksite.com/www -type f -exec chmod 644 {} \;

4. SSL Kurulumu

HTTPS Yönlendirmesi ve Sertifika Ayarları

Acme.sh ile SSL sertifikası kuruldu, OpenLiteSpeed üzerinde yapılandırıldı ve HTTP → HTTPS yönlendirmesi aktif edildi.

### 4.1- WordPress .htaccess e SSL ekle
sudo nano /usr/local/lsws/vhosts/orneksite.com/www/.htaccess
# BEGIN HTTPS REDIRECT
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# END HTTPS REDIRECT

### 4.2- SSL KUR
sudo apt update
sudo apt install socat -y
curl https://get.acme.sh | sh
source ~/.bashrc

~/.acme.sh/acme.sh --register-account -m mailadresiniz@gmail.com

~/.acme.sh/acme.sh --issue -d orneksite.com -w /usr/local/lsws/vhosts/orneksite.com/www

~/.acme.sh/acme.sh --install-cert -d orneksite.com \
--key-file /root/.acme.sh/orneksite.com_ecc/orneksite.com.key \
--fullchain-file /root/.acme.sh/orneksite.com_ecc/orneksite.com.cer \
--reloadcmd "service lsws restart"

### 4.3- SSL dizinlerini değişken olarak tanımla
echo"
SSL_KEY="/root/.acme.sh/orneksite.com_ecc/orneksite.com.key"
Chained Certificate - Yes
SSL_CERT="/root/.acme.sh/orneksite.com_ecc/orneksite.com.cer"
SSL_PATH="/root/.acme.sh/orneksite.com_ecc/ca.cer"
"

### 4.4- Virtual host config dosyası
echo"
VH_CONF="/usr/local/lsws/conf/vhosts/orneksite.com/vhconf.conf"
"
### 4.5- SSL ayarlarını config dosyasına ekle
sudo tee -a $VH_CONF > /dev/null <<EOF

# SSL Settings
keyFile $SSL_KEY
certFile $SSL_CERT
cacertFile $SSL_CA
sslProtocol ALL
enable 1
EOF

sudo service lsws restart

### 4.6- Listener Ekle
echo "Listener Name → HTTPS
IP Address → ANY
Port → 443
Secure → Yes
Virtual Host Mapping → orneksite_com → orneksite.com"

### 4.7- Firewall

sudo ufw allow 7080/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw status

5. Redis Kurulumu

LiteSpeed Cache ile Performans Optimizasyonu

Redis sunucu kurulumu ve PHP ile entegrasyonu yapıldı. LiteSpeed Cache üzerinden nesne önbelleği ayarlandı ve test edildi.

### 5.1- Paketleri güncelle ve Redis kur
sudo apt update
sudo apt install redis-server php-redis -y

### 5.2- Redis servisini başlat ve otomatik açılmasını sağla
sudo systemctl enable redis-server
sudo systemctl start redis-server
sudo systemctl status redis-server

### 5.3- Redis bağlantısını test et
redis-cli ping

### 5.4- PHP Redis modülünü kontrol et
php -m | grep redis
# Eğer "redis" görünüyorsa PHP ile entegre

### 5.5- LiteSpeed Cache için Redis bağlantısını ayarla
# WordPress admin panel > LiteSpeed Cache > Cache > Object
# - Nesne Önbelleği: AÇIK
# - Yöntem: Redis
# - Sunucu: 127.0.0.1
# - Port: 6379
# - Password: boş bırak (Redis için varsayılan şifre yoksa)
# - Database ID: 0

### 5.6- Test et
# WordPress admin panel > LiteSpeed Cache > Cache > Object > Bağlantı Testi
# "Başarılı" görmelisin

### 5.7- Redis’i optimize et (isteğe bağlı, yüksek performans)
sudo sed -i "s/^supervised no/supervised systemd/" /etc/redis/redis.conf
sudo systemctl restart redis-server

6. Performans Optimizasyonu

OPcache, MariaDB ve HTTP/3 Ayarları Optimizasyonu

PHP OPcache optimize edildi, MariaDB performans ayarları eklendi, wp-config.php güvenliği artırıldı, OpenLiteSpeed HTTP/3 etkinleştirildi.

### 6.1- OPcache Ayarlarını Optimize Et
PHP_INI="/usr/local/lsws/lsphp81/etc/php/8.1/litespeed/php.ini"
echo ">>> OPcache ayarları optimize ediliyor..."
sudo sed -i '/opcache.enable/d' $PHP_INI
sudo tee -a $PHP_INI > /dev/null <<'EOF'

; ### CUSTOM OPCACHE SETTINGS ###
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.validate_timestamps=0
opcache.revalidate_freq=0
opcache.save_comments=1
EOF

### 6.2- Redis maxmemory-policy Ayarı
REDIS_CONF="/etc/redis/redis.conf"
echo ">>> Redis maxmemory-policy ayarlanıyor..."
sudo sed -i '/^maxmemory-policy/d' $REDIS_CONF
echo "maxmemory-policy allkeys-lru" | sudo tee -a $REDIS_CONF > /dev/null

### 6.3- MariaDB Performans Ayarları
MARIADB_CONF="/etc/mysql/mariadb.conf.d/50-server.cnf"
echo ">>> MariaDB performans ayarları ekleniyor..."
sudo tee -a $MARIADB_CONF > /dev/null <<'EOF'

# ### CUSTOM MARIADB PERFORMANCE TUNING ###
innodb_buffer_pool_size=2G
innodb_log_file_size=512M
innodb_flush_log_at_trx_commit=2
query_cache_size=0
query_cache_type=0
EOF

### 6.4- wp-config.php Güvenliği
WP_CONFIG="/usr/local/lsws/vhosts/orneksite.com/www/wp-config.php"
echo ">>> wp-config.php güvenlik ayarları yapılıyor..."
sudo chmod 600 $WP_CONFIG
sudo chown nobody:nogroup $WP_CONFIG

### 6.5- OpenLiteSpeed HTTP/3 (QUIC) Etkinleştirme
echo ">>> OpenLiteSpeed için QUIC etkinleştiriliyor..."
LITESPEED_CONF="/usr/local/lsws/conf/httpd_config.conf"
sudo sed -i '/quicEnable/d' $LITESPEED_CONF
echo "quicEnable 1" | sudo tee -a $LITESPEED_CONF > /dev/null

### 6.6- Servisleri Yeniden Başlat
echo ">>> Servisler yeniden başlatılıyor..."
sudo systemctl restart redis-server
sudo systemctl restart mariadb
sudo service lsws restart

echo ">>> ✅ Optimizasyon tamamlandı! Artık site daha hızlı ve güvenli çalışıyor."

7. Güvenlik Katmanı

Fail2Ban ile SSH ve WordPress Koruması

Fail2Ban kuruldu, SSH ve WordPress login saldırılarına karşı koruma aktif edildi. WordPress debug logları açıldı ve güvenlik testi yapıldı.

### 7.1- Fail2Ban Ana Konfigürasyon
echo ">>> Fail2Ban kurulumu başlıyor..."
sudo apt update
sudo apt install fail2ban -y

JAIL_LOCAL="/etc/fail2ban/jail.local"

sudo tee $JAIL_LOCAL > /dev/null <<'EOF'
[DEFAULT]
bantime = 1h
findtime = 10m
maxretry = 3
backend = systemd
ignoreip = 127.0.0.1/8

[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3

[wordpress]
enabled = true
port = http,https
filter = wordpress
logpath = /usr/local/lsws/vhosts/orneksite.com/www/wp-content/debug.log
maxretry = 5
EOF

### 7.2- WordPress için Fail2Ban Filter Oluştur
FILTER_WP="/etc/fail2ban/filter.d/wordpress.conf"
sudo tee $FILTER_WP > /dev/null <<'EOF'
[Definition]
failregex = ^.*WordPress authentication failed.*$
ignoreregex =
EOF

### 7.3- WordPress’te debug log aktif et (giriş hataları için)
WP_CONFIG="/usr/local/lsws/vhosts/orneksite.com/www/wp-config.php"
if ! grep -q "WP_DEBUG_LOG" $WP_CONFIG; then
echo "define('WP_DEBUG', true);" | sudo tee -a $WP_CONFIG > /dev/null
echo "define('WP_DEBUG_LOG', true);" | sudo tee -a $WP_CONFIG > /dev/null
echo "define('WP_DEBUG_DISPLAY', false);" | sudo tee -a $WP_CONFIG > /dev/null
fi

### 7.4- Fail2Ban Başlat
sudo systemctl enable fail2ban
sudo systemctl restart fail2ban

echo ">>> ✅ Fail2Ban kurulumu tamamlandı. SSH ve WordPress brute-force saldırılarına karşı koruma aktif."
echo ">>> Log dosyalarını izlemek için: sudo fail2ban-client status wordpress"

### 7.5- SSH Port Değiştirme
sudo ufw allow 3408/tcp
sudo ufw reload

sudo nano /etc/ssh/sshd_config
echo'Port başındaki # yi kaldır 3408 yaz - Artık ssh bağlantısında Port 3408 ile giriş yapabilirsin'

sudo systemctl restart ssh

ssh -p 3408 root@72.60.130.58