вторник, 3 марта 2015 г.

Установка NGINX на CentOS 7.0 minimal

* Установка дополнительных Репозиториев

rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

vi /etc/yum.repos.d/nginx.repo
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    gpgcheck=0
    enabled=1

* Установка NGINX, PHP 5.6.6, PHP-FPM

yum --enablerepo=remi,remi-php56 install nginx php-fpm php-common

* Установка модулей PHP 5.6.6


    OPcache (php-opcache) – The Zend OPcache provides faster PHP execution through opcode caching and optimization.
    APCu (php-pecl-apc) – APCu userland caching
    CLI (php-cli) – Command-line interface for PHP
    PEAR (php-pear) – PHP Extension and Application Repository framework
    PDO (php-pdo) – A database access abstraction module for PHP applications
    MySQL (php-mysqlnd) – A module for PHP applications that use MySQL databases
    PostgreSQL (php-pgsql) – A PostgreSQL database module for PHP
    MongoDB (php-pecl-mongo) – PHP MongoDB database driver
    SQLite (php-pecl-sqlite) – Extension for the SQLite Embeddable SQL Database Engine
    Memcache (php-pecl-memcache) – Extension to work with the Memcached caching daemon
    Memcached (php-pecl-memcached) – Extension to work with the Memcached caching daemon
    GD (php-gd) – A module for PHP applications for using the gd graphics library
    XML (php-xml) – A module for PHP applications which use XML
    MBString (php-mbstring) – A module for PHP applications which need multi-byte string handling
    MCrypt (php-mcrypt) – Standard PHP module provides mcrypt library support

yum --enablerepo=remi,remi-php56 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongo php-pecl-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

* Остановка сервиса httpd (Apache), запуск NGINX и PHP-FPM

systemctl stop httpd.service
systemctl disable httpd.service

systemctl start nginx.service
systemctl enable nginx.service

systemctl start php-fpm.service
systemctl enable php-fpm.service

* Настройка NGINX и PHP-FPM

Создаём директорию для сайта:
mkdir /srv/www/site
chown -R apache:apache /srv/www/site

Создание виртуальных директорий:
mkdir /etc/nginx/sites-available
mkdir /etc/nginx/sites-enabled

Директория для логов сайта site:
mkdir /var/log/nginx/site

Настройка NGINX:
vi /etc/nginx/nginx.conf
    ## Load virtual host conf files. ##
    include /etc/nginx/sites-enabled/*;

    server {
        server_name site.domain.org;
        access_log /var/log/nginx/site/access.log;
        error_log /var/log/nginx/site/error.log;
        root /srv/www;
        location / {
                index index.html index.htm index.php;}

        location ~ \.php$ {
                include /etc/nginx/fastcgi_params;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /srv/www/$fastcgi_script_name;}
     }

Подключение витуального хоста к /etc/nginx/sites-enabled:
cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/site.domain.org
sysctemctl restart nginx.service

Добавление site.domain.org в /etc/hosts:
vi /etc/hosts
    127.0.0.1               localhost.localdomain localhost site.domain.org
    
Проверка NGINX и PHP-FPM:
Создаём тестовый php файл
vi /srv/www/site/index.php
    <?php 
        phpinfo();
    ?>

Проверяем в браузере site.domain.org, должны получить такую страницу

* Выключить SElinux:

#vi /etc/sysconfig/selinux

    SELINUX=enforcing поменять на SELINUX=disabled

#setenforce 0

* Добавить правила в IPtables:

#vi /etc/sysconfig/iptables
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

#systemctl restart iptables


Комментариев нет:

Отправить комментарий