LNMP Environment Construction (centos7+nginx1.10.1+mysql5.6.31+php5.6.22)

Source: Internet
Author: User
Tags bz2 chmod configuration php fpm install php openssl

Tag: Lis Run 1.0 error One scripts service PATH environment variable installation

0. Preparatory work

Installing Wget:yum Install Wget-y

Installing GCC and G++:yum install gcc gcc-c++-y

All subsequent source codes are downloaded to the/USR/LOCAL/SRC directory

Firewall change configuration and shutdown SELinux see another article, "Lamp Environment building"

First, install Nginx

Nginx relies on pcre (rewrite rewrite), zlib (web gzip compression), and OpenSSL (encrypted transfer).

1, installation Pcre

[Root]wget http://pilotfiber.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz

[Root]tar-xvzf pcre-8.38.tar.gz

[ROOT]CD pcre-8.38

[Root]./configure--prefix=/usr/local/pcre

[Root]make && make install

2, installation Zlib

[Root]wget http://zlib.net/zlib-1.2.8.tar.gz

[Root]tar-xvzf zlib-1.2.8.tar.gz

[ROOT]CD zlib-1.2.8

[Root]./configure--prefix=/usr/local/zlib

[Root]make && make install

3. Installing OpenSSL

[Root]wget http://www.openssl.org/source/openssl-1.0.2h.tar.gz

[Root]tar-xvzf openssl-1.0.2h.tar.gz

[ROOT]CD openssl-1.0.2h

[Root]./config--prefix=/usr/local/openssl

[Root]make && make install

4. Installing Nginx

For the sake of security, create an Nginx account dedicated to running Nginx, of course, in order to easily run directly with the root account (not recommended), you do not need to create Nginx account and open Nginx related files to the Nginx account.

[Root]groupadd Nginx

[Root]useradd-g nginx nginx-s/bin/false# This account is only used to run Nginx and related software, cannot log in

[Root]wget http://nginx.org/download/nginx-1.10.1.tar.gz?

[Root]tar-xvzf nginx-1.10.1.tar.gz?

[ROOT]CD nginx-1.10.1

[Root]./configure--prefix=/usr/local/nginx--user=nginx--group=nginx--with-http_ssl_module--with-http_realip_ Module--with-http_image_filter_module--with-http_sub_module--with-http_gzip_static_module--with-http_stub_ Status_module--with-pcre=/usr/local/src/pcre-8.38--with-zlib=/usr/local/src/zlib-1.2.8--with-openssl=/usr/ local/src/openssl-1.0.2h

[Root]make && make install

Tip:./configure--help to view compilation options

Note here :

Http_image_filter_module is an integrated image processing module provided by Nginx, which needs gd-devel support, the error message is as follows:
the HTTP image filter module requires the GD library.You can either do not enable the module or install the libraries.
    • 1
    • 2

Workaround:

-y install gd-devel
5, configuration Nginx1) modify the configuration file

[root]vi/usr/local/nginx/conf/nginx.conf

If required, change HTTP---server-server_name to the server's extranet IP address, or your website domain name?

2) Configure boot from

Method One: Add a line of script at the end of the/etc/rc.d/rc.local file

[Root]/usr/local/nginx/sbin/nginx

Method Two: Add Nginx to the service, add/etc/init.d/nginx script, see Nginx script, then set boot from:

[Root]chmod +x/etc/init.d/nginx

[Root]chkconfig Nginx on #设置开启自启动后会自动将其加入服务

3) Start Nginx

If Nginx has joined the service, start the service with the Services command

[Root]service nginx Start

Otherwise run the Nginx program

[Root]/usr/local/nginx/sbin/nginx

Second, install MySQL1, install Ncurses-devel

[Root]yum Install Ncurses-devel-y

2, installation CMake

[Root]wget https://cmake.org/files/v3.5/cmake-3.5.2.tar.gz

[Root]tar-xvzf cmake-3.5.2.tar.gz

[ROOT]CD cmake-3.5.2

[Root]./configure--prefix=/usr/local/cmake

[Root]make && make install

[Root]export path= $PATH:/usr/local/cmake/bin# temporarily joins the PATH environment variable

3. Install MySQL

Like Nginx, create a MySQL account dedicated to running MySQL

[Root]groupadd MySQL

[Root]useradd-g MySQL mysql-s/sbin/false

[Root]wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.31.tar.gz

[Root]tar-xvzf mysql-5.6.31.tar.gz

[ROOT]CD mysql-5.6.31

[Root]cmake-dcmake_install_prefix=/usr/local/mysql \ #mysql安装到的路径

-DSYSCONFDIR=/ETC \ #mysql配置文件 (my.cnf) path

-dmysql_datadir=/usr/local/mysql/data \ #data目录路径

-dmysql_unix_addr=/var/lib/mysql/mysql.sock \ #sock存放路径

-ddefault_charset=utf8 \ #默认字符集

-ddefault_collation=utf8_general_ci# Default Character Set checksum

[Root]make && make install

4. Configure MySQL

All of the following operations are performed under the/usr/local/mysql path.

1) Initializing the database

[root]scripts/mysql_install_db--user=mysql--datadir=/usr/local/mysql/data

2) Copy the configuration file

[ROOT]CP support-files/my-default.cnf/etc/my.cnf

3) Start MySQL

[ROOT]CP support-files/mysql.server/etc/init.d/mysqld# service name can also be taken as MySQL, as you

[Root]chkconfig mysqld on

[Root]service mysqld start

4) Change the root account password of MySQL

[Root]bin/mysql_secure_installation

Then set the password and make some configuration

5) log in to MySQL

[Root]mysql-uroot-p

Then enter the password to log in. If you have bad luck (like me), enter the password login, the inside off, and output segment fault hint, then you need to modify the source code and re-compile the installation. Open/USR/LOCAL/SRC/PHP.5.6.31/CMD-LINE-UTILS/LIBEDIT/TERMINAL.C, in the Terminal_set function:

A, note char buf[tc_bufsize]; one line

B. Change area = buf to area = NULL

Then recompile the installation.

Third, install PHP

This article installs PHP minimally.

1. Install PHP

[Root]wget http://cn2.php.net/distributions/php-5.6.22.tar.bz2

[Root]tar-xvjf php-5.6.22.tar.bz2

[ROOT]CD php-5.6.22

[Root]./configure--prefix=/usr/local/php \ #php安装路径

--WITH-LIBDIR=LIB64 \ #64位操作系统需要

--ENABLE-MYSQLND \

--WITH-MYSQLI=MYSQLND \

--WITH-PDO-MYSQL=MYSQLND \

--with-mysql_sock=/var/lib/mysql/mysql.sock \

--ENABLE-FPM \

--enable-opcache \

--with-mhash \

--with-ldap# own project to use, need yum install Openldap-devel

[Root]make && make install

2. Configure PHP

The following commands are executed under the/usr/local/php path.

1) View php.ini file storage path

[Root]bin/php--ini

Configuration File (php.ini) Path:/usr/local/php/lib

[Root]cp/usr/local/src/php-5.6.22/php.ini-production Lib/php.ini

2) configuration PHP.ini

A. Turn off display of PHP version information in HTTP headers?

? expose_php = Off

B. Setting the time zone

Date.timezone = PRC?

3, Configuration php-fpm

The following commands are executed under the/usr/local/php path.

[ROOT]CP Etc/php-fpm.conf.default etc/php-fpm.conf

1) Remove 25 lines;p id = run/php-fpm.pid in front of the semicolon to make it effective

2) The 148th line is changed to user = Nginx setting php-fpm operation account is Nginx

3) Change the 149th line to group = Nginx #设置php-fpm Operation Group is Nginx

4) optional. PHP-FPM By default TCP communication, if you need to use the UNIX socket communication, the configuration is as follows

Listen =/dev/shm/php-fpm.sock?

Listen.owner = Nginx?

Listen.group = Nginx

4. Start PHP-FPM

[ROOT]CP/USR/LOCAL/SRC/PHP-5.6.22/SAPI/FPM/INIT.D.PHP-FPM/ETC/INIT.D/PHP-FPM

[Root]chmod +X/ETC/INIT.D/PHP-FPM

[Root]chkconfig php-fpm on

[Root]service php-fpm start

5, Configuration Nginx support PHP

[root]vi/usr/local/nginx/conf/nginx.conf

1) The top row is changed to user Nginx Nginx;

2) the

Location?/{

root HTML;

Index index.html index.htm

}?

Switch

Location?/{

root/www;

Index index.php index.html index.htm

}??

Note: The Web root directory needs to be/www open to Nginx account: Chown nginx:nginx/www

3) Remove the comment from location ~ \.php$ {Paragraph, as follows:

Location ~ \.php$ {
root/www;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
}

This is the configuration of PHP-FPM when TCP communication is used, and if it uses the UNIX socket communication, the Fastcgi_pass line needs to be:

Fastcgi_pass Unix:/dev/shm/php-fpm.sock;

6. Configure PHP to support MySQL

In fact, to this step, PHP has been supported mysqli and Pdo_mysql (because mysql_connect and other functions have been discarded, so when compiling PHP without--with-mysql). However, you can only use ' 127.0.0.1 ' to connect to this machine using Mysqli_connect, instead of ' localhost ', because MySQL connects to 127.0.0.1 via TCP and connects to localhost through a UNIX socket. As long as the php.ini set mysqli and Pdo_mysql Default_socket for/var/lib/mysql/mysql.sock can be. It seems that when compiling PHP with the--with-mysql-sock=/var/lib/mysql/mysql.sock option, you do not have to configure the Default_socket in php.ini.

7. Restart PHP-FPM and Nginx

[Root]service php-fpm Restart

[Root]service nginx Restart

8. Test Nginx support for PHP

Create a new/www/info.php file with the following contents:

<?php phpinfo ();?>

View in Browser: localhost/info.php

9, the test to mysqli and Pdo_mysql support

Create a new/www/mysql.php file and test the mysqli with the following:

<?php var_dump (mysqli_connect (' localhost ', ' root ', ' 111111 '));?>

The contents of the test Pdo_mysql are:

<?php Var_dump (New PDO (' Mysql:host=localhost;db=mysql ', ' root ', ' 111111 '));?>

The above root and 111111 are MySQL accounts and passwords.

View in Browser: localhost/mysql.php, normal, display content contains "object (mysqli)" and "Object (PDO)" respectively.

LNMP Environment Construction (centos7+nginx1.10.1+mysql5.6.31+php5.6.22)

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.