`
844604778
  • 浏览: 548294 次
文章分类
社区版块
存档分类
最新评论

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 (Linux,Nginx,MySQL,PHP) on pre-installed Linux servers and installation instructions can be used on various Linux distribution such asRHEL 6.2/6.1/6/5.8,CentOS 6.2/6.1/6/5.8andFedora 12,13,14,15,16,17,18servers usingRemiandNginxrepositories withYUMcommand.

In this guide we use latestMySQL 5.5.29andPHP 5.4.11versions withPHP-FPMmodules with Nginx. So, before moving further for installation let’s discuss aboutNginxandPHP-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 forHTTP,SMTP,POP3andIMAPprotocols. To know more about features visithttp://wiki.nginx.org/Overview

What is PHP-FPM?

PHP-FPMstands forFastCGI Process Manageris an alternativePHP FastCGIimplementation with some additional useful features for heavily loaded websites. For more information visithttp://php-fpm.org/

Install LEMP (Linux, Nginx, MySQL, PHP) onRHEL 6.2/6.1/6/5.8,CentOS 6.2/6.1/6/5.8andFedora 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

Nginxrepository only needed inRHEL/CentOSdistributions. So, create a file called/etc/yum.repos.d/nginx.repoand 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

ApacheandNginxboth services are bind to same port (i.e. 80). So, you must stop turn-offApachein order to useNginx.

# 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.conffile 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/tecmintfile. 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

Linkingtecmintvirtual 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 forNginxservice 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 calledphpinfo.phpunder/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 usinghttp://tecmint/phpinfo.phpand 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.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics