LNMP environment setup (Discuz Forum)

Source: Internet
Author: User
Tags install openssl

LNMP environment setup (Discuz Forum)

I. Operating System Environment and software version

Operating System: CentOS release 6.5 (Final) minimal

Kernel version: 2.6.32-431. el6.x86 _ 64

MySQL version: MySQL-5.6.28

Nginx version: nginx-1.8.1

Php version: php-5.6.19

2. Install MySQL-5.6.28

Obtain the URL: http://mirrors.sohu.com/mysql/self-selected version

Mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz this version is the official compiled version, unzip the direct initialization can be used, if you use the source code compilation and installation needs to note that MySQL5.5 version to use cmake for compilation, the need to install cmake in advance.

Decompress mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz

# Tar-zxvf mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz

Move the extracted file to/usr/local/and name it mysql.

# Music mysql-5.6.28-linux-glibc2.5-x86_64/usr/local/mysql

Creating a mysql user does not have a home directory and cannot log on

# Useradd-M mysql-s/sbin/nologin

Create a database file storage location

# Mkdir-p/database/mysql

Change owner and group to mysql

# Chown-R mysql. mysql/database/mysql/

Initialize Database

#./Scripts/mysql_install_db -- user = mysql -- datadir =/database/mysql

Add the binary bin directory of mysql to your environment variables.

# Vim ~ /. Bash_profile

Add/usr/local/mysql/bin to PATH

# Source ~ /. Bash_profile

Configure the mysql environment and start it automatically

# Cp mysql. server/etc/init. d/mysqld

Be sure to execute this. Otherwise, you will regret it and will not explain it.

# Sed-I's # ^ datadir = # datadir =/database/mysql # '/etc/init. d/mysqld

# Chkconfig -- add mysqld

# Chkconfig mysqld on

Edit the mysql configuration file

# Vim/usr/local/mysql/my. cnf

Add the following configurations without configuring Master/Slave:

Basedir =/usr/local/mysql

Datadir =/database/mysql/data

Port = 3306

Socket =/tmp/mysql. sock

Lower_case_table_names = 1

Key_buffer_size = 256 M

Sort_buffer_size = 1 M

Read_buffer_size = 1 M

Read_rnd_buffer_size = 4 M

Myisam_sort_buffer_size = 64 M

Thread_cache_size = 16

Query_cache_size = 16 M

Thread_concurrency = 4

Interactive_timeout = 8

Wait_timeout = 8

Slow_query_log = on

Long_query_time = 1

Slow-query-log-file =/database/mysql/slow. log

For more information about the parameters, see MySQL common configuration.

3. install php

Install the package that is used before installing php.

# Yum-y install openssl-devel bzip2-devel libxml2-devel curl-devel libpng-devel libjpeg-devel freetype-devel libtool-ltdl-devel perl-devel

Install epel-release extension Source

Rpm-ivh "http://www.lishiming.net/data/attachment/forum/epel-release-6-8_64.noarch.rpm"

# Yum-y install libmcrypt-devel

Create a php-fpm user

# Useradd-M php-fpm-s/sbin/nologin

# Tar zxvf php-5.6.19.tar.gz

# Cd php-5.6.19

#. /Configure -- prefix =/usr/local/php -- with-config-file-path =/usr/local/php/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

# Make-j 2

# Make install

# Cp php. ini-production/usr/local/php/etc/php. ini

Add php-fpm to the system service and set it to auto-start upon startup

# Cp sapi/fpm/init. d. php-fpm/etc/init. d/php-fpm

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

# Chkconfig -- add php-fpm

# Chkconfig php-fpm on

# Cd/usr/local/php/etc/

# Mv php-fpm.conf.default php-fpm.conf

Check whether the php-fpm file is correct

#/Usr/local/php/sbin/php-fpm-t

Start php-fpm

# Service php-fpm start

4. Install nginx

# Tar-zxvf nginx-1.8.1.tar.gz

# Cd nginx-1.8.1

#./Configure -- prefix =/usr/local/nginx -- with-pcre

# Make-j 2

# Make install

Start nginx

#/Usr/local/nginx/sbin/nginx

Open the php configuration item in the configuration file.

# Vim/usr/local/nginx/conf/nginx. conf

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;

Include fastcgi_params;

}

Reload the nginx configuration file

#/Usr/local/nginx/sbin/nginx-s reload

In the/usr/local/nginx/html directory, You can first create a php information page to test the 5th and common php-fpm configurations.

[Global]

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

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

[Www]

Listen =/tmp/www. sock

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

Slowlog =/tmp/phpslow. log

Request_slowlog_timeout = 1

6. Common 502 errors

This is mainly because nginx has no read/write permissions on the sock of php-fpm, another point is that the permissions under the discuz directory should be able to read and write php-fpm users only when setting up the discuz Forum, rather than nginx.

# Chown-R php-fpm: php-fpm/web/discuz/

VII. nginx User Authentication

Add the following content to the discuz configuration file:

Location ~ . * Admin \. php $ {

Auth_basic "fanjinbao auth ";

Auth_basic_user_file/usr/local/nginx/conf/. htpasswd;

Include fastcgi_params;

Fastcgi_pass unix:/tmp/discuz. sock;

Fastcgi_index index. php;

Fastcgi_param SCRIPT_FILENAME/web/discuz $ fastcgi_script_name;

}

The. htpasswd file must be generated using the apahce password generation tool.

VIII. nginx Domain Name Redirection

Add the following content to the server of discuz. conf:

If ($ host! = 'Www .discuz.com ')

{

Rewrite ^/(. *) $ http://www.discuz.com/#1 permanent;

}

9. nginx does not record the specified file type logs

Add the following content to the server of discuz. conf:

Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $

{

Access_log off;

}

Location ~ (Static | cache)

{

Access_log off;

}

10. nginx log cutting script

#! /Bin/bash

D = 'date-d "-1 day" + % F'

[-D/tmp/nginx_log] | mkdir/tmp/nginx_log

Mv/web/discuz. log/tmp/nginx_log/$ d. log

/Etc/init. d/nginxd reload>/dev/null

Cd/tmp/nginx_log/

Gzip-f $ d. log

11. Configure the expiration time of static files in nginx

Location ~ \. (Js | css)

{

Access_log off;

Expires 2 h;

}

12. configure anti-leech protection for nginx

Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $

{

Access_log off;

Expires 15d;

Valid_referers none blocked * .discuz.com * .fansik.com;

If ($ invalid_referer)

{

Return 403;

}

}

Run the curl command to test whether the anti-leech protection configuration is successful:

# Curl-e "http://www.baidu.com/111"-x127.0.0.1: 80 'HTTP: // www.discuz.com/static/image/common/logo.png'-I

The returned status code must be 403

# Curl-e "http://www.fansik.com/111"-x127.0.0.1: 80 'HTTP: // www.discuz.com/static/image/common/logo.png'-I

The returned status code must be 200

12. nginx Access Control

Add directly in the configuration file (or location)

Allow 127.0.0.1;

Deny 1.1.1.1;

XIII. Disable user_agent in nginx

If ($ http_user_agent ~ * 'Curl | baidu | 000000 ')

{

Return 403;

}

~ *: Case insensitive

14. nginx proxy and Load

Upstream baidu {

Server 61.135.169.125: 80;

Server 61.135.169.121: 80;

}

Server {

Listen 80;

Server_name www.baidu.com;

Location /{

Proxy_pass http: // baidu /;

Proxy_set_header Host $ host;

}

}

Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL

Install the LAMP \ Vsftpd \ Webmin \ phpMyAdmin service and settings in Ubuntu 13.04

Build and install the LNMP production environment in CentOS 6.4

Practical Production Environment-LNMP architecture compilation and installation + SSL encryption implementation

LNMP full-featured compilation and installation for CentOS 6.3 notes

Install LNMP in CentOS 6.3 (PHP 5.4, MyySQL5.6)

Nginx startup failure occurs during LNMP deployment.

Ubuntu install Nginx php5-fpm MySQL (LNMP environment setup)

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.