LEMP

Установка LEMP на RHEL, CentOS и Fedora

Установка LEMP (Linux, Nginx, MySQL, PHP) на RHEL 6.2/6.1/6/5.8, CentOS 6.2/6.1/6/5.8 и Fedora 12,13,14,15,16,17,18

Шаг 1: Установка Remi Repository

## Install Remi Repository on Fedora 18, 17, 16, 15 ##
# rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
# rpm -Uvh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm

## Fedora 18 ##
# rpm -Uvh http://rpms.famillecollet.com/remi-release-18.rpm

## Fedora 17 ##
# rpm -Uvh http://rpms.famillecollet.com/remi-release-17.rpm

## Fedora 16 ##
# rpm -Uvh http://rpms.famillecollet.com/remi-release-16.rpm

## Fedora 15 ##
# rpm -Uvh http://rpms.famillecollet.com/remi-release-15.rpm

## Fedora 14 ##
# rpm -Uvh http://rpms.famillecollet.com/remi-release-14.rpm

## Fedora 13 ##
# rpm -Uvh http://rpms.famillecollet.com/remi-release-13.rpm

## Fedora 12 ##
# rpm -Uvh http://rpms.famillecollet.com/remi-release-12.rpm

## Install Remi Repository on RHEL/CentOS 6.3-6.0 ##
# rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

## Install Remi Repository on RHEL/CentOS 5.4-5.0 ##
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

Шаг 2: Установка Nginx Repository

Nginx repository необходим только для RHEL/CentOS дистрибутивов. Создаем файл /etc/yum.repos.d/nginx.repo и добавляем в него код, в зависимости от дистрибутива.

Для RHEL 6.3/6.2/6.1/6/5.8
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/$releasever/$basearch/
gpgcheck=0
enabled=1

Для CentOS 6.3/6.2/6.1/6/5.8
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

Шаг 3: Установка Ngnix, MySQL 5.5.29, PHP 5.4.11 & PHP-FPM

## Installing on Fedora 12, 13, 14, 15, 16, 17, 18 ##
# yum --enablerepo=remi install nginx mysql mysql-server php php-common php-fpm

## Installing on RHEL/CentOS 5-6 ##
# yum --enablerepo=remi,remi-test install nginx mysql mysql-server php php-common php-fpm

Шаг 4: Установка PHP 5.4.11 Modules

## Installing on Fedora 12, 13, 14, 15, 16, 17, 18 ##
# yum --enablerepo=remi install php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml php-pecl-apc php-cli php-pear php-pdo

## Installing on RHEL/CentOS 5-6 ##
# yum --enablerepo=remi,remi-test install php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml php-pecl-apc php-cli php-pear php-pdo

Шаг 5: Стоп Apache Service

# chkconfig --levels 235 httpd off
# /etc/init.d/httpd stop

Шаг 6: Запуск/Стоп Nginx MySQL and PHP-FPM

## Enable Nginx, MySQL and PHP-FPM on Boot ##
# chkconfig --add nginx
# chkconfig --add mysqld
# chkconfig --add php-fpm

## Enable Nginx, MySQL and PHP-FPM on Run Levels ##
# chkconfig --levels 235 nginx on
# chkconfig --levels 235 mysqld on
# chkconfig --levels 235 php-fpm on

## Nginx Startup Commands ##
# /etc/init.d/nginx start
# /etc/init.d/nginx stop
# /etc/init.d/nginx status

## MySQL Startup Commands ##
# /etc/init.d/mysqld start
# /etc/init.d/mysqld stop
# /etc/init.d/mysqld status

## PHP-FPM Startup Commands ##
# /etc/init.d/php-fpm start
# /etc/init.d/php-fpm stop
# /etc/init.d/php-fpm status

Шаг 7: Настройка Nginx and PHP-FPM
Создаем структуру веб сервера в директории /srv/www/.
Создаем корень сайта
## public_html directory and logs directory ##
# mkdir -p /srv/www/site/public_html
# mkdir /srv/www/site/logs
# chown -R nginx:nginx /srv/www/site

Создаем директорию с логами
## public_html directory and logs directory ##
# mkdir -p /srv/www/site/public_html
# mkdir -p /var/log/nginx/site
# chown -R nginx:nginx /srv/www/site
# chown -R nginx:nginx /var/log/nginx

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

Включаем конфиг виртуальных хостов
в /etc/nginx/nginx.conf добавляем
## Load virtual host conf files. ##
include /etc/nginx/sites-enabled/*;

Пример:
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

Создаем виртуальных хост
в /etc/nginx/sites-available/site добавляем

server {
server_name site;
access_log /srv/www/site/logs/access.log;
error_log /srv/www/site/logs/error.log;
root /srv/www/site/public_html;

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/site/public_html$fastcgi_script_name;
}
}

Включаем виртуальный хост
# cd /etc/nginx/sites-enabled/
# ln -s /etc/nginx/sites-available/tecmint

Перезапуск Nginx
# /etc/init.d/nginx restart

Добавляем виртуальных хост в hosts
в /etc/hosts добавляем:
127.0.0.1 localhost.localdomain localhost site

Шаг 8: Проверка Nginx, MySQL, PHP and PHP-FPM

phpinfo ();