CentOS 7 Üzerine LEMP Kurulumu

Linux sistem üstünde bir internet uygulaması yayınlayacaksanız mutlaka tavsiyem Nginx’tir. Nginx olabildiğince süratli kolay ve stabil bir internet sunucusudur. Çok fazla esnek konfigürasyon girişlerine izin veriyor. Performas ayarlarından emniyet yapılandırmalarına kadar çoğu ayarı yapabiliyorsunuz. Ayrıca SPDY ve HTTP2 desteğide mevcut.

Bu kurulumu CentOS 7 üstüne kuracagız base sunucu kurulumu yapmış olup internete bağlı olduğunuzu varsayıyorum.

1. İlk öce sistem güncellemesi

İlk ilkin sunucunuzu “Vmware olsun veya cloud VPS olsun” güncelliyoruz :

# yum update

2. Veritabanı Kurulumu MariaDB(MySQL)

CentOS 7 (RHEL) Mysql kurulumu yapıyoruz.

# yum -y install mariadb mariadb-server

Kurulumdan derhal sonrasında konfigurasyon için “/etc/my.cnf.d/server.cnf” dosyasında “bind-address” kısmını aşağıdaki gibi düzenliyoruz veya denetim ediyoruz :

# nano /etc/my.cnf.d/server.cnf

[mysqld]
bind-address = 127.0.0.1

Şimdi Mysql i başlatıp otomatik açılması için enable ediyoruz :

# systemctl start mariadb
# systemctl enable mariadb

Güvenlik ayarları için scriptimizi çalıştırıyoruz mysql_secure_installation :

# mysql_secure_installation

Enter current password for root (enter for none): ENTER
Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

3. Nginx Kurulumu

Centos EPEL kütüphanesinde default olarak Nginx bulunmaz bu nedenden dolayı eklemeniz gerekiyor :

# yum install epel-release

Sonrasında Nginx kurulunumu başlatıyoruz :

# yum -y install nginx

Kurulum tamamlandıktan sonrasında Nginx i start edip otomatik açılması için enable ediyoruz :

# systemctl start nginx
# systemctl enable nginx

Nginx kurulumumuzun çalışıp çalışmadığını denetim ediyoruz:

# systemctl status nginx

The output of the command above should be similar to this:

● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running)
 Main PID: 10092 (nginx)
   CGroup: /system.slice/nginx.service
           ├─10092 nginx: master process /usr/sbin/nginx
           ├─10093 nginx: worker process
           └─10094 nginx: worker process

Nginx’in çalışıp çalışmadığını internet broowser’ınızın adres satırına http://ip_adresiniz i yazarak ta denetim edebilirsiniz.

4. PHP7.1-FPM Kurulumu

Sıra geldi PHP7.1-FPM kurulumuna. Öncelikle gene CentOS repository’sine bir ilave daha yapıyoruz zira default olarak PHP-7.1 CentOS repository’sinde yok.

# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm && rpm -Uvh remi-release-7.rpm

PHP7.1-FPM Kurulumu için aşağıdaki komutu girip kurulumu başlatıyoruz :

# yum --enablerepo=remi-safe -y install php71-php-fpm

PHP7.1-FPM kuruldu, açılışta başlaması içi enable edip start ediyoruz :

# systemctl start php71-php-fpm
# systemctl enable php71-php-fpm

PHP7.1-FPM çalışıp çalışmadığını denetim ediyoruz :

# systemctl status php71-php-fpm

The output of the command above should be similar to this:

● php71-php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php71-php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running)
 Main PID: 10792 (php-fpm)
   Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
   CGroup: /system.slice/php71-php-fpm.service
           ├─10792 php-fpm: master process (/etc/opt/remi/php71/php-fpm.conf)
           ├─10793 php-fpm: pool www
           ├─10794 php-fpm: pool www
           ├─10795 php-fpm: pool www
           ├─10796 php-fpm: pool www
           └─10797 php-fpm: pool www

Not : PHP-7.1 konfigürasyon dosyaları bu klasördedir. “/etc/opt/remi/php71”

PHP7.1-FPM ayarlarını denetim ediyoruz :

# nano /etc/opt/remi/php71/php-fpm.d/www.conf
===========================================================
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
;                            a specific port;
;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses
;                            (IPv6 and IPv4-mapped) on a specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /run/php/php7.1-fpm.sock

===========================================================

Dosyayı kaydedip PHP7.1-FPM servisini tekrar başlatıyoruz :

# systemctl restart php71-php-fpm

5. Nginx Konfigürasyonu

Son olarak nginx ayarlarımızı internet sitemizin adına göre düzenliyoruz.

Dosyalarımızın bulunacağı klasörü oluturuyoruz :

# mkdir -p /var/www/teknolojik-blog.com

Nginx Server bloğu ve PHP-7.1 için ayarlarımızı giriyoruz :

# nano /etc/nginx/conf.d/teknolojik-blog.com.conf

server {
        listen 80;
        
        root /var/www/teknolojik-blog.com;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name teknolojik-blog.com;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass the PHP scripts to FastCGI sunucu using the /run/php/php7.1-fpm.sock socket
        #
        location ~ \.php$ {
                include fastcgi.conf;
                fastcgi_pass unix:/run/php/php7.1-fpm.sock;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny all;
        }
}

Basitçe ayarlarımız bitti dosyamızı kaydedip test ediyoruz :

# nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Eğer hata alırsanız “/var/www/teknolojik-blog.com”  klasörünün yetkilerini düzenleyin :

# chown -R nginx:nginx /var/www/teknolojik-blog.com
# systemctl restart nginx

 

Sever bloğunuz PHP 7 ile çalışmaya başladı.

Test etmek için root klasörünüze phpinfo.php isminde bir dosya oluturup içerisine :

<?php phpinfo(); ?>

satırını ilave edip kaydedin ve browser’a :

http://ip-addres/phpinfo.php

yazın sunucunuzun PHP detayları ekrana gelecektir.

Tabi güvenilir bir sunucu yapısı için çoğu ayar yapmak gerekiyor burada kolay bir kurulum yapılmıştır.

Aziz Ozdemiroglu
Teknolojik-Blog.Com