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

Introduction to LNMP architecture, working mode and installation of MySQL and PHP

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

The following content mainly brings you LNMP architecture, working mode and MySQL, PHP installation introduction, the knowledge mentioned is slightly different from books, are summarized by professional and technical personnel in the process of contact with users, have a certain experience sharing value, hope to bring help to the majority of readers.

Introduction to LNMP Architecture

What LNMP represents is the website cloud server architecture of Nginx+MySQL+PHP under Linux system. PHP in Nginx is combined with Nginx in the way of fastcgi, which can be understood as that Nginx proxies the fastcgi of PHP.

LNMP working mode

Unlike LAMP, web service is provided by Nginx and php exists as an independent service. This service is called php-fpmNginx to handle static requests directly, and dynamic requests are forwarded to php-fpm. The performance of static file processing is higher than that of apache. User concurrency support is very large, which can be tens of thousands. Apache cannot install MySQL.

Download and extract the source package

Download the package:

[root@localhost src] # wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36.tar.gz

Decompress:

[root@localhost src] # tar-zxv-f mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz

Move the extracted file and modify the file name:

Move the extracted mysql-5.6.35-linux-glibc2.5-x86_64 file to the / usr/local/ directory and rename it mysql.

[root@localhost src] # mv mysql-5.6.35-linux-glibc2.5-x86_64 / usr/local/mysql

Change to the / usr/lcoal/mysql/ directory

[root@localhost src] # cd / usr/local/mysql/

Create an account and / data/ directory:

[root@localhost mysql] # useradd mysql

[root@localhost mysql] # mkdir / data/

Configure mysql

[root@localhost mysql] # / scripts/mysql_install_db-- user=mysql-- datadir=/data/mysql

# if there are two ok during installation, the installation is successful. Or use the command echo $? Command, if the output is 0, the installation is successful. The result is 1, the installation fails.

Copy configuration fil

The directory of the configuration file is: / usr/local/mysql/support-files/my-default.cnf

[root@localhost mysql] # cp support-files/my-default.cnf / etc/my.cnf

The configuration file for mysql is fixed under / etc/ and is named my.cnf (if you need to specify it for another directory, otherwise the system will only look for the / etc/my.cnf file. )

You cannot copy the configuration file, directly use the ready-made / etc/my.cnf file, edit this file, and modify the following:

Datadir=/data/mysql

Socket=/tmp/mysql.sock

Comment out these three lines:

Log _ r _ r / etc/my.cnf.d

Startup script

The startup script directory is: / usr/local/mysql/support-files/mysql.server

Copy the startup script to the / etc/init.d/ directory and rename it to: mysqld

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

Edit the / etc/init.d/mysqld file:

Basedir=/usr/local/mysql

Datadir=/data/mysql

(line 46, line 47)

Permission change:

Change the file permissions to 755 (default is 755, no need to change)

Chmod 755 / etc/init.d/mysqld

Set boot up and add the service to the list of system services:

[root@localhost mysql] # chkconfig-- add mysqld

[root@localhost mysql] # chkconfig-- list

Note: this output shows only SysV services and does not include native systemd services. SysV configuration data may be overwritten by native systemd configurations.

If you want to list systemd services, execute 'systemctl list-unit-files'.

To see which services are enabled for a specific target, execute

'systemctl list-dependencies [target]'.

Mysqld 0: off 1: off 2: on 3: on 4: on 5: on 6: off

You can also start it directly with the command:

/ etc/init.d/mysqld startservice mysqld start

[root@localhost mysql] # service mysqld start

Starting MySQL.Logging to'/ data/mysql/localhost.localdomain.err'.

. SUCCESS! # started successfully

You can use the command:

Ps aux | grep mysqld to view the process

Netstat-lntp view listening port

Stop the mysqld service

Service mysqld stop

Start on the command line (& start in the background):

/ usr/local/mysql/bin/mysqld_safe-defaults-file=/etc/my.cnf-user=mysql-datadir=/data/mysql &

PHP installation if you have previously installed PHP, you need to clear its original configuration: [root@localhost src] # cd php-5.6.30 [root@localhost src] # make clean

Download and extract PHP

Download the package:

[root@localhost php] # wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2

Extract the package:

[root@localhost php] # tar-jxv-f php-7.1.6.tar.bz2

Move the package to / usr/local/ and rename it to php

[root@localhost php] # mv php-7.1.6 / usr/local/php

Configuration

[root@localhost src] # cd / usr/local/php/

[root@localhost php] # / configure-- prefix=/usr/local/php-fpm-- with-config-file-path=/usr/local/php-fpm/etc-- enable-fpm-- with-fpm-user=php-fpm-- with-fpm-group=php-fpm-- with-pdo-mysql=/usr/local/mysql-- with-mysqli=/usr/local/mysql/bin/mysql_config-- with-pdo-mysql=/usr/local/mysql-- with-mysql-sock=/tmp/mysql.sock -with-libxml-dir-- with-gd-- with-jpeg-dir-- with-png-dir-- with-freetype-dir-- with-iconv-dir-- with-zlib-dir-- with-mcrypt-- enable-soap-- enable-gd-native-ttf-- enable-ftp-- enable-mbstring-- enable-exif-- with-pear-- with-curl-- with-openssl

Additional packages may need to be installed during configuration, as detailed in php installation.

Compile and install

[root@localhost php] # make

.

[root@localhost php] # echo $?

0

[root@localhost php] # make install

.

[root@localhost php] # echo $?

0

See which modules are loaded by php-fpm

[root@localhost php] # / usr/local/php-fpm/sbin/php-fpm-m

Check the php-fpm configuration file

[root@localhost php] # / usr/local/php-fpm/sbin/php-fpm-t

Configure php-fpm

Create a php-fpm user

[root@localhost php] # useradd-s / sbin/nologin php-fpm

This account is used to run php-fpm services, because in a LNMP environment, PHP exists independently as a service.

Add the php profile to the php-fpm profile directory

[root@localhost php] # cp php.ini-production / usr/local/php-fpm/etc/php.ini

Configuration file

Change to the / usr/lcoal/php-fpm/etc directory:

[root@localhost php] # cd / usr/local/php-fpm/etc

Add the php-fpm.conf file and add the following:

[root@localhost etc] # vim php-fpm.conf

[global]

# define global parameters

Pid = / usr/local/php-fpm/var/run/php-fpm.pid

Error_log = / usr/local/php-fpm/var/log/php-fpm.log

[www]

Listen = / tmp/php-fcgi.sock

# listener address, you can also write: listen = 127.0.0.1 IP:port 9000, local listener, or other listener

# the format here will affect the path of Nginx addressing PHP when configuring the combination of Nginx and PHP

Listen.mode = 666,

# this part takes effect only when listening to socket files, which is used to specify the permissions of .sock files

User = php-fpm

Group = php-fpm

# define the user of php-fpm service

Pm = dynamic

Pm.max_children = 50

Pm.start_servers = 20

Pm.min_spare_servers = 5

Pm.max_spare_servers = 35

Pm.max_requests = 500,

Rlimit_files = 1024

# the above parts are process-related information

Check the configuration document for errors:

[root@localhost etc] # / usr/local/php-fpm/sbin/php-fpm-t

[02-Jan-2018 23:18:03] NOTICE: configuration file / usr/local/php-fpm/etc/php-fpm.conf test is successful

Configure startup script

Change to / usr/local/php/ directory

[root@localhost etc] # cd / usr/local/php/

Add the startup script to the system configuration file:

[root@localhost php] # cp sapi/fpm/init.d.php-fpm / etc/init.d/php-fpm

Change file permissions:

[root@localhost php] # chmod 755 / etc/init.d/php-fpm

Set up boot boot

[root@localhost php] # chkconfig-- add php-fpm

[root@localhost php] # chkconfig php-fpm on

Start the php-fpm service:

[root@localhost php] # service php-fpm start

Starting php-fpm done

Check to see if the service started successfully:

[root@localhost etc] # ps aux | grep php

Nginx introduction

Nginx ("engine x") is a lightweight Web server / reverse proxy server and email (IMAP/POP3) proxy server, and is distributed under a BSD-like protocol. 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, Sina, NetEase, Tencent, Taobao and so on.

Nginx application scenarios:

Web server, reverse proxy, load balancer

For the above introduction of LNMP architecture, working mode and MySQL and PHP installation, if you have more information, you can continue to pay attention to the innovation of our industry. If you need professional solutions, you can contact the pre-sales and after-sales on the official website. I hope this article can bring you some knowledge updates.

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

Database

Wechat

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

12
Report