Linux Build Lnmp

Source: Internet
Author: User
Tags install php mcrypt mysql create

Hardware environment:

System: CentOS 6.6 nginx:nginx-1.8.0 mysql:mysql-5.5.45 php:php-5.5.30

LNMP is the nginx+mysql+php of this kind of Web server architecture under Linux system.

Nginx is a high-performance HTTP and reverse proxy server, also a IMAP/POP3/SMTP proxy server. MySQL is a small relational database piping system. PHP is a scripting language for embedded HTML documents that are executed on the server side.

LNMP installation should be noted:MySQL must be installed in front of PHP, because PHP installation will use MySQL.

First, install MySQL

1. Download MySQL Source package

Cd/usr/local/srcwget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.45-linux2.6-i686.tar.gz

Here is a compiler-free binary package, the address is Sohu mirror site, you can also go to MySQL official website download http://dev.mysql.com/downloads/, do not affect the experiment.

2. Unzip the source package

Tar zxvf mysql-5.5.45-linux2.6-i686.tar.gz

3. Change

MV Mysql-5.5.45-linux2.6-i686/usr/local/mysql//change MySQL file directory useradd-s/sbin/nologin mysql//create user Mkdir-p/data/mysql Create MySQL Data Catalog Chown-r mysql:mysql/data/mysql//change belongs to

4. Installation

cd/usr/local/mysql./scripts/mysql_install_db--user=mysql--datadir=/data/mysql//See if the key location has two OK, otherwise there may be an error CP SUPPORT-FILES/MY-LARGE.CNF/ETC/MY.CNF//Copy configuration file

Support-files There are several files below: config.huge.cnf,my-large.cnf,my-medium.cnf,my-small.cnf
General selection: Memory size 1-2g: Choose huge 512M: Choose large 32-64m: Choose Medium <=64: Select Small

CP support-files/mysql.server/etc/init.d/mysqld//copy process file chmod 755/etc/init.d/mysqld vim/etc/init.d/mysqld//Modify Datad IR and Basedir basedir=/usr/local/mysql datadir=/data/mysql

Add Chkconfig--add mysqld

Chkconfig mysqld on

Service mysqld Start

To this MySQL installation is complete.

Second, install PHP

Installing PHP-FPM in LNMP

1. Download the source package

Cd/usr/local/srcwget Http://cn2.php.net/distributions/php-5.5.30.tar/bz2tar JXVF php-5.5.30.tar.bz2

2. Compiling the installation

Useradd-s/sbin/nologin php-fpm cd php-5.5.30./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-curl

See the figure below, the compilation is complete, you can use the echo $ command to verify that the return "0" is no problem.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/76/02/wKiom1ZHQnzQU2_uAAAva43qmN4913.png "title=" 888. PNG "alt=" Wkiom1zhqnzqu2_uaaava43qmn4913.png "/>


Errors may occur at compile time, because some dependent packages are not installed, you can install them on your own prompts, and then compile again.

For example, there are some errors:

(1) Checking for gcc...no

Solve:

Yum install-y gcc

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/75/FE/wKioL1ZHMoOiuG_SAABfSntkiBg059.png "title=" 111. PNG "alt=" Wkiol1zhmooiug_saabfsntkibg059.png "/> (2) error:xml2-config not found. Please chek your LIBXML2 installation.

Solve:

Yum Install-y libxml2-devel

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/75/FF/wKioL1ZHPFiR59RsAAAsGV4YPDc082.png "title=" 222. PNG "alt=" Wkiol1zhpfir59rsaaasgv4ypdc082.png "/> (3) error:please Reinstall the Libcurl distribution

Solve:

Yum Install-y libcurl-devel

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/75/FF/wKioL1ZHPp3xTTX0AAAqsJpDomo431.png "title=" 333. PNG "alt=" Wkiol1zhpp3xttx0aaaqsjpdomo431.png "/> (4) error:jpeglib.h not found.

Solve:

Yum Install-y libjpeg-devel

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/75/FF/wKioL1ZHP9LQCDQ6AAAh_zd20uY230.png "title=" 444. PNG "alt=" Wkiol1zhp9lqcdq6aaah_zd20uy230.png "/> (5) error:png.h not found.

Solve:

Yum Install-y libpng-devel

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/75/FF/wKioL1ZHQGrxL_LWAAAgbhTvHqE808.png "title=" 555. PNG "alt=" Wkiol1zhqgrxl_lwaaagbhtvhqe808.png "/>

(6) Error:freetype-config not found.

Solve:

Yum Install-y freetype-devel

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/75/FF/wKioL1ZHQRXTUZ6aAAAifUqbeQ0975.png "title=" 666. PNG "alt=" Wkiol1zhqrxtuz6aaaaifuqbeq0975.png "/>

(7) Error:mcrypt.h not found. Please reinstall Libmcrypt.

Solve:

Yum Install-y libmcrypt-devel

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/76/02/wKiom1ZHQW_jtwuYAAAhqn8pR9g941.png "title=" 777. PNG "alt=" Wkiom1zhqw_jtwuyaaahqn8pr9g941.png "/>

These are the errors I encountered during the installation process, and there are other issues that are not listed.

Then it is the installation:

Make && make install

can still be verified with echo $?

3. Configuration

CP Php.ini-production/usr/local/php-fpm/etc/php.ini

Copy startup script:

cp/usr/local/src/php-5.5.30/sapi/fpm/init.d.php-fpm/etc/init.d/php-fpmmv/usr/local/php-fpm/etc/ Php-fpm.conf.default/usr/local/php-fpm/etc/php-fpm.confchmod 755/etc/init.d/php-fpmchkconfig--add Php-fpmchkconfig php-fpm onservice php-fpm start

To this PHP installation is complete.

Third, install Nginx

    1. Download the source Package

Cd/usr/local/src/wget Tar zxvf nginx-1.8.0.tar.gz

2. Compiling the installation

CD Nginx-1.8.0./configure--prefix=/usr/local/nginx

The following errors may occur at compile time:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/76/02/wKiom1ZHRw7xe0QRAAAkEolxheI850.png "title=" 999. PNG "alt=" wkiom1zhrw7xe0qraaakeolxhei850.png "/> Solution: Yum install-y pcre-devel

Then install:

Makemake Install

The three steps for compiling and installing can be verified with echo $ .


Start Nginx:

/usr/local/nginx/sbin/nginx

3. Writing Nginx Startup scripts

Vim/etc/init.d/nginx //Add the following (originally no configuration file)

#!/bin/bash# chkconfig: - 30 21# description: http service.# source  function library. /etc/init.d/functions# nginx settingsnginx_sbin= "/usr/local/nginx/ Sbin/nginx "nginx_conf="/usr/local/nginx/conf/nginx.conf "nginx_pid="/usr/local/nginx/logs/nginx.pid "RETVAL= 0prog= "Nginx" Start ()  {echo -n $ "starting  $prog: " mkdir -p /dev/shm/nginx_ tempdaemon  $NGINX _sbin -c  $NGINX _confretval=$?echoreturn  $RETVAL}stop ()  {echo -n  $ "stopping  $prog: " killproc -p  $NGINX _pid  $NGINX _SBIN&NBSP;-TERMRM&NBSP;-RF  /dev/shm/nginx_tempRETVAL=$?echoreturn  $RETVAL}reload () {echo -n $ "reloading  $prog:   "killproc -p  $NGINX _pid  $NGINX _sbin -hupretval=$?echoreturn  $RETVAL}restart () { Stopstart}configtest () {$NGINX _sbin -c  $NGINX _conf -treturn 0}case  "$"  instart) start;; stop) stop;; Reload) reload;; restart) restart;; Configtest) configtest;; *) echo $ "usage: $0 {start|stop|reload|restart|configtest}" retval=1esacexit  $RETVAL

Save End, execute

chmod a+x/etc/init.d/nginxchkconfig--add nginxchkconfig nginx onservice nginx Start

To this nginx installation is complete.

Iv. Configuration parsing PHP

vim/usr/local/nginx/conf/nginx.conf//Modify the following content 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/usr/local/nginx/sbin/nginx-s Reload

To do the test:

Vim/usr/local/nginx/html/1.php<?phpphpinfo ();? >

Test:

Curl localhost/1.php


or in the browser input IP, will appear the Nginx welcome page

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/75/FF/wKioL1ZHSrKCNdxcAABolx2n_-w884.png "title=" 9999. PNG "alt=" Wkiol1zhsrkcndxcaabolx2n_-w884.png "/>

Input ip/1.php information about PHP

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/76/02/wKiom1ZHSs6DaZPDAABpJv9MTQw257.png "title=" 99999. PNG "alt=" Wkiom1zhss6dazpdaabpjv9mtqw257.png "/> This lnmp's build is complete.



Linux Build Lnmp

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.