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

Build a LNMP environment (based on minimizing installation of CentOS 6.5)

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

Share

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

This document mainly describes the steps to manually install the LNMP environment on a single server. The system version used in this document may be different from your actual version, and you can choose the appropriate version according to the actual situation.

1. Release notes for the LNMP environment of this document:

OS: minimize installation of CentOS 6.5

Nginx:nginx-1.10.2.tar.gz

MySQL:mysql-5.6.24.tar.gz

PHP:php-5.6.23.tar.bz2

Second, the basic steps of building a LNMP environment

1. Prepare the compilation environment

two。 Install nginx

3. Install mysql

4. Install php-fpm

5. Test access

Step 1: prepare the compilation environment

1. Minimize the installation of CentOS6.5 (brief steps)

# cat / etc/redhat-release

CentOS release 6.5 (Final)

2. Close SELINUX

# sed-I's bind SELINUXPROTHERMY SELINUXPROUX.SELINUXPROUXING / etc/selinux/config

# setenforce 0

3. Configure the firewall and open port 80

# vi / etc/sysconfig/iptables

-An INPUT-m state-- state NEW-m tcp-p tcp-- dport 80-j ACCEPT

# service iptables restart

Step 2: install nginx

1. Add a user running the nginx service process

# groupadd-r nginx

# useradd-r-g nginx nginx

2. Download the source code package, decompress and compile.

# yum-y install wget gcc gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel

# wget http://nginx.org/download/nginx-1.10.2.tar.gz

# tar xvf nginx-1.10.2.tar.gz-C / usr/local/src

# cd / usr/local/src/nginx-1.10.2

#. / configure\

-- prefix=/usr/local/nginx\

-- sbin-path=/usr/sbin/nginx\

-- conf-path=/etc/nginx/nginx.conf\

-- error-log-path=/var/log/nginx/error.log\

-- http-log-path=/var/log/nginx/access.log\

-- pid-path=/var/run/nginx.pid\

-- lock-path=/var/run/nginx.lock\

-- http-client-body-temp-path=/var/tmp/nginx/client\

-- http-proxy-temp-path=/var/tmp/nginx/proxy\

-- http-fastcgi-temp-path=/var/tmp/nginx/fcgi\

-- http-uwsgi-temp-path=/var/tmp/nginx/uwsgi\

-- http-scgi-temp-path=/var/tmp/nginx/scgi\

-- user=nginx\

-- group=nginx\

-- with-pcre\

-- with-http_v2_module\

-- with-http_ssl_module\

-- with-http_realip_module\

-- with-http_addition_module\

-- with-http_sub_module\

-- with-http_dav_module\

-- with-http_flv_module\

-- with-http_mp4_module\

-- with-http_gunzip_module\

-- with-http_gzip_static_module\

-- with-http_random_index_module\

-- with-http_secure_link_module\

-- with-http_stub_status_module\

-- with-http_auth_request_module\

-- with-mail\

-- with-mail_ssl_module\

-- with-file-aio\

-- with-ipv6\

-- with-http_v2_module\

-- with-threads\

-- with-stream\

-- with-stream_ssl_module

# make & & make install

# mkdir-pv / var/tmp/nginx/client

3. Add SysV startup script

# vi / etc/init.d/nginx

#! / bin/sh

#

# nginx-this script starts and stops the nginx daemon

#

# chkconfig:-85 15

# description: Nginx is an HTTP (S) server, HTTP (S) reverse\

# proxy and IMAP/POP3 proxy server

# processname: nginx

# config: / etc/nginx/nginx.conf

# config: / etc/sysconfig/nginx

# pidfile: / var/run/nginx.pid

# Source function library.

. / etc/rc.d/init.d/functions

# Source networking configuration.

. / etc/sysconfig/network

# Check that networking is up.

["$NETWORKING" = "no"] & & exit 0

Nginx= "/ usr/sbin/nginx"

Prog=$ (basename $nginx)

NGINX_CONF_FILE= "/ etc/nginx/nginx.conf"

[- f / etc/sysconfig/nginx] & &. / etc/sysconfig/nginx

Lockfile=/var/lock/subsys/nginx

Start () {

[- x $nginx] | | exit 5

[- f $NGINX_CONF_FILE] | | exit 6

Echo-n $"Starting $prog:"

Daemon $nginx-c $NGINX_CONF_FILE

Retval=$?

Echo

[$retval-eq 0] & & touch $lockfile

Return $retval

}

Stop () {

Echo-n $"Stopping $prog:"

Killproc $prog-QUIT

Retval=$?

Echo

[$retval-eq 0] & & rm-f $lockfile

Return $retval

Killall-9 nginx

}

Restart () {

Configtest | | return $?

Stop

Sleep 1

Start

}

Reload () {

Configtest | | return $?

Echo-n $"Reloading $prog:"

Killproc $nginx-HUP

RETVAL=$?

Echo

}

Force_reload () {

Restart

}

Configtest () {

$nginx-t-c $NGINX_CONF_FILE

}

Rh_status () {

Status $prog

}

Rh_status_q () {

Rh_status > / dev/null 2 > & 1

}

Case "$1" in

Start)

Rh_status_q & & exit 0

, 1

Stop)

Rh_status_q | | exit 0

, 1

Restart | configtest)

, 1

Reload)

Rh_status_q | | exit 7

, 1

Force-reload)

Force_reload

Status)

Rh_status

Condrestart | try-restart)

Rh_status_q | | exit 0

*)

Echo $"Usage: $0 {start | stop | status | restart | condrestart | try-restart | reload | force-reload | configtest}"

Exit 2

Esac

4. Give the script the right to execute.

# chmod + x / etc/init.d/nginx

5. Add it to the service management list and set it to boot.

# chkconfig-add nginx

# chkconfig nginx on

6. start the service.

# service nginx start

7. Browser access test.

Step 3: install mysql

1. Prepare the compilation environment.

# yum install ncurses-devel

# yum install cmake

2. Prepare the mysql data storage directory and add users running the mysql service process.

# mkdir-pv / data/mysql

# groupadd-r mysql

# useradd-r-g mysql-s / sbin/nologin mysql

# id mysql

Uid=497 (mysql) gid=498 (mysql) groups=498 (mysql)

3. Change the data directory to belong to the master group.

# chown-R mysql:mysql / data/mysql

4. Decompress and compile the stable version of the source code package downloaded on the MySQL official website. Version 5.6.24 is used here.

# wget https://downloads.mysql.com/archives/get/file/mysql-5.6.24.tar.gz

# tar xvf mysql-5.6.24.tar.gz-C / usr/local/src

# cd / usr/local/src/mysql-5.6.24

# cmake. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql\

-DMYSQL_DATADIR=/data/mysql\

-DSYSCONFDIR=/etc\

-DWITH_INNOBASE_STORAGE_ENGINE=1\

-DWITH_ARCHIVE_STORAGE_ENGINE=1\

-DWITH_BLACKHOLE_STORAGE_ENGINE=1\

-DWITH_READLINE=1\

-DWITH_SSL=system\

-DWITH_ZLIB=system\

-DWITH_LIBWRAP=0\

-DMYSQL_TCP_PORT=3306\

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock\

-DDEFAULT_CHARSET=utf8\

-DDEFAULT_COLLATION=utf8_general_ci

# make & & make install

5. Change the affiliated group of the installation directory to mysql.

# chown-R mysql:mysql / usr/local/mysql/

6. Initialize the database.

# / usr/local/mysql/scripts/mysql_install_db-user=mysql-datadir=/data/mysql-basedir=/usr/local/mysql

7. Copy configuration files and startup scripts.

# cp / usr/local/mysql/support-files/mysql.server / etc/init.d/mysqld

# chmod + x / etc/init.d/mysqld

# mv / etc/my.cnf / etc/my.cnf.bak / / after the minimum installation of CentOS 6.5, there is a my.cnf in the / etc directory and rename this file.

# cp / usr/local/mysql/support-files/my-default.cnf / etc/my.cnf

8. Set the boot to start automatically.

# chkconfig mysqld on

# chkconfig-add mysqld

9. Modify the installation path and data directory storage path in the configuration file.

# echo-e "basedir = / usr/local/mysql\ ndatadir = / data/mysql\ n" > > / etc/my.cnf

10. Set the PATH environment variable.

# echo "export PATH=$PATH:/usr/local/mysql/bin" > / etc/profile.d/mysql.sh

# source / etc/profile.d/mysql.sh

Start the service.

# service mysqld start

# mysql-h 127.0.0.1 / / login authentication MySQL

12. Run mysql security tools, set root account password, delete anonymous users, do not allow root remote login, delete test library, etc.

# / usr/local/mysql/bin/mysql_secure_installation

13. (optional steps in the following steps) establish application database app1_db, application account app1_user and authorize.

# mysql-h 127.0.0.1-uroot-p

Mysql > create database app1_db

Mysql > grant all privileges on app1_db.* to 'app1_user'@'%' identified by' app1_password' with grant option

Mysql > flush privileges

Mysql > exit

Step 4: install php-fpm

Nginx itself can not handle PHP, as a web server, when it receives the request, it does not support the direct call or parsing of external programs, it must be called through FastCGI. If it is a PHP request, it is handed over to the PHP interpreter and the result is returned to the client. PHP-FPM is a FastCGI process manager that supports parsing php. Provides a better way to manage PHP processes, effectively control memory and processes, and smoothly reload PHP configuration.

1. Install dependency packages.

# yum install-y epel-release / / install the epel extension source to install libmcrypt, etc.

# yum install libmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2 bzip2-devel

2. Decompress the php source code package downloaded from the official website, compile and install it.

# wget http://cn.php.net/distributions/php-5.6.23.tar.bz2

# tar xvf php-5.6.23.tar.bz2-C / usr/local/src

# cd / usr/local/src/php-5.6.23

#. / configure-prefix=/usr/local/php\

-- with-config-file-scan-dir=/etc/php.d\

-- with-config-file-path=/etc\

-- with-mysql=/usr/local/mysql\

-- with-mysqli=/usr/local/mysql/bin/mysql_config\

-- enable-mbstring\

-- with-freetype-dir\

-- with-jpeg-dir\

-- with-png-dir\

-- with-zlib\

-- with-libxml-dir=/usr\

-- with-openssl\

-enable-xml\

-- enable-sockets\

-- enable-fpm\

-- with-mcrypt\

-- with-bz2

# make & & make install

3. Add php and php-fpm configuration files.

# cp / usr/local/src/php-5.6.23/php.ini-production / etc/php.ini

# cd / usr/local/php/etc/

# cp php-fpm.conf.default php-fpm.conf

# sed-I's pid = run/php-fpm.pid@pid = / usr/local/php/var/run/php-fpm.pid@' php-fpm.conf

4. Add php-fpm startup script.

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

# chmod + x / etc/init.d/php-fpm

5. Add php-fpm to the service list and set it to boot automatically.

# chkconfig-add php-fpm

# chkconfig php-fpm on

6. start the service.

# service php-fpm start

7. To add nginx's support for fastcgi, first back up the default configuration file.

# cp / etc/nginx/nginx.conf / etc/nginx/nginx.conf.bak

# cp / etc/nginx/nginx.conf.default / etc/nginx/nginx.conf

Edit / etc/nginx/nginx.conf and add the php format, similar to the following:

Location / {

Root / usr/local/nginx/html

Index index.php index.html index.htm

}

Uncomment the following:

Location ~\ .php$ {

Root / usr/local/nginx/html

Fastcgi_pass 127.0.0.1:9000

Fastcgi_index index.php

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

Include fastcgi_params

}

Reload the configuration file for nginx.

# service nginx reload

Create a new test page for index.php in / usr/local/nginx/html/, as follows.

Note: in the following test content, the database account is root and the password is p@ssw0rd.

# cat index.php

Browser access test, if you see the following, it means that the LNMP environment has been built.

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