Home Operation and Maintenance Linux Operation and Maintenance linux+Nginx+Mysql+Php icon, detailed operation steps!

linux+Nginx+Mysql+Php icon, detailed operation steps!

Jun 23, 2017 pm 02:17 PM
php Steps Detailed explanation

LNMPIntroduction

LAMPLinux apache mysql php---Earlierweb service.

LNMPLinux 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: nginxapache- -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

1Nginx 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 to

nginx.conf and remove the comments

##Error log format is placed at the top

Software for analyzing

nginx

log:syslog,rsyslog,Awstats,scribe,kafka

Mysql

mysql

Installation 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;

}

## }

[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

(wiki

下载

HDwiki)

[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

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

[root@localhost www]# cd ../

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

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles