LNMP Compile Installation Tutorial (very detailed)

Source: Internet
Author: User
Tags bz2 curl fpm install php mcrypt openssl openldap


Linux uses CentOS, the package is unified in the/USR/LOCAL/SRC directory. Because the CentOS source is older, and the update is also relatively slow, here suggest you to replace 163 sources. Tip: If you really intend to install PHP with this kind of compilation, please schedule at least half a day to complete. If you are testing in the virtual machine, it is recommended to increase the memory to make time shorter, I gave the virtual machine 2G memory. After the installation is complete, you can set up a little bit of memory to run. Install in sequence.

Change the Yum source

#更换到163源
cd/etc/yum.repos.d/
wget Http://mirrors.163.com/.help/CentOS6-Base-163.repo
MV Centos-base.repo Centos-base.repo.bak
MV Centos6-base-163.repo Centos-base.repo

#先更新一下
Yum Clean All
Yum Makecache
Yum update (This step is slower, it is recommended not to run first)

Prepare LNMP Installation Environment

First use the Yum package to install some dependent things

Yum-y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-deve L zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel Curl curl-devel e2fsprogs E2 Fsprogs-devel krb5 krb5-devel libidn libidn-devel OpenSSL openssl-devel openldap openldap-devel Nss_ldap Openldap-clients openldap-servers make cmake libtool* git tree

Download some of the software is placed under the/USR/LOCAL/SRC

Install Libiconv

Cd/usr/local/src
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
Tar zxvf libiconv-1.14.tar.gz
CD libiconv-1.14/
./configure--prefix=/usr/local
Make && make install
Error occurred while I made && make install: "gets ' undeclared here" (not in a function). If you do not encounter encounter, if encountered please make the following changes: (Foreign This article recorded http://www.itkb.ro/kb/linux/patch-libiconv-pentru-glibc-216)

CD Libiconv-1.14/srclib

Edit Stdio.in.h file, search this sentence


_gl_warn_on_use (Gets, "gets is a security hole-use fgets instead");

Replace this deletion with the following sentence


#if defined (__glibc__) &&!defined (__uclibc__) &&!__glibc_prereq (2, 16)
_gl_warn_on_use (Gets, "gets is a security hole-use fgets instead");
#endif

And then

Cd..
Make && make install

Download and install Libmcrypt

Cd/usr/local/src
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
TAR-ZXVF libmcrypt-2.5.7.tar.gz
CD libmcrypt-2.5.7
./configure
Make
Make install
CD libltdl/
./configure--enable-ltdl-install
Make
Make install

Download and install the Mbash URL: http://mhash.sourceforge.net/, download and then use WINSCP this tool to upload Linux/usr/local/src directory

Cd/usr/local/src
TAR-JXVF mhash-0.9.9.9.tar.bz2
CD mhash-0.9.9.9
./configure
Make
Make install

Download and install Mcript


Cd/usr/local/src
Tar zxvf mcrypt-2.6.8.tar.gz
CD mcrypt-2.6.8/

#注意一下这步运行下, or there may be an error.

Export Ld_library_path=/usr/local/lib: $LD _library_path

./configure
Make
Make install

Ln-s/usr/local/lib/libmcrypt.la/usr/lib/libmcrypt.la
Ln-s/usr/local/lib/libmcrypt.so/usr/lib/libmcrypt.so
Ln-s/usr/local/lib/libmcrypt.so.4/usr/lib/libmcrypt.so.4
Ln-s/usr/local/lib/libmcrypt.so.4.4.8/usr/lib/libmcrypt.so.4.4.8
Ln-s/USR/LOCAL/LIB/LIBMHASH.A/USR/LIB/LIBMHASH.A
Ln-s/usr/local/lib/libmhash.la/usr/lib/libmhash.la
Ln-s/usr/local/lib/libmhash.so/usr/lib/libmhash.so
Ln-s/usr/local/lib/libmhash.so.2/usr/lib/libmhash.so.2
Ln-s/usr/local/lib/libmhash.so.2.0.1/usr/lib/libmhash.so.2.0.1
Ln-s/usr/local/bin/libmcrypt-config/usr/bin/libmcrypt-config

Install MySQL (mysql5.6.13)

Let's check if MySQL is already there and delete MySQL if it exists.

Rpm-qa | grep MySQL

#我的显示如下 (if there is no display, it means no MySQL)

mysql-libs-5.1.73-3.el6_5.i686

#如果存在就卸载mysql

RPM-E mysql-libs-5.1.73-3.el6_5.i686--nodeps

#此时再运行

Rpm-qa | grep MySQL

#发现没有任何显示

Add a MySQL user (nologin user and no home directory)

Useradd-m-s/sbin/nologin MySQL

The time is long when MySQL is first compiled, please wait patiently

Cd/usr/local/src
TAR-ZXF mysql-5.6.13.tar.gz
CD mysql-5.6.13
#注意下面是cmake. Note the point
CMake.
Make && make install
#复制mysql配置文件
CP SUPPORT-FILES/MY-DEFAULT.CNF/ETC/MY.CNF
#创建系统数据库表
Cd/usr/local/mysql
scripts/mysql_install_db--user=mysql
#更改权限
Cd/usr/local/mysql
Chown-r Root:mysql.
Chown-r Mysql:mysql Data

#把mysql添加到系统服务中去
Cp/usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld
#启动mysql启动的时候, if you don't move, press ENTER.
/usr/local/mysql/bin/mysqld_safe--user=mysql &
#查看mysql是否启动
NETSTAT-TUNPL | grep 3306
#或者pstree, it's okay to see a mysqld process.
#修改mysql密码
/usr/local/mysql/bin/mysqladmin-u root Password "xxxxx"
#进入mysql中删除空密码和匿名用户
/usr/local/mysql/bin/mysql-u root-p
Select Host,user,password from Mysql.user;
Delete from Mysql.user where password= "" or user= "";
Flush privileges;
#也可以在mysql修改用户密码 (just to explain)
Set password form ' root ' @ ' localhost ' = password (' 123456 ');
#关闭mysql的时候可以使用
/usr/local/mysql/bin/mysqladmin-u root-p shutdown

#把mysql添加到开机启动
Vim/etc/rc.local
#在最后再加一行
/usr/local/mysql/bin/mysqld_safe--user=mysql &

#最后做一个软链接方便使用mysql

Ln-s/usr/local/mysql/bin/mysql/usr/bin/
Nginx installation (here I installed the Nginx version of the Tengine,nginx based on the installation and this is basically exactly the same, you can fully refer to and complete installation)

Nginx Install pcre zlib OPENSSL[OPENSSL installation before installation./config]

Pcre Installation

Cd/usr/local/src
TAR-JXF pcre-8.31.tar.bz2
CD pcre-8.31
./configure
Make && make install

Zlib installation

Cd/usr/local/src
TAR-ZXF zlib-1.2.8.tar.gz
CD zlib-1.2.8
./configure
Make && make install


OpenSSL installation

Cd/usr/local/src
TAR-ZXF openssl-1.0.1c.tar.gz
CD openssl-1.0.1c
./config
Make && make install
Note that I installed Tengine, if you use Nginx, full reference installation on the line


cd/usr/local/src
useradd-m-s/sbin/nologin nginx
#如果是nginx, please change this here to Nginx
Tar-zxf Tengine-2.0.1.tar. GZ
CD tengine-2.0.1
#注意的是with-pcre These all point to/USR/LOCAL/SRC directories, which is very strange
./configure--with-pcre=/usr/local/src/ pcre-8.31--with-http_ssl_module--with-zlib=/usr/local/src/zlib-1.2.8--with-openssl=/usr/local/src/ Openssl-1.0.1c--with-http_concat_module=shared (Note: If Nginx is not required--with-http_concat_module=shared)
 
Make && make install
#做软链接方便nginx启动
ln-s/usr/local/nginx/sbin/nginx/usr/bin/
#修改nginx配置文件
Vim /usr/local/nginx/conf/nginx.conf
Change #user Nobody to user nginx
#测试一下nginx配置文件
nginx-t
#启动nginx
Nginx
 
#说一下nginx启动的一些事情
#一般来说在nginx的配置文件修改后进行如下操作, Nginx-t detects that the configuration file is correct, if correct
#再使用nginx-s Reload Make Nginx smooth start
 
#把nginx添加到开机启动
vim/etc/rc.local
#在最后新加一行
/usr/local/nginx/sbin/nginx
# See if Nginx starts
NETSTAT-TUNPL | grep
Pstree See if there's any nginx.
 

Installing PHP


Cd/usr/local/src
Useradd-m-s/sbin/nologin PHP
TAR-JXF php-5.5.12.tar.bz2
CD php-5.5.12

./configure--enable-opcache--prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc--with-mysql=/usr/ Local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--enable-mbstring=all--with-pdo-mysql-- Enable-sockets--enable-mbstring--enable-fpm--with-curl--with-iconv-dir=/usr/local--with-freetype-dir-- With-jpeg-dir--with-png-dir--with-zlib--enable-xml--with-gd--with-mcrypt- With-openssl--with-iconv=/usr/local/iconv

Make zend_extra_libs= '-liconv '
Make install

CP Php.ini-development/usr/local/php/etc/php.ini

#配置php-FPM
Cd/usr/local/php/etc
CP Php-fpm.conf.default php-fpm.conf
Vim php-fpm.conf
Will
user = Nobody
Group = Nobody
To
user = PHP
Group = PHP
#启动php-FPM
/usr/local/php/sbin/php-fpm
#把php-fpm Add to boot
Vim/etc/rc.local
#最后一行加上
/usr/local/php/sbin/php-fpm

#修改nginx配置文件使之支持php
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/scripts$fastcgi_script_name;
# include Fastcgi_params;
#}

Amended to

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

#也顺便把gzip给开启下吧
Gzip on front of # Remove

After you finish modifying the configuration
Nginx-s Reload
OK, now let's test the environment.

Cd/usr/local/nginx
CD HTML
Vim test.php

Write on

<?php
Phpinfo ();
Then visit localhost/test.php, Normal, everything's fine.

If there is a problem, please see if Nginx has started, PHP-FPM has not started

Note A few questions if you modify the PHP configuration file, you need to restart the PHP-FPM.


#先关闭php-FPM

Pkill PHP-FPM

#然后运行

/usr/local/php/sbin/php-fpm

#就可以了可以看到php-FPM started, Pstree can see the process.
Pstree
To make it easier to use PHP and PHP-FPM, I made two chain links

Ln-s/usr/local/php/sbin/php-fpm/usr/bin/
Ln-s/usr/local/php/bin/php/usr/bin/
LNMP installation is completely completed, there are any questions you can contact me. [There is no talk about how to optimize some configuration issues, later can write article analysis]

In some also specifically explain how nginx support path_info this form. The configuration file can be written like this. Of course it doesn't need to be for you.


Location ~ ^ (. +\.php) (. *) $ {
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_split_path_info ^ (. +\.php) (. *) $;

Fastcgi_param script_filename $document _root$fastcgi_script_name;
Fastcgi_param path_info $fastcgi _path_info;
Fastcgi_param path_translated $document _root$fastcgi_path_info;
Include Fastcgi_params;
}

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.