LNMPIntroduction
LAMP(Linux apache mysql php)---Earlierweb service.
LNMP(Linux nginx mysql php)---More trendy and new The webn service has an increasing usage rate (very popular in China).
Nginx (Engine X) is developed by Russians and is open sourcewww Service software, the software totals 780K (very small), it is a static (html, js, css, jpg, etc.) wwwSoftware, small static files have high concurrency and occupy very few resources.
NginxUse platform (linux unix windows is OK) and apacheSame.
Nginx Functions:
a.www webService---http 80
b.Load balancing (reverse proxyproxy)
c.web cache
nginxAdvantages:
1. Simple configuration and flexibility.
2.High concurrency (static small files), static 1-2W.
3. Occupies few resources, 2W concurrently opens 10 thread services, and consumes hundreds of megabytes of memory.
4.There are many types of functions (web cache proxyproxy), and each function is not very strong.
5.Supports the epoll model, making nginx support high concurrency.
6.nginxThere is a difference between working with dynamic services and apache.
7.Use nginx to limit the speed of IP. The number of connections can be limited.
Implementation principle: nginx(apache)- -》php--》mysql
nginx Application scenarios:
1.Static service (pictures, videos), the other lighttpd (the community is not active). Concurrency: 1-3W, html, js, css、.flv
2.Dynamic service: nginx+fastcgi way to run php, jsp. Concurrency: 500-1500, similar to apache+php, lighttpd+fcgi php
3.Reverse proxy, load balancing. For products below PV2000W, you can use nginx as an agent. haproxy,F5,a10
4.Cache Service, SQUID,VARNI.
nginx Comparison with other web servers:
1) apache
a. Stable and powerful
b. Prefork mode cancels the process creation overhead and has high performance.
c.When processing dynamic business data, because it is associated with the back-end engine and database, the bottleneck is not apache itself
d. High concurrency consumes relatively more system resources
e.Based on the traditional select model
2) nginx
a. Based on the asynchronous IO model (epoll, kqueue), strong performance, able Supports tens of thousands of concurrency
b. Very good support for small files, high performance (limited to small static files)
c. Beautiful code, extension library must be compiled for the main program
d. Resource consumption is relatively low
3) Lighttpd (Baidu Tieba, Douban)
a.Based on asynchronous IOModel, performance is similar to nginx
b.The extension is SO mode, better than nginxBe flexible
c.The global usage rate is low, and the security is not as good asapache andnginxGood
d.File URL address encryption can be achieved through the plug-in (mod secdownload)
How to choose web server (recommended) in enterprise production scenarios:
Static business: For high concurrency, use nginx or lighttpd
Dynamic business: use nginx and apache Both
Both dynamic and static services: nginx and apache both Yes, single choice
External businessnginx, Internal businessapache
Installation, configurationnginx
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.Startup check:
[root@localhost application]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx1.12.0/conf/nginx.conf syntax is ok
nginx: the 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(Also80 The port can also be checked)
The appearance of this interface indicates success
[root@localhost application]# vim /application/nginx/html/index.html Modify homepage content
4.About nginx module
1)Nginx core modules(required), includingMain Events
2)Standard HTTP modules (Although it is not required, it will be installed by default and it is not recommended to change it), including Core Acess FastCGI Gzip (Compression module, performance optimization) LOG (Log module) Proxy Rewrite( URLRewriting module) Upstream (Load balancing module) etc.
Tips: Under default conditions, Both sets of modules will be installed. Modifying the configuration file mainly involves modifying the parameters of the module based on the functions of this 2 group of modules. The parameters of the module can be viewed on the official website.
5.nginx configuration
[root@localhost conf]# egrep -v "#|^$" nginx. conf.default >nginx.conf (remove the 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 windowslocalhosts file to ensure it is in winIn the command prompt, ping can be passed from the virtual host, and then go to the web page to view
Add status server tag:
[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;
}
}
在winLocalhostsAlso add ,
to the file
Solution to malicious domain name binding:
[root@localhost conf]# vim /application/nginx/conf/nginx.conf (must be placed first server)
server {
listen 80;
location / {
deny all;
}
}
Enable logging function:
[root@localhost conf]# cat /application/nginx/conf/nginx.conf.default (Find the log format)
#log_format $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
Copy tonginx.conf and remove the comments
##Error log format is placed at the topSoftware for analyzing
nginxlog:syslog,rsyslog,Awstats,scribe,kafka
MysqlmysqlInstallation method:
5.1---Compile and install
configure,make,make install5.5---Compile Install
cmake, make, make install (you can install it directly with the binary package , just unzip it)
1.Installation
mysql[root@localhost conf]# useradd mysql -s /sbin/ nologin -M
[root@localhost tools]# 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 needs to 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
(The configuration file of each version is different)
cp: Do you want to 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 password (enter mysqlModify)mysql> set password for root@localhost = password('123');
PHP
php under LNMP:
apache----》libphp5.so
nginx---》fcgi php-fpm port9000(Baidu)
InstallationphpBefore making suremysql, nginx is running normally[root@localhost mysql]# netstat -lntup|egrep "nginx|mysql"
1.Software that needs to be installed
Installationlibiconv(./configure --prefix=/usr/local/libiconv)
Installationlibmcrypt (Not required, recommended to install) It is an encrypted library
./configure
make
make install
sleep2
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../cd
Installmhash
./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.8
ln -s /usr/local/lib64/libmhash.a /usr/lib64/libmhash.a
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
Installationmcrypt
/sbin/ldconfig
./configure LD_LIBRARY_PATH=/usr/local/ lib
make
make install
cd ../
sleep 2
2.Installphp
[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: ,,
3.phpConfiguration
[root@localhost php-5.3.27]# cp php.ini-production /application/php/lib/php.ini
Upload directly
[root@localhost etc]# /application/php/sbin/php-fpm -t
[root@localhost etc]# /application/php/sbin/php-fpm
Boot up
cat >>/etc/rc.local< #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 root html/bbs; index index.html index.htmi index.php; Location ~ .*\.(php|php5)?$ #Not specified at this time{} Directory, directly read the php file { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } Software mysql> create database wiki; (wiki [root@localhost www]# wget (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 The above is the detailed content of linux+Nginx+Mysql+Php icon, detailed operation steps!. For more information, please follow other related articles on the PHP Chinese website!