Install LEMP (Linux, Nginx, MySQL 5.5.29, PHP 5.4.11) on RHEL/CentOS 5-6 & Fedora 18-12

This howto guide explains more deeply on how to install LEMP (LinuxNginxMySQLPHP) on pre-installed Linux servers and installation instructions can be used on various Linux distribution such as RHEL 6.2/6.1/6/5.8CentOS 6.2/6.1/6/5.8 and Fedora 12,13,14,15,16,17,18 servers using Remi and Nginx repositories with YUM command.

In this guide we use latest MySQL 5.5.29 and PHP 5.4.11 versions with PHP-FPM modules with Nginx. So, before moving further for installation let’s discuss about Nginx and PHP-FPM.

Install Nginx MySQL PHP in Linux

Setup LEMP Stack in Linux

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 HTTPSMTPPOP3 and IMAP protocols. To know more about features visit http://wiki.nginx.org/Overview

What is PHP-FPM?

PHP-FPM stands for FastCGI Process Manager is an alternative PHP FastCGIimplementation with some additional useful features for heavily loaded websites. For more information visit http://php-fpm.org/

Install LEMP (Linux, Nginx, MySQL, PHP) on RHEL 6.2/6.1/6/5.8,CentOS 6.2/6.1/6/5.8 and Fedora 12,13,14,15,16,17,18

Step 1: Installing 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

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 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
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 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

Step 4: Installing 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

Step 5: Stopping Apache Service

Apache and Nginx both services are bind to same port (i.e. 80). So, you must stop turn-offApache 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 usedwww.tecmint.com. This way you can create for your real site.

## public_html directory and logs directory ##
# mkdir -p /srv/www/tecmint/public_html
# mkdir /srv/www/tecmint/logs
# chown -R nginx:nginx /srv/www/tecmint
Creating Website Logs

Creating log directories under /var/log.

## public_html directory and logs directory ##
# mkdir -p /srv/www/tecmint/public_html
# mkdir -p /var/log/nginx/tecmint
# chown -R nginx:nginx /srv/www/tecmint
# 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-enabled

Add 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 Tecmint

Add the following lines of code to /etc/nginx/sites-available/tecmint file. This is a basic virtual host config file.

server {
    server_name tecmint;
    access_log /srv/www/tecmint/logs/access.log;
    error_log /srv/www/tecmint/logs/error.log;
    root /srv/www/tecmint/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/tecmint/public_html$fastcgi_script_name;
    }
}
Linking Tecmint Virtual Host

Linking tecmint virtual host to /etc/nginx/sites-enabled.

# cd /etc/nginx/sites-enabled/
# ln -s /etc/nginx/sites-available/tecmint
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 tecmint

Step 8: Testing Nginx, MySQL, PHP and PHP-FPM

Create a file called phpinfo.php under /srv/www/tecmint/public_html/ and add the following lines of code to it. For example (/srv/www/tecmint/public_html/phpinfo.php).

<?php

     phpinfo ();
?>

Now access the page with web browser using http://tecmint/phpinfo.php and verify all versions.

That’s It! for now, If you’re having any problems in installation and configuration, please feel free to ask your questions using our comment form below.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值