## Remi Dependency on CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
## CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
Создадим файл /etc/yum.repos.d/nginx.repo
и добавим в него следующие строки:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
yum --enablerepo=remi,remi-php55 install nginx php-fpm php-common
yum install mysql-server
yum --enablerepo=remi,remi-php55 install php-pecl-apc php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml php-dom
service nginx start
service php-fpm start
service mysqld start
chkconfig --add nginx
chkconfig --levels 235 nginx on
chkconfig --add php-fpm
chkconfig --levels 235 php-fpm on
chkconfig --add mysqld
chkconfig --levels 235 mysqld on
Создаем папку под сайт
mkdir -p /srv/www/example.com/public_html
mkdir /srv/www/example.com/logs
chown -R apache:apache /srv/www/example.com
альтернативный вариант:
mkdir -p /srv/www/testsite.local/public_html
mkdir -p /var/log/nginx/testsite.local
chown -R apache:apache /srv/www/testsite.local
chown -R nginx:nginx /var/log/nginx
Я использую пользователя и группу apache
, потому что php-fpm
по-умолчанию их использует. Можно изменить в его настройках.
mkdir /etc/nginx/sites-available
mkdir /etc/nginx/sites-enabled
Добавляем в файл /etc/nginx/nginx.conf
следующие строки после “include /etc/nginx/conf.d/*.conf”
## Load virtual host conf files. ##
include /etc/nginx/sites-enabled/*;
Создаем файл в директории /etc/nginx/sites-available/
с названием хоста, в нашем случае example.com и добавим туда следующие настройки:
server {
server_name example.com;
access_log /srv/www/example.com/logs/access.log;
error_log /srv/www/example.com/logs/error.log;
root /srv/www/example.com/public_html;
location / {
try_files $uri $uri/ /index.html;
}
location ~ /\.ht {
deny all;
}
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
try_files $uri =404;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/example.com/public_html$fastcgi_script_name;
}
}
cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/example.com
service nginx restart
iptables
:Для этого добавим строчку в файл /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
service iptables restart
chcon -R -t httpd_sys_content_t /srv/www/example.com/public_html
Альтернативный вариант
chcon -R -t httpd_sys_rw_content_t /srv/www/example.com/public_html