RHEL5.8 Build Lnmp Platform Example

Source: Internet
Author: User

Nginx in the processing of concurrency has a very good performance, relative to the more commonly used lamp platform (Linux + Apache + Mysql + PHP), Lnmp is also more and more used, when the site of concurrent access to a large, nginx is indeed a good choice, However, Nginx and PHP are integrated through the PHP-FPM way, that is, fastcgi, which requires PHP-FPM to enable a single process, as to how to choose, should be based on the actual production environment needs to be applied.


Experimental planning:

System platform: rhel5.8-i386

Nginx:nginx-1.4.7.tar

Mysql:mysql-5.5.44-linux2.6-i686.tar

Php:php-5.4.41.tar


One, install Nginx:

1. Resolve Dependencies:

# yum-y Groupinstall "Development Libraries" "Development Tools" # Yum-y Install Pcre-devel

2. Add Nginx running users and groups:

# groupadd-r nginx# useradd-r-G nginx nginx

3, compile and install Nginx:

# tar xf nginx-1.4.7.tar.gz# cd nginx-1.4.7# ./configure   -- Prefix=/usr   --sbin-path=/usr/sbin/nginx   --conf-path=/etc/nginx/nginx.conf    --error-log-path=/var/log/nginx/error.log   --http-log-path=/var/log/nginx/ access.log   --pid-path=/var/run/nginx/nginx.pid    --lock-path=/var/lock/ Nginx.lock   --user=nginx   --group=nginx   --with-http_ssl_ module   --with-http_flv_module   --with-http_stub_status_module    --with-http_gzip_static_module   --http-client-body-temp-path=/var/tmp/nginx/client/    --http-proxy-temp-path=/var/tmp/nginx/proxy/   --http-fastcgi-temp-path=/var/ tmp/nginx/fcgi/   --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi   -- Http-scgi-temp-path=/var/tmp/nginx/scgi &nbSp; --with-pcre# make && make install 

Start Nginx

#/usr/sbin/nginx

Test Nginx

# NETSTAT-TNLP | Grep:80tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 31103/nginx# Curl <! DOCTYPE Html>

See the hint above, stating that your nginx can work properly.


Second, installation mysql-5.5.44

1, first to prepare a file system for storing data, it is recommended to use LVM

# VGS VG #PV #LV #SN Attr vsize vfree vg_root 1 1 0 wz--n-97.70g 48.58g# lvcreate-l 300m-n Mydata/dev /vg_root/# mkfs.ext3/dev/vg_root/mydata# mkdir/mydata# mount/dev/vg_root/mydata/mydata# cd/mydata# mkdir data

2. Create MySQL user and MySQL group:

# groupadd-r mysql# useradd-r-G mysql-s/sbin/nologin-m-d/mydata/data mysql# chown-r mysql:mysql/mydata/data

3. Install and initialize MySQL

# tar XF mysql-5.5.44-linux2.6-i686.tar.gz-c/usr/local# ln-sv/usr/local/mysql-5.5.44-linux2.6-i686/usr/local/mysql  # cd/usr/local/mysql# Chown-r mysql:mysql. # scripts/mysql_install_db--user=mysql--datadir=/mydata/data# chown-r Root .

4. Provide the main configuration file for MySQL:

# cd/usr/local/mysql# CP support-files/my-large.cnf/etc/my.cnf

and modify the value of thread_concurrency in this file to multiply your number of CPUs by 2, for example using the following line:

Thread_concurrency = 2

In addition, you need to add the location of the MySQL data file:

DataDir =/mydata/data

5, provide SYSV script for MySQL

# cd/usr/local/mysql# CP support-files/mysql.server/etc/rc.d/init.d/mysqld# chkconfig--add mysqld # chkconfig mysqld o N

6, export the MySQL man manual:

To edit the/etc/man.config, add the following line:

Manpath/usr/local/mysql/man

7, output MySQL header file to System header file directory

# Ln-sv/usr/local/mysql/include/usr/include/mysql

8, output the path of the MySQL library file to the system library file:

# echo '/usr/local/mysql/lib ' >/etc/ld.so.conf.d/mysql.conf# ldconfig-v

9. Modify the PATH environment variable:

# echo "Export path= $PATH:/usr/local/mysql/bin" >/etc/profile.d/mysql.sh#. /etc/profile.d/mysql.sh

10. Test start MySQL service:

# service Mysqld Start # Mysqlwelcome to the MySQL Monitor. Commands End With;  or \g.your MySQL connection ID is 3Server version:5.5.44-log mysql Community Server (GPL) Copyright (c) +, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.mysql>

At this point, the mysql-5.5.44 installation is complete.


Three, install PHP-5.5.41

1, compile and install PHP

# Tar XF php-5.4.41.tar.bz2# cd php-5.4.41#./configure--prefix=/usr/local/php--with-mysql=/usr/local/mysql-- With-openssl--enable-fpm--enable-sockets--enable-sysvshm--with-mysqli=/usr/local/mysql/bin/mysql_config-- Enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib-dir--with-libxml-dir=/usr-- Enable-xml--with-config-file-path=/etc--with-config-file-scan-dir=/etc/php.d--with-bz2--with-curl # Make & & Make Install

2, provide the configuration file for PHP:

# CP Php.ini-production/etc/php.ini

3, provide the SYSV init script for php-fpm and add it to the list of services:

# CP sapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm# chmod +x/etc/rc.d/init.d/php-fpm# chkconfig--add php-fpm# CHKCO Nfig PHP-FPM on

4, provide the configuration file for php-fpm:

# cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf

To edit a php-fpm configuration file:

# vim/usr/local/php/etc/php-fpm.conf

The relevant options for configuring FPM are the values you need (this is just the reference value, adjusted to the actual situation), and the PID file is enabled (the last line below):

Pm.max_children = 150pm.start_servers = 8pm.min_spare_servers = 5pm.max_spare_servers = 10pid =/usr/local/php/var/run/ Php-fpm.pid

5, start php-fpm:

# service PHP-FPM start# NETSTAT-TNLP | grep php-fpmtcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 31025/php-fpm

PHP installation is complete.


Four, integrated Nginx and PHP5

1, edit/etc/nginx/nginx.conf, enable the following options:

Location ~ \.php$ {            root            html;             fastcgi_pass   127.0.0.1:9000;             fastcgi_index  index.php;             fastcgi_param  script_filename  /scripts$ fastcgi_script_name;            include         fastcgi_params;        }#   Add a page to PHP format location / {             root   html;            index   index.php index.html index.htm;        } 

2. Edit the/etc/nginx/fastcgi_params to change its contents to the following:

fastcgi_param  gateway_interface  cgi/1.1;fastcgi_param  server_software     nginx;fastcgi_param  QUERY_STRING        $query _ string;fastcgi_param  request_method      $request _method;fastcgi_param   CONTENT_TYPE        $content _type;fastcgi_param   content_length      $content _length;fastcgi_param  script_filename      $document _root$fastcgi_script_name;fastcgi_param  script_name          $fastcgi _script_name;fastcgi_param  request_uri          $request _uri;fastcgi_param  document_uri         $document _uri;fastcgi_param  document_root       $document _ Root;fastcgi_param  server_protocol     $server _protocol;fastcgi_param  remote_addr          $remote _addr;fastcgi_param  remote_port          $remote _port;fastcgi_param  server_addr          $server _addr;fastcgi_param  server_port         $server _port;fastcgi_param  server_name         $server _name;

3. Re-loading Nginx

#/usr/sbin/nginx-s Reload

4, in/usr/html new index.php test page, test PHP will work:

# VIM/USR/HTML/INDEX.PHP<H1>LNMP Test

Open the browser test as follows

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/7F/wKioL1X_vT7Q00GWAAIK7r852-E105.jpg "title=" QQ picture 20150921160751.png "alt=" Wkiol1x_vt7q00gwaaik7r852-e105.jpg "/>


RHEL5.8 Build Lnmp Platform Example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.