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

How to configure the LNMP environment

2025-04-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the relevant knowledge of how to configure the LNMP environment, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to configure the LNMP environment. Let's take a look.

LNMP environment configuration concept

LNMP is short for Linux Nginx MySQL PHP. Nginx, MySQL, and PHP are installed on the Linux system to form an environment to run PHP's scripting language.

Nginx is a kind of Web service software similar to Apache.

MySQL is a relatively small database software.

Apache and PHP need to be on the same machine.

(install c compiled language first)

Install MySQL

Switch directories

Download the source package

Decompression

Rename a file

Move position

Establish MySQL user

Create a datadir, and the database file will be put into it.

Change permissions

Possible installation packages (error occurred)

Finally (two ok appear)

Copy Profil

Configuration file

# vi / etc/my.cnf

Basedir is the path where the MySQL package is located

Datadir is a defined place to store data

Port defines the port on which the MySQL service listens (default is 3306)

Server_id defines the ID number

Socket defines the socket address that the service listens to

Copy the startup script file and modify its properties

Modify startup script

# vi / etc/init.d/mysqld

Add the startup script to the system service item and set the boot

Check if MySQL is started (more than two lines)

Install PHP

Download PHP

Configure compilation options

. / 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-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\

>-- disable-ipv6\

>-- with-pear\

>-- with-curl\

>-- with-openssl

Possible errors

Compilation and installation

Modify the configuration file

# cp php.ini-production / usr/local/php-fpm/etc/php.ini

# vi / usr/local/php-fpm/etc/php-fpm.conf

Write the following

[global]

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

Listen.mode = 666,

User = php-fpm

Group = php-fpm

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

Verify that the configuration is correct

Copy Profil

# cp / usr/local/src/php-5.6.30/sapi/fpm/init.d.php-fpm / etc/init.d/php-fpm

Set permissions

# chmod 755 / etc/init.d/php-fpm

Create a user

# useradd-s / sbin/nologin php-fpm

Start php-fpm

Set up boot boot

Detect whether or not to start

Install Nginx

Download nginx

Decompression

Configure compilation options

Compile and install

Write a startup script

Add the following

#! / bin/bash

# chkconfig:-30 21

# description: http service.

# Source Function Library

. / etc/init.d/functions

# Nginx Settings

NGINX_SBIN= "/ usr/local/nginx/sbin/nginx"

NGINX_CONF= "/ usr/local/nginx/conf/nginx.conf"

NGINX_PID= "/ usr/local/nginx/logs/nginx.pid"

RETVAL=0

Prog= "Nginx"

Start ()

{

Echo-n $"Starting $prog:"

Mkdir-p / dev/shm/nginx_temp

Daemon $NGINX_SBIN-c $NGINX_CONF

RETVAL=$?

Echo

Return $RETVAL

}

Stop ()

{

Echo-n $"Stopping $prog:"

Killproc-p $NGINX_PID $NGINX_SBIN-TERM

Rm-rf / dev/shm/nginx_temp

RETVAL=$?

Echo

Return $RETVAL

}

Reload ()

{

Echo-n $"Reloading $prog:"

Killproc-p $NGINX_PID $NGINX_SBIN-HUP

RETVAL=$?

Echo

Return $RETVAL

}

Restart ()

{

Stop

Start

}

Configtest ()

{

$NGINX_SBIN-c $NGINX_CONF-t

Return 0

}

Case "$1" in

Start)

Start

Stop)

Stop

Reload)

Reload

Restart)

Restart

Configtest)

Configtest

*)

Echo $"Usage: $0 {start | stop | reload | restart | configtest}"

RETVAL=1

Esac

Exit $RETVAL

Change permissions after saving

Set up boot boot

Change the configuration file

Empty the configuration file

Write a startup script

# vi / usr/local/nginx/conf/nginx.conf

Add the following

User nobody nobody

Worker_processes 2

Error_log / usr/local/nginx/logs/nginx_error.log crit

Pid / usr/local/nginx/logs/nginx.pid

Worker_rlimit_nofile 51200

Events

{

Use epoll

Worker_connections 6000

}

Http

{

Include mime.types

Default_type application/octet-stream

Server_names_hash_bucket_size 3526

Server_names_hash_max_size 4096

Log_format combined_realip'$remote_addr $http_x_forwarded_for [$time_local]'

'$host "$request_uri" $status'

'"$http_referer"$http_user_agent"'

Sendfile on

Tcp_nopush on

Keepalive_timeout 30

Client_header_timeout 3m

Client_body_timeout 3m

Send_timeout 3m

Connection_pool_size 256

Client_header_buffer_size 1k

Large_client_header_buffers 8 4k

Request_pool_size 4k

Output_buffers 4 32k

Postpone_output 1460

Client_max_body_size 10m

Client_body_buffer_size 256k

Client_body_temp_path / usr/local/nginx/client_body_temp

Proxy_temp_path / usr/local/nginx/proxy_temp

Fastcgi_temp_path / usr/local/nginx/fastcgi_temp

Fastcgi_intercept_errors on

Tcp_nodelay on

Gzip on

Gzip_min_length 1k

Gzip_buffers 4 8k

Gzip_comp_level 5

Gzip_http_version 1.1

Gzip_types text/plain application/x-javascript text/css text/htm

Application/xml

Server

{

Listen 80

Server_name localhost

Index index.html index.htm index.php

Root / usr/local/nginx/html

Location\ .php$

{

Include fastcgi_params

Fastcgi_pass unix:/tmp/php-fcgi.sock

Fastcgi_index index.php

Fastcgi_param SCRIPT_FILENAME / usr/local/nginx/html$fastcgi_script_name

}

}

}

Verify configuration

Start nginx

Detect whether or not to start

Test whether you can parse correctly

test

This is the end of the article on "how to configure the LNMP environment". Thank you for reading! I believe you all have a certain understanding of "how to configure the LNMP environment". If you want to learn more, you are welcome to follow the industry information channel.

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: 233

*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

Development

Wechat

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

12
Report