LEMP (Linux, Nginx, MySQL 5.5.29, PHP 5.4.11)
What is Nginx?
Nginx (Engine X) is open source robust light and high performance Web server, reverse proxy sever and also mail proxy server for HTTP, SMTP, POP3 and IMAP protocols. To know more about features visit http://wiki.nginx.org/OverviewWhat is PHP-FPM?
PHP-FPM stands for FastCGI Process Manager is an alternative PHP FastCGI implementation with some additional useful features for heavily loaded websites. For more information visit http://php-fpm.org/Step 1: Installing Remi Repository
## 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
## 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
Step 2: Installing Nginx Repository
Nginx repository only needed in RHEL/CentOS distributions. So, create a file called /etc/yum.repos.d/nginx.repo and add the following lines to it.For 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
Step 3: Installing Ngnix, MySQL 5.5.29, PHP 5.4.11 & PHP-FPM
## Installing on RHEL/CentOS 5-6 ## # yum --enablerepo=remi,remi-test install nginx mysql mysql-server php php-common php-fpm
Step 4: Installing PHP 5.4.11 Modules
## 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
Step 5: Stopping Apache Service
Apache and Nginx both services are bind to same port (i.e. 80). So, you must stop turn-off Apache in order to use Nginx.# chkconfig --levels 235 httpd off # /etc/init.d/httpd stop
Step 6: Starting/Stopping 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
Step 7: Configuring Nginx and PHP-FPM
Creating Website Directory
Creating a directory structure for your website under /srv/www/. In my case I used www.howtolinux247.info. This way you can create for your real site.## public_html directory and logs directory ##
# mkdir -p /srv/www/howtolinux247/public_html
# mkdir /srv/www/howtolinux247/logs
# chown -R nginx:nginx /srv/www/howtolinux247
Creating Website Logs
Creating log directories under /var/log.## public_html directory and logs directory ##
# mkdir -p /srv/www/howtolinux247/public_html
# mkdir -p /var/log/nginx/howtolinux247
# chown -R nginx:nginx /srv/www/howtolinux247
# chown -R nginx:nginx /var/log/nginx
Configuring Virtual Host Directories
Creating virtual host directoires under /etc/nginx.# mkdir /etc/nginx/sites-available # mkdir /etc/nginx/sites-enabledAdd following line of code to /etc/nginx/nginx.conf file at the end, before closing (http block) tag.
## Load virtual host conf files. ## include /etc/nginx/sites-enabled/*;For reference see below red line of code, how i added to the file /etc/nginx/nginx.conf.
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/*; }
Creating Virtual Host file for howtolinux247
Add the following lines of code to /etc/nginx/sites-available/howtolinux247 file. This is a basic virtual host config file.server { server_name howtolinux247; access_log /srv/www/howtolinux247/logs/access.log; error_log /srv/www/howtolinux247/logs/error.log; root /srv/www/howtolinux247/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/howtolinux247/public_html$fastcgi_script_name; } }
Linking Howtolinux247 Virtual Host
Linking howtolinux247 virtual host to /etc/nginx/sites-enabled.# cd /etc/nginx/sites-enabled/ # ln -s /etc/nginx/sites-available/howtolinux247
Restarting Nginx Service
We need here restart for Nginx service to reflect all the configuration which we have done above.# /etc/init.d/nginx restart
Adding Virtual Domain to Host File
Add the newly created virtual host domain to your local host file /etc/hosts.127.0.0.1 localhost.localdomain localhost howtolinux247
Step 8: Testing Nginx, MySQL, PHP and PHP-FPM
Create a file called phpinfo.php under /srv/www/howtolinux247/public_html/ and add the following lines of code to it. For example (/srv/www/howtolinux247/public_html/phpinfo.php).<?php phpinfo (); ?>
0 comments:
Post a Comment