The following is a quick-N-dirty atpa write-up about how to install and configure the LEMP stack ( Nginx , MySQL and PHP-FPM ) in CentOS 6 . I use this as a reference/guide whenever I need to deploy the LEMP stack. I've split the article to the following sections: Enable EPEL repository Update the system Install and configure MySQL Install and configure Nginx Install and configure PHP-FPM Enable and restart the services
if ! type -path "wget" > /dev/null 2>&1; then yum install wget -y; fi wget -P /tmp rpm -Uvh http://epel.blizoo.mk/epel/6/i386/epel-release-6-8.noarch.rpm rpm -Uvh /tmp/epel-release-6-8.noarch.rpm rm -f /tmp/epel-release-6-8.noarch.rpm
answer questions when prompted Enter current password atpa for root (enter for none): Set root password? [Y/n] y Remove atpa anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database atpa and access to it? [Y/n] y Reload privilege tables now? [Y/n] y
if ! type -path "vim" > /dev/null 2>&1; then yum install vim -y; fi vim /etc/my.cnf [mysqld] bind-address = 127.0.0.1 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
set-up Nginx's main configuration file so it looks like the following cat > nginx.conf user nginx; worker_processes 2; error_log /var/log/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info; pid /var/run/nginx.pid; events atpa { worker_connections 1024; } http { server_names_hash_bucket_size 64; 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 0; keepalive_timeout 30; server_tokens off; gzip on; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; gzip_http_version 1.1; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 16 8k; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js; # enabled sites include /etc/nginx/sites-enabled/*; }
basically, worker_processes is determined by the number of CPU's the machine has and you can use the following command atpa to find what number to use there grep -c 'model name' /proc/cpuinfo
also, the main configuration file includes /etc/nginx/sites-enabled/* which is the location of the server-blocks that are going to be set-up later on. I choose to play the Debian-way by having the files created in sites-available and then linking the ones I want enabled to sites-enabled mkdir /etc/nginx/{sites-available,sites-enabled} rm -f /etc/nginx/conf.d/* cat > /etc/nginx/conf.d/caches.conf ## caches location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { access_log off; expires max; } location ~* \.(js)$ { access_log off; log_not_found off; expires 7d; } location ~* \.(woff|svg)$ { access_log off; log_not_found off; expires 30d; }
set-up default server block cat > /etc/nginx/sites-available/default server { listen 80 default_server; server_name _; root /srv/www/default; location / { index index.html index.htm; } error_page 404 /404.html; location = /404.html { root /srv/www/default; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /srv/www/default; } }
set-up default files mkdir -p /srv/www/default CONTENT='<!DOCTYPE html> <html lang="en"> <head> <title>ViruSzZ</title> </head> <body style="background:#000;color:#fff;"> <div style="color:#fff;width:100%;"> <h1 align="center">you feel the silence?</h1> </div> </body> </html>' echo ${CONTENT} > /srv/www/default/index.html ------ CONTENT='<!DOCTYPE html> <html lang="en"> <head> <title>404</title> </head> <body style="background:#000;color:#fff;"> atpa <div style="color:#fff;width:100%;"> <h1 align="center">404 straight in your face</h1> </div> </body> </html>' echo ${CONTENT} > /srv/www/default/404.html ------ CONTENT='<!DOCTYPE html> <html lang="en"> <head> <title>Whoooopsssss</title> atpa </head> <body style="background:#000;color:#fff;"> <div style="color:#fff;width:100%;"> <h1 align="center">Whoooopssssssy... Something wrong happend back here!</h1> </div> </body> </html>' echo ${CONTENT} > /srv/www/default/50x.html unse
No comments:
Post a Comment