Centos + Nginx + MySql + Php both LNMP source code compilation and 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

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

[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

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

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

[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

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

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

[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

[Root @ lly mysql] # ldconfig refresh

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

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

Mysql configuration complete

Ii. Install nginx

Install pcre (Compatible Regular Expression Library) and lievent before installing nginx

1. Install pcre (use the software package on the CD here)

[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

[Root @ lly libevent] # ldconfig refresh

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

[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

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

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

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

[Root @ lly ~] # Service nginx start nginx

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

Enter http: // 192.168.126.129/test in the browser

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

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

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

Clearly write the Home Page

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

Restart nginx and fastcgi services

[Root @ lly html] # service nginx restart

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

Edit test page test and database connection

[Root @ lly html] # vim index. php

Enter http: // 192.168.126.129 in the browser

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

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

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.

Compile the test page

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

[Root @ lly html] # vim index. php

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

Enter http: // 192.168.126.129 in the browser

In this way, xcache and php are combined successfully.

To facilitate xcache Management

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

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

Enter the default username and password admin to log on.

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.