Linux + Nginx + MySql + Php both LNMP source code Installation

Source: Internet
Author: User
Tags mysql create

Preface:

We all know that Apache, as a good web server, occupies more than half of the market, and no one can replace it at present. However, apart from Apache, Apache is among the top web server software vendors, nginx has won the favor of many people for its stable performance, rich functions, simple O & M, fast processing of static and static files, and extremely low consumption of system resources.

The following describes how to install Nginx + mysql + php in linux.

Preparation tools:

Mysql-5.5.15-linux2.6-i686.tar.gz

Nginx-1.0.11.tar.gz

Pcre-devel-6.6-2.el5_1.7.i386.rpm

Libevent-2.0.16-stable.tar.gz

Php-5.4.3.tar.gz

Xcache-2.0.1.tar.gz

1. Install mysql binary)

To save time, mysql is installed in binary mode. We have already discussed how to set up the source code in the LAMP environment. If you need to set up the LAMP environment, see

[Root @ lly ~] # Tar-zxvf mysql-5.5.15-linux2.6-i686.tar.gz-C/usr/local/

[Root @ lly ~] # Cd/usr/local/

[Root @ lly local] # ll

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-10349 "border =" 0 "alt =" wps_clip_image-10349 "width =" 555 "height =" 170 "src =" http://www.bkjia.com/uploads/allimg/131228/01434040B-0.png "/>

Generated mysql-5.5 ..... The directory name is long, and it is not easy to remember during operations. We can change the name for it or create a link. Here is a link

[Root @ lly local] # ln-s mysql-5.5.15-linux2.6-i686 mysql

[Root @ lly local] # cd mysql can directly access the mysql directory.

[Root @ lly mysql] # less INSTALL-BINARY view mysql BINARY Installation Steps

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-7017 "border =" 0 "alt =" wps_clip_image-7017 "width =" 555 "height =" 351 "src =" http://www.bkjia.com/uploads/allimg/131228/0143405159-1.png "/>

[Root @ lly ~] # Groupadd-r mysql CREATE a group

[Root @ lly ~] # Useradd-r-g mysql-M create account-M indicates no home directory is created

[Root @ lly ~] # Cd/usr/local/mysql

[Root @ lly mysql] # chown-R mysql. Change the owner of all objects in the current directory to mysql.

[Root @ lly mysql] # chgrp-R mysql. Change all objects in the current directory to mysql

[Root @ lly mysql] # scripts/mysql_install_db -- user = mysql Initialization

[Root @ lly mysql] # chown-R root.

[Root @ lly mysql] # chown-R mysql data, except for the data directory, all directory owners are changed to administrators.

[Root @ lly mysql] # cp support-files/my-medium.cnf/etc/my. cnf copy the mysql configuration file under support-file to the etc directory and rename it my. cnf

[Root @ lly mysql] # cp support-files/mysql. server/etc/init. d/mysqld generate the mysql Service Control File

[Root @ lly mysql] # chmod a + x/etc/init. d/mysqld

[Root @ lly mysql] # chkconfig -- add mysqld

[Root @ lly mysql] # chkconfig -- list | grep mysql

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-21402 "border =" 0 "alt =" wps_clip_image-21402 "width =" 555 "height =" 31 "src =" http://www.bkjia.com/uploads/allimg/131228/0143405093-2.png "/>

[Root @ lly mysql] # service mysqld start mysql service

[Root @ lly mysql] # netstat-tupln | grep 3306 check whether the port is enabled

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-20038 "border =" 0 "alt =" wps_clip_image-20038 "width =" 555 "height =" 51 "src =" http://www.bkjia.com/uploads/allimg/131228/014340C33-3.png "/>

[Root @ lly mysql] #/usr/local/mysql/bin

[Root @ lly bin] # vim/etc/profile Add the mysql service to the variable for future access

Add path

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-12408 "border =" 0 "alt =" wps_clip_image-12408 "width =" 555 "height =" 236 "src =" http://www.bkjia.com/uploads/allimg/131228/0143401307-4.png "/>

[Root @ lly bin] #./etc/profile run

[Root @ lly bin] # Enter mysql to access mysql.

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-8049 "border =" 0 "alt =" wps_clip_image-8049 "width =" 555 "height =" 172 "src =" http://www.bkjia.com/uploads/allimg/131228/0143404608-5.png "/>

[Root @ lly bin] # mysqladmin-u root-p password '000000' create an administrator password

[Root @ lly bin] # cd ..

[Root @ lly mysql] # vim/etc/ld. so. conf. d/mysql. conf

Write mysql database files to the environment

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-11591 "border =" 0 "alt =" wps_clip_image-11591 "width =" 380 "height =" 31 "src =" http://www.bkjia.com/uploads/allimg/131228/0143403416-6.png "/>

[Root @ lly mysql] # ldconfig refresh

[Root @ lly mysql] # ldconfig-pv | grep mysql check whether to import

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-24885 "border =" 0 "alt =" wps_clip_image-24885 "width =" 555 "height =" 58 "src =" http://www.bkjia.com/uploads/allimg/131228/014340E23-7.png "/>

[Root @ lly mysql] # ln-s include/usr/include/mysql makes a connection to the mysql header file

Mysql configuration complete

Ii. Install nginx

Install the pcre-Compatible Regular Expression Library) and lievent before installing nginx.

1. Install pcre here by using the software package in the CD)

[Root @ lly ~] # Mount/dev/cdrom/mnt/cdrom mount the optical drive

[Root @ lly ~] # Cd/mnt/cdrom/Server/

[Root @ lly Server] # rpm-ivh pcre-devel-6.6-2.el5_1.7.i386.rpm install the pcre rpm package

2. Install libevent

[Root @ lly Server] # cd

[Root @ lly ~] # Tar-zxvf libevent-2.0.16-stable.tar.gz-C/usr/local/src/

[Root @ lly ~] # Cd/usr/local/src/libevent-2.0.16-stable/

[Root @ lly libevent-2.0.16-stable] #./configure -- prefix =/usr/local/libevent specifies the installation path

[Root @ lly libevent-2.0.16-stable] # make

[Root @ Lili libevent-2.0.16-stable] # make install

[Root @ lly libevent-2.0.16-stable] # cd/usr/local/libevent/

[Root @ lly libevent] # vim/etc/ld. so. conf. d/libevent. conf

Write database files

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-9224 "border =" 0 "alt =" wps_clip_image-9224 "width =" 444 "height =" 35 "src =" http://www.bkjia.com/uploads/allimg/131228/0143401449-8.png "/>

[Root @ lly libevent] # ldconfig refresh

[Root @ lly libevent] # ldconfig-pv | grep libevent

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-6888 "border =" 0 "alt =" wps_clip_image-6888 "width =" 555 "height =" 130 "src =" http://www.bkjia.com/uploads/allimg/131228/014340O14-9.png "/>

[Root @ lly libevent] # ln-s/usr/local/libevent/include // usr/include/libevent link the header file

Install nginx

[Root @ lly libevent] # cd

[Root @ lly ~] # Tar-zxvf nginx-1.0.11.tar.gz-C/usr/local/src/

Nginx runs as a process and requires an account.

[Root @ lly nginx-1.0.11] # groupadd-r nginx

[Root @ lly nginx-1.0.11] # useradd-s/sbin/nologin-M-r-g nginx create account

[Root @ lly nginx-1.0.11] #./configure \

-- Conf-path =/etc/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/lock/nginx. lock \

-- User = nginx \

-- Group = nginx \

With-http_ssl_module \

With-http_flv_module \

With-http_stub_status_module \

With-http_gzip_static_module \

-- 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 /\

-- With-pcre

[Root @ lly nginx-1.0.11] # make

[Root @ Lili nginx-1.0.11] # make install

[Root @ lly nginx-1.0.11] # cd/etc/nginx/

[Root @ lly nginx] # ll/usr/local/nginx/

Write a control script for nginx

[Root @ lly nginx] # ll/usr/local/nginx/sbin/

[Root @ lly ~] # Vim/etc/init. d/nginx

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-9901 "border =" 0 "alt =" wps_clip_image-9901 "width =" 554 "height =" 266 "src =" http://www.bkjia.com/uploads/allimg/131228/0143405941-10.png "/>

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-26334 "border =" 0 "alt =" wps_clip_image-26334 "width =" 555 "height =" 243 "src =" http://www.bkjia.com/uploads/allimg/131228/0143404400-11.png "/>

[Root @ lly ~] # Chmod a + x/etc/init. d/nginx

[Root @ lly ~] # Chkconfig -- add nginx

[Root @ lly ~] # Chkconfig -- list | grep nginx

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-7613 "border =" 0 "alt =" wps_clip_image-7613 "width =" 555 "height =" 30 "src =" http://www.bkjia.com/uploads/allimg/131228/0143401N9-12.png "/>

[Root @ lly ~] # Service nginx start nginx

[Root @ lly ~] # Netstat-tupln | grep 80 check whether port 80 of nginx is enabled

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-27902 "border =" 0 "alt =" wps_clip_image-27902 "width =" 555 "height =" 28 "src =" http://www.bkjia.com/uploads/allimg/131228/0143406236-13.png "/>

Enter http: // 192.168.126.129/test in the browser

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-21777 "border =" 0 "alt =" wps_clip_image-21777 "width =" 555 "height =" 119 "src =" http://www.bkjia.com/uploads/allimg/131228/01434040A-14.png "/>

3. install php

[Root @ lly ~] # Tar-zxvf php-5.4.3.tar.gz-C/usr/local/src/

[Root @ lly ~] # Cd/usr/local/src/php-5.4.3/

[Root @ lly php-5.4.3] #. /configure -- prefix =/usr/local/php -- enable-fpm -- enable-sockets -- with-mysql =/usr/local/mysql -- with-mysqli =/usr/local/ mysql/bin/mysql_config -- enable-mbstring -- enable-xml -- with-png-dir -- with-png -- with-jpeg-dir -- with-zlib -- with-freetype-dir -- with-config-file-path =/etc/php -- with-config-file-scan-dir =/etc/php5.d

[Root @ lly php-5.4.3] # make

[Root @ Lili php-5.4.3] # make install

[Root @ lly php-5.4.3] # mkdir/etc/php/etc/php5.d

[Root @ lly php-5.4.3] # cp php. ini-production/etc/php

[Root @ lly php-5.4.3] # cp sapi/fpm/init. d. php-fpm/etc/init. d/php-fpm

[Root @ lly php-5.4.3] # chmod a + x/etc/init. d/php-fpm add permissions for Control Scripts

[Root @ lly php-5.4.3] # cd/usr/local/php/etc/

[Root @ lly etc] # cp php-fpm.conf.default php-fpm.conf to generate php-fpm configuration file

[Root @ lly etc] # chkconfig -- add php-fpm

[Root @ lly etc] # chkconfig -- list | grep fpm

[Root @ lly etc] # service php-fpm start

[Root @ lly etc] # netstat-tupln | grep php-fpm

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-18178 "border =" 0 "alt =" wps_clip_image-18178 "width =" 555 "height =" 34 "src =" http://www.bkjia.com/uploads/allimg/131228/0143401062-15.png "/>

In this case, nginx needs to be able to complete php page requests.

[Root @ lly etc] # vim/etc/nginx. conf

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-12192 "border =" 0 "alt =" wps_clip_image-12192 "width =" 555 "height =" 118 "src =" http://www.bkjia.com/uploads/allimg/131228/0143403E1-16.png "/>

Clearly write the Home Page

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-17317 "border =" 0 "alt =" wps_clip_image-17317 "width =" 555 "height =" 98 "src =" http://www.bkjia.com/uploads/allimg/131228/0143403a9-17.png "/>

Make a php test page for testing

[Root @ lly etc] # cd/usr/local/nginx/html/

[Root @ lly html] # ll

Total 16

-Rw-r -- 1 root 383 Apr 13 50x.html

-Rw-r -- 1 root 151 Apr 13 index.html

[Root @ lly html] # Change index.html to index. php in mv index.html index.php

[Root @ lly html] # vim index. php

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-17003 "border =" 0 "alt =" wps_clip_image-17003 "width =" 476 "height =" 206 "src =" http://www.bkjia.com/uploads/allimg/131228/014340L47-18.png "/>

Restart nginx and fastcgi services

[Root @ lly html] # service nginx restart

[Root @ lly html] # service php-fpm restart

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-26698 "border =" 0 "alt =" wps_clip_image-26698 "width =" 555 "height =" 290 "src =" http://www.bkjia.com/uploads/allimg/131228/01434022P-19.png "/>

Edit test page test and database connection

[Root @ lly html] # vim index. php

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-22537 "border =" 0 "alt =" wps_clip_image-22537 "width =" 555 "height =" 244 "src =" http://www.bkjia.com/uploads/allimg/131228/014340OW-20.png "/>

Enter http: // 192.168.126.129 in the browser

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-19688 "border =" 0 "alt =" wps_clip_image-19688 "width =" 554 "height =" 157 "src =" http://www.bkjia.com/uploads/allimg/131228/0143405310-21.png "/>

The connection to the database is successful.

Iv. Installation and Use of Php acceleration tool xcache

[Root @ lly ~] # Tar-zxvf xcache-2.0.1.tar.gz-C/usr/local/src/

[Root @ lly ~] # Cd/usr/local/src/xcache-2.0.1/

[Root @ lly xcache-2.0.1] # less INSTALL view installation instructions

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-10601 "border =" 0 "alt =" wps_clip_image-10601 "width =" 555 "height =" 144 "src =" http://www.bkjia.com/uploads/allimg/131228/0143401043-22.png "/>

Use phpize to generate the configure file

But where is phpize? In fact, it is in the/usr/local/php/bin/directory.

Direct execution

[Root @ lly xcache-2.0.1] #/usr/local/php/bin/phpize

Then the configure file is generated under the/usr/local/src/xcache-2.0.1/directory.

Install

[Root@llyxcache-2.0.1] #./configure -- enable-xcache -- with-php-config =/usr/local/php/bin/php-config

[Root @ lly xcache-2.0.1] # make

[Root @ Lili xcache-2.0.1] # make install

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-3128 "border =" 0 "alt =" wps_clip_image-3128 "width =" 555 "height =" 22 "src =" http://www.bkjia.com/uploads/allimg/131228/01434044I-23.png "/>

This directory is the directory of the modules formed by the combination of xcache and php.

[Root @ lly xcache-2.0.1] # cp xcache. ini/etc/php5.d/Description: install php when there is a php.5 file xcache and php to be a good combination of xcache. ini file copied to the past

[Root @ lly xcache-2.0.1] # vim/etc/php5.d/xcache. ini

Lines 2 and 12 are configured in windows and commented out with double semicolons.

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-15808 "border =" 0 "alt =" wps_clip_image-15808 "width =" 555 "height =" 122 "src =" http://www.bkjia.com/uploads/allimg/131228/0143401222-24.png "/>

Compile the test page

[Root @ lly xcache-2.0.1] # cd/usr/local/nginx/html/

[Root @ lly html] # vim index. php

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-4734 "border =" 0 "alt =" wps_clip_image-4734 "width =" 555 "height =" 209 "src =" http://www.bkjia.com/uploads/allimg/131228/0143401261-25.png "/>

[Root @ lly html] # service php-fpm restart

Enter http: // 192.168.126.129 in the browser

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-12983 "border =" 0 "alt =" wps_clip_image-12983 "width =" 555 "height =" 356 "src =" http://www.bkjia.com/uploads/allimg/131228/0143403492-26.png "/>

In this way, xcache and php are combined successfully.

To facilitate xcache Management

[Root @ lly html] # cd/usr/local/src/xcache-2.0.1/

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-10078 "border =" 0 "alt =" wps_clip_image-10078 "width =" 552 "height =" 103 "src =" http://www.bkjia.com/uploads/allimg/131228/0143403456-27.png "/>

This directory contains php page files managed by xcache.

[Root @ lly xcache-2.0.1] # cp-r admin // usr/local/nginx/html/copy the files under admiin to the html directory

[Root @ lly html] # chmod a + rx admin/Add access view Permissions

[Root @ lly html] # cd admin/

[Root @ lly admin] # chmod a + r index. php add view permission

Enter http: // 192.168.126.129/admin in the browser

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-30562 "border =" 0 "alt =" wps_clip_image-30562 "width =" 330 "height =" 252 "src =" http://www.bkjia.com/uploads/allimg/131228/0143405934-28.png "/>

Enter the default username and password admin to log on.

650) this. width = 650; "style =" border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right -: "title =" wps_clip_image-13215 "border =" 0 "alt =" wps_clip_image-13215 "width =" 555 "height =" 160 "src =" http://www.bkjia.com/uploads/allimg/131228/0143403094-29.png "/>

This article is from the "HWOTT" blog, please be sure to keep this source http://iceblock.blog.51cto.com/6758400/1190538

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.