install lemp (linux, nginx, mysql 5.5.29, php 5.4.pdf

13
► Install PHP ► Install RPM ► Apache ► Centos

Upload: victor-l-wamukoya

Post on 03-Jan-2016

156 views

Category:

Documents


2 download

DESCRIPTION

install LEMP

TRANSCRIPT

Page 1: Install LEMP (Linux, Nginx, MySQL 5.5.29, PHP 5.4.pdf

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

www.tecmint.com/install-lemp-linux-nginx-mysql-php-on-rhel-centos-5-6-fedora-12-17/ 1/13

Search

Select Language Pow ered by Translate

Advertise

Hire Us

Submit Articles

Archives

Who We Are?

Contact Us

Privacy Policy

Copyright Policy

Home

Linux Distros »

Open Source

Web Servers »

Databases »

Linux Commands

TecMint.com is a community driven Linux website. Our motto is to provide an effortless howto’s to our valuable readers.

You are also welcome to join our community and can be part of our team, contributing and submitting well written article on Linux. If you have any query, please contact us by email tecmint.com [at] gmail [dot] com or use our contact form.

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

By Ravi Saive Under: CentOS, Databases, Fedora, Linux Distros, MySQL, Nginx, PHP, RedHat, Web Servers On: January 23, 2013

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 as 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 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 PHP ► Install RPM ► Apache ► Centos

Page 2: Install LEMP (Linux, Nginx, MySQL 5.5.29, PHP 5.4.pdf

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

www.tecmint.com/install-lemp-linux-nginx-mysql-php-on-rhel-centos-5-6-fedora-12-17/ 2/13

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 HTTP, SMTP, POP3 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 FastCGI implementation 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

Page 3: Install LEMP (Linux, Nginx, MySQL 5.5.29, PHP 5.4.pdf

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

www.tecmint.com/install-lemp-linux-nginx-mysql-php-on-rhel-centos-5-6-fedora-12-17/ 3/13

## 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 repobaseurl=http://nginx.org/packages/rhel/$releasever/$basearch/gpgcheck=0enabled=1

For CentOS 6.3/6.2/6.1/6/5.8

[nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0enabled=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-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

Page 4: Install LEMP (Linux, Nginx, MySQL 5.5.29, PHP 5.4.pdf

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

www.tecmint.com/install-lemp-linux-nginx-mysql-php-on-rhel-centos-5-6-fedora-12-17/ 4/13

## 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.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;

Page 5: Install LEMP (Linux, Nginx, MySQL 5.5.29, PHP 5.4.pdf

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

www.tecmint.com/install-lemp-linux-nginx-mysql-php-on-rhel-centos-5-6-fedora-12-17/ 5/13

Bio Latest Posts

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.

Ravi SaiveOwner at TecMint.com

Page 6: Install LEMP (Linux, Nginx, MySQL 5.5.29, PHP 5.4.pdf

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

www.tecmint.com/install-lemp-linux-nginx-mysql-php-on-rhel-centos-5-6-fedora-12-17/ 6/13

Simple Word a Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux.

Linux Services & Free WordPress Setup

Our post is simply ‘DIY’ aka ‘Do It Yourself, still you may find difficulties and want us to help you out. We offer wide range of Linux and Web Hosting Solutions at fair minimum rates. Please submit your orders by Clicking Here.

TweetTweet

9

41

Like

9

22

comments

« Previous Post

Fedora 18 (Spherical Cow) Basic Installation Guide with Screenshots

Next Post »

4 Ways to Upgrade from Fedora 17 to Fedora 18

Related Post(s):

1. 12 Useful “df” Commands to Check Disk Space in Linux

2. Red Hat Enterprise Linux (RHEL) 6 Installation Guide with Screenshots

3. Fedora 18 XFCE Desktop Installation Guide with Screenshots

4. Install Software Packages via YUM command using CentOS 6/5 Installation DVD/CD

5. How to Mount and Unmount an ISO Image in RHEL/CentOS/Fedora and Ubuntu

6. Install and Enable RPMForge Repository in RHEL/CentOS 6, 5, 4

22 Responses

4

ShareShare

► Centos ► RedHat ► Nginx ► Linux RPM

Page 7: Install LEMP (Linux, Nginx, MySQL 5.5.29, PHP 5.4.pdf

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

www.tecmint.com/install-lemp-linux-nginx-mysql-php-on-rhel-centos-5-6-fedora-12-17/ 7/13

1. Gary says:October 1, 2012 at 12:39 pm

In step 7, why some of commands in “Creating Website Directory” and “Creating Website Logs” such as mkdir -p /srv/www/tecmint/public_html & chown -R nginx:nginx /srv/www/tecmint are duplicate?

Reply

2. ajay says:

November 3, 2012 at 1:22 pm

YUM SERVER & DNS SERVER configuration on RHEL 6

Reply

3. Ravi says:

November 22, 2012 at 6:15 pm

Hi,

I am unable to install php-fpm on centos 6.2. getting below mentioned error.

[root@localhost home]# yum –enablerepo=remi,remi-test install nginx mysql mysql-server php php-common php-fpm

Loaded plugins: fastestmirrorLoading mirror speeds from cached hostfile* base: centos.01link.hk

* extras: centos.01link.hk* updates: centos.01link.hkSetting up Install Process

Package nginx-1.2.5-1.el6.ngx.x86_64 already installed and latest versionPackage mysql-5.1.66-1.el6_3.x86_64 already installed and latest versionPackage mysql-server-5.1.66-1.el6_3.x86_64 already installed and latest version

Package php-5.3.3-14.el6_3.x86_64 already installed and latest versionPackage php-common-5.3.3-14.el6_3.x86_64 already installed and latest versionNo package php-fpm available.

Nothing to do

Reply

Ravi Saive says:November 22, 2012 at 7:01 pm

@Ravi

You have not added remi repository. see the above errors the mirrors loading from CentOS base. Install remi repository and try again.

Reply

4. Yafanz says:February 11, 2013 at 8:20 pm

# chkconfig –add mysqld

error reading information on service mysqld: No such file or directory

Page 8: Install LEMP (Linux, Nginx, MySQL 5.5.29, PHP 5.4.pdf

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

www.tecmint.com/install-lemp-linux-nginx-mysql-php-on-rhel-centos-5-6-fedora-12-17/ 8/13

# /etc/init.d/mysqld startbash: /etc/init.d/mysqld: No such file or directory

# /etc/init.d/php-fpm start

Starting php_fpm /etc/init.d/php-fpm: line 44: /usr/local/bin/php-cgi: No such file or directoryfailed

Reply

5. Ravi Saive says:

February 11, 2013 at 8:33 pm

Have you installed MySQL and php-cgi packages correctly? If not, install them correctly. Because the errors clearly saying you don’t have those files.

Reply

6. Yafanz says:February 11, 2013 at 9:00 pm

i have installed mysql

# rpm -qa mysql\*

mysql-libs-5.5.29-1.fc18.x86_64

mysql-server-5.5.29-1.fc18.x86_64mysql-5.5.29-1.fc18.x86_64

how to install php-cgi ??

Reply

Ravi Saive says:February 12, 2013 at 12:34 pm

Please use the below command is being used for latest fedora 18/17 onwards to start services.

# systemctl start mysqld.service

Reply

7. Yafanz says:

February 12, 2013 at 11:56 am

how to fix error 502 Bad Gateway???

nginx , php-fpm status is enable and active.

Reply

8. Dabney says:April 8, 2013 at 8:05 pm

http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

The 6-7 release is no longer active via the link in the first section of this post. Just a heads up in case someone encounters a 404 when attempting to install the RPM.

Reply

Page 9: Install LEMP (Linux, Nginx, MySQL 5.5.29, PHP 5.4.pdf

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

www.tecmint.com/install-lemp-linux-nginx-mysql-php-on-rhel-centos-5-6-fedora-12-17/ 9/13

Ravi Saive says:

April 8, 2013 at 8:17 pm

Thanks.. updated now..

Reply

9. Cristian says:

June 11, 2013 at 12:21 am

hello, I have the following problem in php-fpm. I set up nginx + php-fpm + mysql and it occurs, the processes of php-fpm are always running on Linux, even after the client close the connection, the processes remain active, the only way

to solve it by restarting the service php -fpm. Did this happen to you?

Reply

10. Dev says:July 2, 2013 at 1:52 pm

Sir can you tell me the default web directory…….

Were I will just copy and paste my html and php file that can browsable from other clients to view that web page.

Reply

Ravi Saive says:

July 2, 2013 at 3:29 pm

The default web directory for for Nginx is /srv/www/. Please follow the guide correctly.

Reply

11. David Nguyen says:

July 8, 2013 at 10:14 am

Hi Ravi,

Can Nginx run both php 5.2 and 5.4 ?

Thanks,

Reply

Ravi Saive says:

July 8, 2013 at 1:30 pm

Yes! Nginx can run both the PHP versions.

Reply

12. Tapash Datta says:

July 16, 2013 at 8:46 pm

Hi Ravi,

Page 10: Install LEMP (Linux, Nginx, MySQL 5.5.29, PHP 5.4.pdf

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

www.tecmint.com/install-lemp-linux-nginx-mysql-php-on-rhel-centos-5-6-fedora-12-17/ 10/13

Thank you for great work. I am a beginner with linux and planning to host a website from my homeserver on CentOS. I Have followed both of your tutorial on Nginx + PHP & Phpmyadmin. However I am not able to get the

phpmyadmin screen. I would also like to install drupal on it. I have created 2 vhost, drupal & phpmyadmin. But only able to get the drupal installation screen. phpmyadmin vhost gives 404 error. Would you please be kind to make

tutorial for CentOS+ Nginx+PHP+ MysQL+ Phpmyadmin+ drupal on a combined vhost file please? I would be very grateful to you. I am sure it will be useful for many others like me…. Thanks again

Reply

Ravi Saive says:

July 17, 2013 at 12:07 pm

OK noted your requirement, will write up on this soon, if we get time. stay tuned for this.

Reply

Corey Jones says:

July 24, 2013 at 8:30 am

This is exactly the problem im having too. A tutorial for that would be great. I’m hoping this will be for 6.4? Thanks for the tutorials though they are great.

Reply

Ravi Saive says:

July 24, 2013 at 5:36 pm

Ok, I think we need to recheck the article to make it 100% working. Give us some time to check.

Reply

Leave a Reply

Name (Required)

Mail (will not be published) (Required)

Website

Submit Comment

Twitter 869 Twitter

Facebook 11390 Facebook

Google+ 281 Google+

RSS 1431 Subscribers

Become A TecMint Subscriber to receive latest Updates.

Page 11: Install LEMP (Linux, Nginx, MySQL 5.5.29, PHP 5.4.pdf

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

www.tecmint.com/install-lemp-linux-nginx-mysql-php-on-rhel-centos-5-6-fedora-12-17/ 11/13

Enter Your Email Address :)Signup!

Popular

Latest

CommentsTags

Install Apache, MySQL 5.5.32 & PHP 5.5.0 on RHEL/CentOS 6.4/5.9 & Fedora 19-1288 Comments

Install Cacti (Network Monitoring) on RHEL/CentOS 6.3/5.8 and Fedora 17-1288 Comments

Wine 1.6 Released – Install in RHEL, CentOS and Fedora85 Comments

CentOS 6.3 Step by Step Installation Guide with Screenshots71 Comments

Install Google Chrome 28.0 on RHEL/CentOS 6 and Fedora 19/1544 Comments

Install Skype 4.1 in Ubuntu 12.10, Xubuntu 12.10 and Linux Mint 14/1343 Comments

15 Command Line Tools to Monitor Linux Performance41 Comments

Install VirtualBox 4.2.16 on RHEL/CentOS 6.4/5.9 and Fedora 19-1236 Comments

CentOS 6.4 Step by Step Installation Guide with Screenshots36 Comments

Page 13: Install LEMP (Linux, Nginx, MySQL 5.5.29, PHP 5.4.pdf

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

www.tecmint.com/install-lemp-linux-nginx-mysql-php-on-rhel-centos-5-6-fedora-12-17/ 13/13

©2013Tecmint: Linux Howtos, Tutorials & Guides.All rights reserved.

Proudly designed by Tecmint.com.