Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Source code compilation and installation of LNMP

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

I. Overview of nginx

LNMP=Linux Nginx Mysql PHP

Nginx ("engine x") is a high-performance HTTP and reverse proxy server. Nginx was developed by Igor Sysoev for the second most visited Rambler.ru site in Russia, and the first public version 0.1.0 was released on October 4, 2004. It distributes the source code as a BSD-like license and is known for its stability, rich feature set, sample configuration files, and low consumption of system resources. Nginx 1.0.4 was released on June 1, 2011.

Nginx is a lightweight Web server / reverse proxy server and email (IMAP/POP3) proxy server, and is distributed under a BSD-like protocol. Developed by Igor Sysoev, a Russian programmer, it is used by Russia's large portal website and search engine Rambler. It is characterized by less memory and strong concurrency ability. in fact, the concurrency ability of nginx does perform well in the same type of web server. Chinese mainland uses nginx website users: Baidu BWS, Sina, NetEase, Tencent and so on.

Nginx official website

RamBler: http://www.rambler.ru/ Nginx: http://nginx.org/

In Nginx, we use php-fpm to parse php pages, and PHP-FPM is actually a patch to PHP source code that integrates FastCGI process management into the PHP package. You must patch it into your PHP source code, and then compile and install PHP before you can use it

Starting from PHP5.3.3, PHP-FPM is directly integrated into PHP, so after the PHP5.3.3 version, there is no need to download the PHP-FPM patch pack. Here is the official notice from PHP-FPM:

Http://php-fpm.org/download

Second, the working principle of Nginx

Nginx itself only supports the processing of static pages. When the client visits the php page, nginx will transfer the php to php-fpm to handle it.

The php-fpm service parses the php page into a html file for nginx processing, and the nginx returns to the client for processing.

Here we need to combine the work of Apache, the difference between the processing process of PHP files.

1:Nginx processes php files through the service php-fpm.

2:Apache processes php files through the module libphp5.so.

Apache:

Nginx:

Apache's libphp5.so runs with the apache server, while Nginx and php-fpm run independently, so Nginx and php-fpm need to be started separately during the operation of the service!

Modify Nginx configuration file, start nginx service, modify php configuration file, start php-fpm service.

3. Installation environment

System environment: CentOS release 6.9 64bit

Software name: libmcrypt-2.5.8, mysql-5.6.26, nginx-1.9.4, pcre-8.37, php-5.6.13

Software installation location: / usr/local/

Data storage location: / usr/local/nginx/html, / usr/local/mysql/data

Log location: / usr/local/nginx/logs, / usr/local/mysql/logs

Fourth, install lnmp

1. Compile and install nginx

1) install the development kit

Yum-y groupinstall "Development Tools"Development Libraries"

2) install dependency packages

Yum-y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* pcre-devel

3) create a lnmp folder in home, and upload the corresponding software package to this folder

[root@centos-6 lnmp] # ll

Total 50292

-rw-r--r-- 1 root root 875425 Jun 10 07:10 libmcrypt-2.5.8.tar.bz2

-rw-r--r-- 1 root root 33278710 Jun 10 07:10 mysql-5.6.26.tar.gz

-rw-r--r-- 1 root root 832104 Jun 10 07:10 nginx-1.8.0.tar.gz

-rw-r--r-- 1 root root 866423 Jun 10 07:11 nginx-1.9.4.tar.gz

-rw-r--r-- 1 root root 1557603 Jun 10 07:10 pcre-8.37.tar.bz2

-rw-r--r-- 1 root root 14077633 Jun 10 07:10 php-5.6.13.tar.bz2

[root@centos-6 lnmp] #

4) decompress the pcre software package

Decompress this installation package, do not need to install, Nginx needs to specify that the source code of pcre is not the path after installation, the function of this package is to support address rewriting rewrite function pcre dependence can be yum installation pcre and pcre-devel solution!

Tar jxvf pcre-8.37.tar.bz2-C / usr/local/src/

5) compile and install nginx

[root@centos-6 lnmp] # tar zxvf nginx-1.9.4.tar.gz-C / usr/local/src/

[root@centos-6 lnmp] # cd / usr/local/src/nginx-1.9.4/ [root@centos-6 nginx-1.9.4] #. / configure-- prefix=/usr/local/nginx-- with-http_dav_module

-with-http_stub_status_module-with-http_addition_module

-with-http_sub_module-with-http_flv_module-with-http_mp4_module

-- with-pcre=/usr/local/src/pcre-8.37

6) function module description:

-- with-http_dav_module # enable support (add PUT,DELETE,MKCOL: create collections, COPY and MOVE methods)

It is turned off by default and needs to be compiled on.

-- with-http_stub_status_module # enable support (get the working status of Nginx since it was last started)

-- with-http_addition_module # enable support (as an output filter, support for incomplete buffering, partial corresponding requests)

-- with-http_sub_module # enable support (allow some other text to replace some text in the corresponding Nginx)

-- with-http_flv_module # enable support (support for flv video files)

-- with-http_mp4_module # enable support (support for mp4 video files and pseudo-streaming media server support)

-- with-pcre=/usr/local/src/pcre-8.37 # Note. This refers to the source code. Use #. / configure-- help | grep pcre to view help

7) use multithreaded compilation to speed up

[root@centos-6 nginx-1.9.4] # make-j 4 & & make install

8) create a nginx running account with no home directory and login permissions

[root@centos-6 lnmp] # useradd-M-s / sbin/nologin nginx

9) configure nginx to support php and modify running users

[root@centos-6 nginx-1.9.4] # vim / usr/local/nginx/conf/nginx.conf

# user nobody

User nginx nginx; # add this line

# 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

#} # find the above paragraph, copy it, remove # and modify it as follows

Location ~\ .php$ {

Root html

Fastcgi_pass 127.0.0.1:9000

Fastcgi_index index.php

Fastcgi_param SCRIPT_FILENAME / usr/local/nginx/html$fastcgi_script_name; # modify scripts to the html of nginx, that is, the Nginx page directory, because the php file to be processed is also in this directory

Include fastcgi_params

}

10) start nginx and check whether the status starts successfully

[root@centos-6 nginx-1.9.4] # / usr/local/nginx/sbin/nginx

[root@centos-6 nginx-1.9.4] # ps-aux | grep nginx

Warning: bad syntax, perhaps a bogus'-'? See / usr/share/doc/procps-3.2.8/FAQ

Root 7715 0.0 0.0 21756 840? Ss 07:38 0:00 nginx: master process / usr/local/nginx/sbin/nginx

Nginx 7716 0.0 0.0 22108 1412? S 07:38 0:00 nginx: worker process

Root 7718 0.0 103328 876 pts/2 S+ 07:38 0:00 grep nginx

[root@centos-6 nginx-1.9.4] # netstat-antup | grep nginx

Tcp 0 0 0.0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0 of the LISTEN 7715/nginx.

[root@centos-6 nginx-1.9.4] #

11) nginx maintenance commands

[root@centos-6 nginx-1.9.4] # / usr/local/nginx/sbin/nginx-tnginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file / usr/local/nginx/conf/nginx.conf test is fulfilling [root @ centos-6 nginx-1.9.4] #

[root@centos-6 nginx-1.9.4] # / usr/local/nginx/sbin/nginx-s reload / / build by reloading the configuration text (smooth restart) smooth restart (keep the CmurS link open, the server only reloads the configuration file, without an action of opening and shutting down the server)

[root@centos-6 nginx-1.9.4] # / usr/local/nginx/sbin/nginx-s stop / / stop Nginx, note: startup does not have any parameters

[root@centos-6 nginx-1.9.4] # echo "/ usr/local/nginx/sbin/nginx &" > > / etc/rc.local

12) check whether nginx is installed successfully

2. Compile and install mysql

1) Clean up installed mysql

[root@centos-6 home] # rpm-qa | grep mysql

Mysql-libs-5.1.73-8.el6_8.x86_64

[root@centos-6 home] # yum remove mysql-libs

[root@centos-6 home] # rpm-qa | grep mysql

[root@centos-6 home] #

2) install dependency packages

[root@centos-6 home] # yum install-y cmake ncurses-devel

3) compile and install mysql

[root@centos-6 lnmp] # tar xf mysql-5.6.26.tar.gz-C / usr/local/src/

3) create an account to run mysql

[root@centos-6 mysql-5.6.26] # useradd-M-s / sbin/nologin mysql

4) configure compilation parameters

[root@centos-6 mysql-5.6.26] # cmake\

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock\

-DDEFAULT_CHARSET=utf8\

-DDEFAULT_COLLATION=utf8_general_ci\

-DWITH_EXTRA_CHARSETS=all\

-DWITH_MYISAM_STORAGE_ENGINE=1\

-DWITH_INNOBASE_STORAGE_ENGINE=1\

-DWITH_MEMORY_STORAGE_ENGINE=1\

-DWITH_READLINE=1\

-DENABLED_LOCAL_INFILE=1\

-DMYSQL_DATADIR=/usr/local/mysql/data\

-DMYSQL-USER=mysql

5) description of compilation parameters

DCMAKE_INSTALL_PREFIX # establishes the installation root directory of mysql, which is automatically created during installation. This value can also be set with-- basedir when the server starts.

The Unix socket file that the DMYSQL_UNIX_ADDR # server communicates with the local client must be an absolute path. The default location / tmp/mysql.sock can be changed with-- socket when the server starts.

DDEFAULT_CHARSET # mysql default character set, does not specify that Latin1 Western European character set will be used by default

DDEFAULT_COLLATION # default character proofreading

DWITH_EXTRA_CHARSETS # formulates the mysql extended character set. The default value is also all supports all character sets.

DWITH_MYISAM_STORAGE_ENGINE # statically compiling MYISAM,INNOBASE,MEMORY storage engine to MYSQL service

So that MYSQL supports these three storage engines

DWITH_INNOBASE_STORAGE_ENGINE

DWITH_MEMORY_STORAGE_ENGINE

DWITH_READLINE # supports readline libraries

DENABLED_LOCAL_INFILE # allows data to be poured locally, enabling loading of local data

DMYSQL_DATADIR # mysql database storage path

DMYSQL-USER # users running mysql

The help of these compilation parameters to find ways:

Http://www.mysql.com →→ Documentation →→ Select the corresponding version (5.6) →→ HTML Online →→ View →→ Installation & Upgrades →→ Installing MySQL from Source →→ MySQL Source-Configuration Options →→

Http://dev.mysql.com/doc/refman/... Ration-options.html

6) compile and install

[root@centos-6 mysql-5.6.26] # make-j 4; make install

/ / accelerate the compilation speed with 4 processes, but do not exceed the number of CPU cores. You need to wait patiently for a long compilation time.

7) configure mysql

[root@centos-6 mysql-5.6.26] # chown-R mysql:mysql / usr/local/mysql/ subordinate group change

[root@centos-6 mysql-5.6.26] # cp / usr/local/mysql/support-files/my-default.cnf / etc/my.cnf / / overwrite the original configuration file

[root@centos-6 mysql-5.6.26] # cp / usr/local/mysql/support-files/mysql.server / etc/init.d/mysqld / / copy startup script

[root@centos-6 mysql-5.6.26] # vim / etc/init.d/mysqld / / change the mysql location specified in the startup script

Basedir=

Datadir=

# modified to

Basedir=/usr/local/mysql

Datadir=/usr/local/mysql/data

[root@centos-6 mysql-5.6.26] # chkconfig mysqld on / / set boot

8) initialize the database

[root@centos-6 mysql-5.6.26] # / usr/local/mysql/scripts/mysql_install_db\

-- defaults-file=/etc/my.cnf\

-- basedir=/usr/local/mysql/\

-- datadir=/usr/local/mysql/data/\

-- user=mysql

Check whether initialization is successful

[root@centos-6 mysql-5.6.26] # ls / usr/local/mysql/data/

Ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema test

[root@centos-6 mysql-5.6.26] #

[root@centos-6 mysql-5.6.26] # ln-s / usr/local/mysql/bin/* / bin/ this contains some commands for the system to call directly

[root@centos-6 mysql-5.6.26] # / etc/init.d/mysqld restart / / start the database

ERROR! MySQL server PID file could not be found!

Starting MySQL.. SUCCESS!

[root@centos-6 mysql-5.6.26] # mysql_secure_installation / initial security settings, setting root password, emergency root remote access, deleting test database, etc.

9) Test whether the login is normal

[root@centos-6 mysql-5.6.26] # mysql- u root-p

Enter password:

Welcome to the MySQL monitor. Commands end with; or\ g.

Your MySQL connection id is 12

Server version: 5.6.26 Source distribution

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

Affiliates. Other names may be trademarks of their respective

Owners.

Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.

Mysql >

3. Compile and install php

1) resolve dependencies

Yum-y install php-pear

/ / pear manages the pear application code base according to certain categories, and you

Pear code can be organized into appropriate directories, and others can easily retrieve and share your results; pear is not only a code repository, it is also a standard, using this standard to write your php code will enhance your program readability, reusability, and reduce the chance of errors. Pear builds a framework for you through two classes that implement functions such as destructors and error trapping, which you can use through inheritance.

PHP adds libmcrypt extension

Libmcrypt encryption algorithm extension library, supports DES, 3DESMagneRIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+ and other algorithms

Official website: http://mcrypt.hellug.gr/index.html or http://mcrypt.sourceforge.net/

Click the link below on the page to download the latest version 2.5.8 (there is a Browse All Files →→ Libmcrypt on the page)

2) install the encryption algorithm extension library

[root@centos-6 lnmp] # tar xf libmcrypt-2.5.8.tar.bz2-C / usr/local/src/; cd / usr/local/src/libmcrypt-2.5.8/

[root@centos-6 libmcrypt-2.5.8] #. / configure-- prefix=/usr/local/libmcrypt; make-j 4; make install

3) in addition to the above dependency solution, you also need to install pictures, xml, font support basic libraries, use yum to install, when installing, these packages also have their own dependencies!

[root@centos-6 libmcrypt-2.5.8] # yum install-y libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype freetype-devel libzip libzip-devel

4) need to add to the library file path

[root@centos-6 libmcrypt-2.5.8] # vim / etc/ld.so.conf

Add the following

Include ld.so.conf.d/*.conf

/ usr/local/libmcrypt/lib # add on this line

/ usr/local/mysql/lib # add on this line

[root@centos-6 libmcrypt-2.5.8] # ldconfig

[root@centos-6 libmcrypt-2.5.8] # echo 'ldconfig' > > / etc/rc.local

5) pressurized php

[root@centos-6 lnmp] # tar xf php-5.6.13.tar.bz2-C / usr/local/src/; cd / usr/local/src/php-5.6.13

[root@centos-6 php-5.6.13] #

6) configure php compilation parameters

[root@centos-6 php-5.6.13] # / configure-prefix=/usr/local/php-- with-config-file-path=/usr/local/php-- with-iconv-dir-- with-freetype-dir-- with-jpeg-dir-- with-png-dir-- with-zlib-- with-libxml-dir=/usr-- enable-xml-- disable-rpath-- enable-bcmath-- enable-shmop-- enable-sysvsem-- enable-inline-optimization-- with- Curl-- enable-mbregex-- enable-fpm-- enable-mbstring-- with-gd-- enable-mysqlnd-- with-openssl-- with-mhash-- enable-pcntl-- enable-sockets-- with-xmlrpc-- enable-soap-- with-gettext-- with-mcrypt=/usr/local/libmcrypt-- with-mysqli=mysqlnd-- with-pdo-mysql=mysqlnd-- with-mysql=mysqlnd

7) description of compilation parameters

-- with-config-file-path # sets the search path for php.ini. Default is PREFIX/lib

-- with-mysql # mysql installation directory, support for mysql

With-mysqli # mysqli extension technology can not only call MySQL stored procedures and handle MySQL transactions, but also make database access more stable. It's a database driver.

-- with-iconv-dir conversion between # character sets

-- with-freetype-dir # turns on support for freetype font library

-- with-jpeg-dir # turns on support for jpeg images

-- with-png-dir # turns on support for png images

-- with-zlib # opens the support of zlib library to achieve GZIP compression output

-- with-libxml-dir=/usr # Open libxml2 library support, libxml is a function library used to parse XML documents

-- enable-xml # supports xml documents

-- disable-rpath # closes additional runtime files

-- enable-bcmath # opens image resizing and uses this module when using zabbix monitoring

-- enable-shmop # shmop shared memory operation function, which can communicate with cUniverse +

-- enable-sysvsem # plus the above shmop, which allows your PHP system to handle related IPC functions (active at the kernel level).

-- enable-inline-optimization # optimize thread

-- with-curl # Open support for curl browsing tool

-- with-curlwrappers # use the curl tool to open the url stream, the new version of PHP5.6 has been deprecated

-- enable-mbregex # supports multibyte regular expressions

-- Startup program installed in enable-fpm # CGI, PHP-FPM service

-- enable-mbstring # multi-byte string support

-- with-gd # support for opening the gd library, which is an extension of php to process graphics. The GD library provides a series of API for processing pictures. You can use the GD library to process pictures or generate pictures.

-- enable-gd-native-ttf # supports TrueType string function library

-- with-openssl # turn on ssl support

-- with-mhash # supports extension of mhash algorithm

-- needed by enable-pcntl # freeTDS. Pcntl extension can support multithreaded operation of php.

-- enable-sockets # turn on sockets support

-- with-xmlrpc # Open the c language of xml-rpc

-- enable-zip # turns on support for zip

The enable-soap # extension library realizes the data interaction between the customer server and the server through the soap protocol.

-- with-mcrypt # mcrypt algorithm extension

-- with-zlib-dir=/usr/local/libzip # # specify the zip library path

8) compile and install

[root@centos-6 php-5.6.13] # make-j 3 & & make install

9) configure php and php-fpm

[root@centos-6 php-5.6.13] # cp / usr/local/src/php-5.6.13/php.ini-production / usr/local/php/php.ini / / replace php configuration file

[root@centos-6 php-5.6.13] # cp / usr/local/php/etc/php-fpm.conf.default / usr/local/php/etc/php-fpm.conf / / replace php-fpm configuration file

[root@centos-6 php-5.6.13] # chown-R nginx:nginx / usr/local/php/etc/php-fpm.conf / / modify php-fpm.conf file permissions

[root@centos-6 nginx] # vim / usr/local/php/etc/php-fpm.conf / / modify the php-fpm running account to nginx

Set

User = nobody

Group = nobody

Change to

User = nginx

Group = nginx

10) configure php-fpm startup script and configure random startup

[root@centos-6 php-5.6.13] # cp / usr/local/src/php-5.6.13/sapi/fpm/init.d.php-fpm / etc/init.d/php-fpm

[root@centos-6 php-5.6.13] # chmod + x / etc/init.d/php-fpm

[root@centos-6 php-5.6.13] # chkconfig php-fpm on

[root@centos-6 php-5.6.13] # / etc/init.d/php-fpm start

Starting php-fpm done

11) Test whether the php interpretation is valid

[root@centos-6 php-5.6.13] # echo "" > / usr/local/nginx/html/info.php

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report