Linux + Nginx + Mysql + Php illustration, detailed operation steps !, Nginxmysql

Source: Internet
Author: User

Linux + Nginx + Mysql + Php illustration, detailed operation steps !, Nginxmysql

About LNMP

LAMP (Linux apache mysql php) --- early web services.

LNMP (Linux nginx mysql php) --- more popular, new webn services, increasing usage (very popular in China ).

 

Nginx (Engine X) is an open-source www service software developed by Russians. The software is 780 K (very small) in total and is a static (html, js, css, jpg, etc.) www software, static small files are highly concurrent and occupy very little resources at the same time.

 

The Nginx platform (linux and unix windows) is the same as apache.

 

Nginx features:

A. www web Service --- http 80

B. Server Load balancer (reverse proxy)

C. web cache

 

Advantages of nginx:

1. simple and flexible configuration.

2. High concurrency (static small files), static 1-2 W.

3. A few resources are occupied, and 10 thread services are concurrently opened at 2 w, consuming several hundred megabytes of memory.

4. Many features (web cache proxy), each of which is not very powerful.

5. Supports the epoll model to enable nginx to support high concurrency.

6. nginx is different from apache in combination with dynamic services.

7. Use nginx to speed up IP addresses. You can limit the number of connections.

 

Implementation principle: nginx (apache) -- php -- mysql

 

Nginx application scenarios:

1. Static services (images, videos) and other lighttpd (inactive community ). Concurrency: 1-3 W, html, js, css,. flv

2. dynamic service: run php and jsp in nginx + fastcgi mode. Concurrency: 500-1500, similar to apache + php, lighttpd + fcgi php

3. reverse proxy and Server Load balancer. If the daily PV2000W or lower, nginx can be used as the proxy. Haproxy, F5, a10

4. cache service, SQUID, VARNI.

 

Comparison between nginx and other web servers:

1) apache

A. Stable and powerful

B. The Prefork mode removes the Process Creation overhead, resulting in high performance.

C. When Processing dynamic business data, because it is associated with backend engines and databases, the bottleneck is not in apache itself

D. Consumption of system resources during high concurrency is relatively more

E. Based on the traditional select model

2) nginx

A. Based on the asynchronous I/O model (epoll, kqueue), high performance and support for tens of thousands of concurrent jobs

B. good support for small files and high performance (limited to static small files)

C. The code is beautiful, and the extension library must be compiled to implement the main program.

D. Relatively low resource consumption

3) Lighttpd (Baidu Post Bar, Douban)

A. Based on the asynchronous IO model, the performance is similar to that of nginx

B. The SO mode is used for expansion, which is more flexible than nginx.

C. The Global usage is low, and the security is not as good as apache and nginx.

D. The File URL can be encrypted through the plug-in (mod secdownload ).

 

How to select a web server for enterprise production scenarios (recommended ):

Static business: High concurrency, with nginx or lighttpd

Dynamic service: Both nginx and apache are supported.

Both dynamic and static services: Both nginx and apache can be selected.

External business nginx and internal business apache

 

Install and configure nginx

1. Installation preparation: [root @ localhost ~] # Yum install pcre *-y

[Root @ localhost ~] # Yum install openssl *-y

2. Compile:

./Configure -- prefix =/application/nginx1.12.0 \

-- User = nginx \

-- Group = nginx \

With-http_stub_status_module \

With-http_ssl_module

3. Start the check:

[Root @ localhost application] #/application/nginx/sbin/nginx-t

Nginx: the configuration file/application/nginx1.12.0/conf/nginx. conf syntax is OK

Nginx: configuration file/application/nginx1.12.0/conf/nginx. conf test is successful

[Root @ localhost application] #/application/nginx/sbin/nginx

[Root @ localhost application] # netstat-lntup | grep nginx (you can also check port 80)

 

 

 

The interface is displayed, indicating that the operation is successful.

[Root @ localhost application] # vim/application/nginx/html/index.html modify the homepage content

 

4. About the nginx Module

1) Nginx core modules (required), including Main Events

2) Standard HTTP modules (although not required, it will be installed by default and is not recommended to be changed), including Core Acess FastCGI Gzip (compression module, performance optimization) LOG (LOG Module) proxy Rewrite (URL Rewrite module) Upstream (Server Load balancer module) and so on

Tip: by default, both modules are installed. The configuration file is modified based on the functions of the two groups of modules. You can view the module parameters on the official website.

 

5. nginx Configuration

[Root @ localhost conf] # egrep-v "# | ^ $" nginx. conf. default> nginx. conf (remove comment # Line)

[Root @ localhost conf] # vim nginx. conf (cairui.org is an alias)

 

 

[Root @ localhost conf] # mkdir/application/nginx/html/www

[Root @ localhost conf] # touch/application/nginx/html/www/index.html

[Root @ localhost conf] # vim/application/nginx/html/www/index.html

[Root @ localhost conf] #/application/nginx/sbin/nginx-t

Nginx: the configuration file/application/nginx1.12.0/conf/nginx. conf syntax is OK

Nginx: configuration file/application/nginx1.12.0/conf/nginx. conf test is successful

[Root @ localhost conf] #/application/nginx/sbin/nginx-s reload

Modify the windows local hosts file to ensure that you can ping the host from the VM at the win command prompt and view the host on the web page.

 

Add status server labels:

[Root @ localhost conf] # vim/application/nginx/conf/nginx. conf

 

 

# Status

Server {

Listen 80;

Server_name status.cairui.org;

Location /{

Stub_status on;

Access_log off;

}

}

In the Windows local hosts file,

 

 

 

 

Resolve malicious domain name binding:

[Root @ localhost conf] # vim/application/nginx/conf/nginx. conf (must be placed on the first server)

Server {

Listen 80;

Location /{

Deny all;

 

}

}

 

Enable Logging:

[Root @ localhost conf] # cat/application/nginx/conf/nginx. conf. default (locate the log format)

 

# 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 logs/access. log main;

Copy to nginx. conf and remove comments

 

 

 

 

The error log format is placed at the top

Software for analyzing nginx logs: syslog, rsyslog, Awstats, scribe, kafka

 

Mysql

Mysql installation method:

5.1 --- compile and install configure, make, make install

5.5 --- compile and install cmake, make, and make install (which can be directly installed using a Binary Package and decompressed)

 

1. Install mysql

[Root @ localhost conf] # useradd mysql-s/sbin/nologin-M

[Root @ localhosttools] # tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz

[Root @ localhost tools] # mv mysql-5.5.32-linux2.6-x86_64/application/mysql5.5.32

[Root @ localhost tools] # ln-s/application/mysql5.5.32 // application/mysql

[Root @ localhost tools] # chown-R mysql. mysql/application/mysql/data/

[Root @ localhost mysql] #. /scripts/mysql_install_db -- user = mysql -- basedir =/application/mysql/-- datadir =/application/mysql/data/(libaio must be installed before compilation)

[Root @ localhost mysql] # cp support-files/mysql. server/etc/init. d/mysqld

[Root @ localhost mysql] # vim/etc/init. d/mysqld

 

 

[Root @ localhost mysql] # cp support-files/my-small.cnf/etc/my. cnf (different configuration files for each version)

Cp: overwrite "/etc/my. cnf "? Y

[Root @ localhost mysql] # vim/etc/profile

 

 

[Root @ localhost mysql] # service mysqld start

Starting MySQL... SUCCESS!

[Root @ localhost mysql] # mysql

Database optimization:

Mysql> show databases

Mysql> drop Database test;

Mysql> select user, host from mysql. user;

Mysql> drop user ''@ localhost;

[Root @ localhost mysql] # mysql-uroot-pnew-password

Change the password (go to mysql to modify) mysql> set password for root @ localhost = password ('123 ');

 

PHP

Php In LNMP:

Apache ---- libphp5.so

Nginx --- fcgi php-fpm port9000 (Baidu)

Before installing php, ensure that mysql and nginx run normally [root @ localhost mysql] # netstat-lntup | egrep "nginx | mysql"

1. software to be installed

Install libiconv (./configure -- prefix =/usr/local/libiconv)

 

Install libmcrypt (not required, recommended) as an encrypted Library

./Configure

Make

Make install

Sleep2

/Sbin/ldconfig

Cd libltdl/

./Configure -- enable-ltdl-install

Make

Make install

Cd ../cd

 

Install mhash

./Configure

Make

Make install

Sleep 2

Cd ../

 

Rm-fr/usr/lib64/libmcrypt .*

Rm-fr/usr/lib64/libmhash *

Ln-s/usr/local/lib64/libmcrypt. la/usr/lib64/libmcrypt. la

Ln-s/usr/local/lib64/libmcrypt. so/usr/lib64/libmcrypt. so

Ln-s/usr/local/lib64/libmcrypt. so.4/usr/lib64/libmcrypt. so.4

Ln-s/usr/local/lib64/libmcrypt. so.4.4.8/usr/lib64/libmcrypt. so.4.4.4.8

Ln-s/usr/local/lib64/libmhash. a/usr/lib64/libmhash.

Ln-s/usr/local/lib64/libmhash. la/usr/lib64/libmhash. la

Ln-s/usr/local/lib64/libmhash. so/usr/lib64/libmhash. so

Ln-s/usr/local/lib64/libmhash. so.2/usr/lib64/libmhash. so.2

Ln-s/usr/local/lib64/libmhash. so.2.0.1/usr/lib64/libmhash. so.2.0.1

Ln-s/usr/local/bin/libmcrypt-config/usr/bin/libmcrypt-config

 

Install mcrypt

/Sbin/ldconfig

./Configure LD_LIBRARY_PATH =/usr/local/lib

Make

Make install

Cd ../

Sleep 2

 

2. install php

[Root @ localhost tools] # yum install libxslt *-y

./Configure \

-- Prefix =/application/php5.6.30 \

-- With-mysql =/application/mysql \

-- With-iconv-dir =/usr/local/libiconv \

-- With-freetype-dir \

-- With-jpeg-dir \

-- With-png-dir \

-- With-zlib \

-- With-libxml-dir =/usr \

-- Enable-xml \

-- Disable-rpath \

-- Enable-safe-mode \

-- Enable-bcmath \

-- Enable-shmop \

-- Enable-sysvsem \

-- Enable-inline-optimization \

-- With-curl \

-- With-curlwrappers \

-- Enable-mbregx \

-- Enable-fpm \

-- Enable-mbstring \

-- With-mcrypt \

-- With-gd \

-- Enable-gd-native-ttf \

-- With-openssl \

-- With-mhash \

-- Enable-pcntl \

-- Enable-sockets \

-- With-xmlrpc \

-- Enable-zip \

-- Enable-soap \

-- Enable-short-tags \

-- Enable-zend-multibyte \

-- Enable-static \

-- With-xsl \

-- With-fpm-user = nginx \

-- With-fpm-group = nginx \

-- Enable-ftp \

-- Enable-opcache = no

Ln-s/application/mysql/lib/libmysqlclient. so.18/usr/lib64

Error Handling: http://www.68idc.cn/help/jiabenmake/qita/20141114128775.html ,,

Http://blog.csdn.net/hp6451449/article/details/54746842? LocationNum = 5 & fps = 1

 

3. php configuration

[Root @ localhost php-5.3.27] # cp php. ini-production/application/php/lib/php. ini

 

Direct upload

[Root @ localhost etc] #/application/php/sbin/php-fpm-t

[Root @ localhost etc] #/application/php/sbin/php-fpm

Start

Cat>/etc/rc. local <EOF

# Nginx + php-fpm by cairui at 2017

/Etc/init. d/mysqld start

/Application/php/sbin/php-fpm

/Application/nginx/sbin/nginx

EOF

 

[Root @ 134 extra] # cat/application/nginx/conf/extra/bbs. conf

Server {

Listen 80;

Server_name bbs.caimengzhi.org;

Root html/bbs;

Index index.html index.htm I index. php;

Location ~ . * \. (Php | php5 )? $ # At this time, if no directory is specified in {}, the PHP file under the above html/bbs will be read directly.

{

Fastcgi_pass 127.0.0.1: 9000;

Fastcgi_index index. php;

Include fastcgi. conf;

}

}

 

[Root @ localhost conf] # cd/application/nginx/html/www/

[Root @ localhost www] # vim index. php

 

 

[Root @ localhost www] #/application/nginx/sbin/nginx-t

[Root @ localhost www] #/application/nginx/sbin/nginx-s reload

 

 

 

Wiki software

[Root @ localhost www] # mysql

Mysql> create database wiki;

Mysql> grant all on wiki. * to wiki @ 'localhost' identified by 'wiki ';

Mysql> flush privileges;

Mysql> quit

Http://kaiyuan.baike.com/download/ (wiki download HDwiki)

[Root @ localhost www] # wget http://kaiyuan.hudong.com/download.php? N=HDWiki-v6.0GBK-20170209.zip (note www)

[Root @ localhost www] # unzip download. php \? N \ =HDWiki-v6.0GBK-20170209.zip

[Root @ localhost www] # rm-f download. php \? N \ =HDWiki-v6.0GBK-20170209.zip

[Root @ localhost www] # mv hdwiki /*.

[Root @ localhost www] # cd ../

[Root @ localhost html] # chown-R nginx. nginx www/

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.