
Ubuntu Server Üzerinde Apache Web Server Kurulumu
Merhaba sevgili okuyucu.
Apache Web Sunucu sistemleri üzerinde ilk yazımı “Linux üzerinde ilk kurulumu nasıl yapabiliriz?” konusu ile ,diğer yazılarımda da kaynak olarak kullanmak üzere başlamak istedim.
Ben kurulumu kullanım yaygınlığı açısından Ubuntu Server üzerinde yapıyor olacağım.
Öncelikle sistemim şu şekilde;
ccorbaci@websrv1:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy
ip addr
komutu ile IP adresimizi öğrenelim;
ccorbaci@websrv1:~$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:79:8c:eb brd ff:ff:ff:ff:ff:ff
inet 192.168.122.111/24 metric 100 brd 192.168.122.255 scope global dynamic enp1s0
valid_lft 2151sec preferred_lft 2151sec
inet6 fe80::5054:ff:fe79:8ceb/64 scope link
valid_lft forever preferred_lft forever
Bu adımdan sonra kurulumları yapmak için root kullanıcınıza geçmek isteyebilirsiniz. Bunu aşağıdaki şekilde yapabilirsiniz :
ccorbaci@websrv1:~$ sudo su -
[sudo] password for ccorbaci:
root@websrv1:~#
Her kurulum yazısında gelenek olduğu üzere 🙂 eğer var ise update lerimizi alalım.
root@websrv1:~# apt update
Hit:1 <http://tr.archive.ubuntu.com/ubuntu> jammy InRelease
Hit:2 <http://tr.archive.ubuntu.com/ubuntu> jammy-updates InRelease
Hit:3 <http://tr.archive.ubuntu.com/ubuntu> jammy-backports InRelease
Hit:4 <http://tr.archive.ubuntu.com/ubuntu> jammy-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
root@websrv1:~#
artık kurulumu yapabiliriz. Ben alışkanlık olarak apt paket listesinde neler var önce ona bakıyorum. Eğer siz de bakmak isterseniz:
root@websrv1:~# apt list apache2 -a
Listing... Done
apache2/jammy-updates,jammy-security 2.4.52-1ubuntu4.7 amd64
apache2/jammy 2.4.52-1ubuntu4 amd64
ve ilgili paketleri kuralım:
root@websrv1:~# apt install apache2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
apache2-bin apache2-data apache2-utils bzip2 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.3-0 mailcap mime-support
ssl-cert
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser bzip2-doc
The following NEW packages will be installed:
apache2 apache2-bin apache2-data apache2-utils bzip2 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.3-0 mailcap
mime-support ssl-cert
0 upgraded, 13 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,139 kB of archives.
After this operation, 8,518 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Y
diyerek kuruluma devam ediyorum.
Kurulum sonunda bir hata yok ve ilgili servisleri restart ettiğini de bize aşağıdaki şekilde belirtiyor.
Running kernel seems to be up-to-date.
Restarting services...
Service restarts being deferred:
/etc/needrestart/restart.d/dbus.service
systemctl restart networkd-dispatcher.service
systemctl restart systemd-logind.service
systemctl restart unattended-upgrades.service
systemctl restart user@1000.service
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
Kurulum aslında tamamlandı.
Kurulum sonrası apache sistemimize bir servis olarak eklendi. Eğer bir servisi kontrol etmek için adını bulamassanız şu şekilde aratabilirsiniz.
root@websrv1:~# systemctl | grep apache2
apache2.service loaded active running The Apache HTTP Server
root@websrv1:~#
servisin adı apache2.service imiş. Şimdi durumuna bakalım
root@websrv1:~# systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-02-20 21:08:27 UTC; 6min ago
Docs: <https://httpd.apache.org/docs/2.4/>
Main PID: 16711 (apache2)
Tasks: 55 (limit: 2220)
Memory: 5.0M
CPU: 51ms
CGroup: /system.slice/apache2.service
├─16711 /usr/sbin/apache2 -k start
├─16713 /usr/sbin/apache2 -k start
└─16714 /usr/sbin/apache2 -k start
Feb 20 21:08:27 websrv1 systemd[1]: Starting The Apache HTTP Server...
Feb 20 21:08:27 websrv1 apachectl[16710]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.>
Feb 20 21:08:27 websrv1 systemd[1]: Started The Apache HTTP Server.
lines 1-16/16 (END)
Evet gördüğünüz gibi başarılı bir şekilde çalışıyor. Bazı servisler sistem yeniden başladığında yeniden başlamaz. Bunu da şu şekilde kontrol edebilirsiniz;
root@websrv1:~# systemctl is-enabled apache2.service
enabled
root@websrv1:~#
enabled apache nin sistem yeniden başlatma durumunda da aktif olarak başlatılacağını bize bildiriyor.
Şimdi bu şekilde web browserımızdan deneyebiliriz. Öğrendiğimiz IP adresini web browser kısmına yazdığınızda bu sayfa karşınızda ise tebrikler, artık bir web sunucunuz var.

Kurulum Sonrası Konfigurasyon
/var/www
dosyası, Linux sistemlerde web sunucusu tarafından barındırılan web sitelerinin varsayılan konumudur. Bu dizin, Apache, Nginx veya Lighttpd gibi popüler web sunucuları tarafından web siteleri için dosyaları depolamak için kullanılır.
Şimdi bir üst dizin olarak web sitemizin klasörünü oluştralım.
root@websrv1:~# mkdir -p /var/www/cuneytcorbacicom
root@websrv1:~# ls -l /var/www/
total 8
drwxr-xr-x 2 root root 4096 Feb 20 21:35 cuneytcorbacicom
drwxr-xr-x 2 root root 4096 Feb 20 21:08 html
Bu dizin üzerinde sahiplikleri değiştirmemiz gerekmekte.
root@websrv1:/var/www# chown -R $USER:$USER /var/www/cuneytcorbacicom/
root@websrv1:/var/www# ll
total 16
drwxr-xr-x 4 root root 4096 Feb 20 21:35 ./
drwxr-xr-x 14 root root 4096 Feb 20 21:08 ../
drwxr-xr-x 2 root root 4096 Feb 20 21:35 cuneytcorbacicom/
drwxr-xr-x 2 root root 4096 Feb 20 21:08 html/
root@websrv1:/var/www#
Erişim artık root kullanıcısında. Burada $USER ifadesi o anda oturum açmış kullanıcı demektir.
Erişimleri de ayarlayalım;
root@websrv1:/var/www# chmod -R 755 /var/www/cuneytcorbacicom/
root@websrv1:/var/www# ll
total 16
drwxr-xr-x 4 root root 4096 Feb 20 21:35 ./
drwxr-xr-x 14 root root 4096 Feb 20 21:08 ../
drwxr-xr-x 2 root root 4096 Feb 20 21:35 cuneytcorbacicom/
drwxr-xr-x 2 root root 4096 Feb 20 21:08 html/
root@websrv1:/var/www#
-R ifadesi recursive olarak alt klasörler ile beraber bu kuralları uygulayacağımız anlamına gelmekte. 755 ise klasör sahibinin rwx(read,write,execute), grubunun rx,ve diğer kullanıcıların sadece x yetkisi olaceğını bildirir.
Şimdi dizinimiz hazır. Dizinin içinde artık bir index sayfası oluşturabiliriz. Sadece terminal ile sunucuya bağlı olacağınızı varsayarak nano ile dosyamızı oluşturalım:
root@websrv1:~# nano /var/www/cuneytcorbacicom/index.html
Örnek bir index sayfasını yazıyorum;

Daha önce nano editörünü kullanmadıysanız sol altta göreceğiniz gibi CTRL+X ve sonrasında kaydetmek için Y diyerek index dosyamızı oluşturuyoruz.
Şimdi bu klasör ve sayfa üzerinden ana sayfa ayarlarımızı yapmamız gerekiyor. Varsayılan olarak kullanılan dosya /var/www/html/index.html şeklindedir.
Bu varsayılan ayarı değiştirmek için ilgili yapılandırma dosyası /etc/apache2/sites-available/ dizini altındadır.
root@websrv1:~# cd /etc/apache2/sites-available/
root@websrv1:/etc/apache2/sites-available# ll
total 20
drwxr-xr-x 2 root root 4096 Feb 20 21:08 ./
drwxr-xr-x 8 root root 4096 Feb 20 21:08 ../
-rw-r--r-- 1 root root 1332 May 3 2023 000-default.conf
-rw-r--r-- 1 root root 6338 May 3 2023 default-ssl.conf
root@websrv1:/etc/apache2/sites-available#
Burada ister 000-default.conf dosyasını edit edebilirsiniz ya da kendi dosyanızı da oluşturabilirsiniz.
bunun için yine nano ise cuneytcorbacicom.conf dosyasını oluşturarak editliyorum.
root@websrv1:# nano /etc/apache2/sites-available/cuneytcorbacicom.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName cuneytcorbaci.com
ServerAlias www.cuneytcorbaci.com
DocumentRoot /var/www/cuneytcorbacicom
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<VirtualHost>
Bu şekilde editledikten sonra yine kaydedip çıkıyorum.
Bu yapılandırma dosyasını varsayılan olarak ayarlayalım. Yine aynı klasör de enable durumda olan
000-default.conf dosyası yerine cuneytcorbacicom.conf dosyasının enable olması gerek.
root@websrv1:~# a2ensite cuneytcorbacicom.conf
Enabling site cuneytcorbacicom.
To activate the new configuration, you need to run:
systemctl reload apache2
root@websrv1:~#
a2ensite
komutu, Apache web sunucusunda sanal ana bilgisayarları (virtual host) etkinleştirmek için kullanılır. Sanal ana bilgisayarlar, tek bir IP adresinde birden fazla web sitesini barındırmanıza olanak tanır. Biz konfigurasyon dosyasında aslında bir VirtualHost tanımladık ve a2ensite komutu ile bu virtualhostu devreye aldık.
aşağıdaki şekilde a2dissite
komutu ile 000-default.conf ‘u devre dışı bırakıyorum
root@websrv1:~# a2dissite 000-default.conf
Site 000-default disabled.
To activate the new configuration, you need to run:
systemctl reload apache2
root@websrv1:~#
config durumunu test etmek için ise apache2ctl configtest komutunu kullanıyorum
root@websrv1:/etc/apache2/sites-available# apache2ctl configtest
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Syntax OK
root@websrv1:/etc/apache2/sites-available#
Herhangi bir sorun yok, harika.Şimdi servisimizi yeniden başlatmamız gerekli. reload kullanarak ayar değişikliklerini uygulayarak servisi yeniden başlatıyorum
root@websrv1:~# systemctl reload apache2
root@websrv1:~# systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-02-20 21:08:27 UTC; 1h 27min ago
Docs: <https://httpd.apache.org/docs/2.4/>
Process: 17335 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
Main PID: 16711 (apache2)
Tasks: 55 (limit: 2220)
Memory: 5.0M
CPU: 574ms
CGroup: /system.slice/apache2.service
├─16711 /usr/sbin/apache2 -k start
├─17339 /usr/sbin/apache2 -k start
└─17340 /usr/sbin/apache2 -k start
Feb 20 21:08:27 websrv1 systemd[1]: Starting The Apache HTTP Server...
Feb 20 21:08:27 websrv1 apachectl[16710]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'Serve>
Feb 20 21:08:27 websrv1 systemd[1]: Started The Apache HTTP Server.
Feb 20 22:35:24 websrv1 systemd[1]: Reloading The Apache HTTP Server...
Feb 20 22:35:24 websrv1 apachectl[17338]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'Serve>
Feb 20 22:35:24 websrv1 systemd[1]: Reloaded The Apache HTTP Server.
lines 1-20/20 (END)
Evet browserdan kontrol edelim.

Harika. Artık basit düzeyde de olsa tam anlamıyla çalışır durumda olan bir web sunucunuz var.