Compile and install the LNMP platform (Nginx1.0.10 + PHP5.3.8 + _ MySQL) under CentOS6.0 (X64)

Source: Internet
Author: User
Tags localhost mysql openldap
Compile and install the LNMP platform (Nginx1.0.10 + PHP5.3.8 + Mysql5.5.18) in CentOS6.0 (X64) lnmpcentosng.pdf

BitsCN.com

Compile and install the LNMP platform in CentOS 6.0 (X64) (Nginx1.0.10 + PHP5.3.8 + Mysql5.5.18)

1. install CentOS 6

1.1 Use the VMware virtual machine for installation and the installation interface

(The allocated memory must be greater than 1 GB. Otherwise, the figure-based installation interface is not displayed. the "Bridge Mode" or "Bridged" mode is used for network settings)

1.2 Select Install or upgrade an existing system

1.3 select "skip" in the "Disc found" box"

1.4 next select "chinese (simplified) (chinese (introduction) next

1.5 select "American English style" next step

1.6 select "basic storage device" and click Next

1.7 when the "warning" box is displayed, select "reinitialize all"

1.8 The default host name can be retained. click "configure network" to bring up "network connection" and double-click "System eth0"

1.9 click "edit System eth0", select "automatic connection", click "application", and click "close" network connection "in the pop-up window.

1.10 do not select "use UTC time for system clock" next step

1.11 enter and confirm "root password" next step

1.12 select "replace existing Linux system" next "write modifications to disk"

1.13 select "Basic Server" and click Next

1.14 there are about 590 software packages in total. after copying and installing the software, click "reboot" and restart the computer.

1.15 (after installation, you can change the VM memory from 1 GB to 512 MB)

II. update centos6

2.1 update

Yum update-y

2.2 check the version and confirm it as "CentOS Linux release 6.0 (Final )"

Lsb_release-

2.2 install the compiler

Yum install-y gcc-c ++

3. install Google-perftools (use tcmalloc to accelerate mysql and nginx)

3.1 download the desired file

Download libunwind-1.0.1.tar.gz to/usr/local/src

3.2 install libunwind

Cd/usr/local/src/

Tar zvxf libunwind-1.0.1.tar.gz

Cd libunwind-1.0.1

./Configure -- enable-shared

Make & make install

3.3 install google-perftools

Cd/usr/local/src/

Tar zvxf google-perftools-1.8.3.tar.gz

Cd google-perftools-1.8.3

./Configure -- enable-shared -- enable-frame-pointers

Make & make install

3.4 update so that the dynamic link library can be shared by the system

Echo "/usr/local/lib">/etc/ld. so. conf. d/usr_local_lib.conf

Ldconfig

4. install mysql

4. 1. download an object

Download ncurses-5.9.tar.gz to/usr/local/src
Download bison-2.5.tar.gz to/usr/local/src
Download cmake-2.8.6.tar.gz to/usr/local/src
Download mysql-5.5.18.tar.gz to/usr/local/src

4.2 install ncurses

Yum install ncurses-devel-y

Cd/usr/local/src/

Tar zvxf ncurses-5.9

./Configure

Make & make install

4.3 install cmake

Cd/usr/local/src/

Tar zvxf cmake-2.8.6.tar.gz

Cd cmake-2.8.6

./Bootstrap

Make & make install

4.4 install bison

Cd/usr/local/src/

Tar zvxf bison-2.5.tar.gz

Cd bison-2.5

./Configure

Make & make install

4.5 create directories, configuration users, and user groups required by mysql

Groupadd mysql

Useradd-g mysql

Mkdir-p/data/mysql

Chown-R mysql: mysql/data/mysql

. Install mysql (the cmake ncurses-devel bison Library is required)

4.6.1 installation

Cd/usr/local/src/

Tar zvxf mysql-5.5.18.tar.gz

Cd mysql-5.5.18

Cmake-DCMAKE_INSTALL_PREFIX =/opt/mysql-DMYSQL_DATADIR =/data/mysql-connector = 1-connector = 1-connector = 1-DSYSCONFDIR =/etc/-DWITH_SSL = yes-DDEFAULT_CHARSET = utf8-DDEFAULT_COLLATION = utf8_general_ci-DWITH_READLINE = on

Make & make install

4.6.2 create a soft connection

Ln-s/opt/mysql/lib */usr/lib/

4.6.3 configure the mysql database

Cd/opt/mysql
./Scripts/mysql_install_db -- basedir =/opt/mysql/-- datadir =/data/mysql/-- user = mysql

4.6.4 copy the configuration file

Cp./support-files/my-large.cnf/etc/my. cnf

4.6.5 modify the configuration file and set utf8 encoding by default.

Vim/etc/my. cnf
Add a row under [client]
Default-character-set = utf8
Add a row under [mysqld]
Character-set-server = utf8

4.6.6 set mysql to automatically start the service
Cp./support-files/mysql. server/etc/rc. d/init. d/mysqld
Chkconfig -- add mysqld
Chkconfig -- level 345 mysqld on

4.6.7 modify the service configuration file
Vim/etc/rc. d/init. d/mysqld

Modify the following two items in the mysqld file as needed
Basedir =/opt/mysql
Datadir =/data/mysql

4.6.8 start the mysqld service
Service mysqld start

4.6.9 database initialization and modification of the root password (the root initial password is blank)
./Bin/mysql_secure_installation
Follow the prompts

4.6.10 soft connection to mysql

Ln-s/opt/mysql/bin

4.6.11 try to use root to connect to mysql after centos is restarted
Mysql-u root-p

Check the status after successful logon

Status;

4.6.12 using tcmalloc to optimize mysql (google-perftools must be installed)

Modify the MySQL startup script (depending on your MySQL installation location)
Vim/opt/mysql/bin/mysqld_safe

In the next line of # executing mysqld_safe, add:
Export LD_PRELOAD =/usr/local/lib/libtcmalloc. so

4.6.13 restart the service and check whether tcmalloc is effective (the second command is effective)

Service mysqld restart

Lsof-n | grep tcmalloc

If the following information is displayed, tcmalloc takes effect.

[Root @ localhost mysql] # lsof-n | grep tcmalloc
Mysqld 30347 mysql mem REG 253,0 2177570 544322/usr/local/lib/libtcmalloc. so.0.2.2

5. install Nginx

5. 1. Prepare for installation

Download pcre-8.20.tar.gz to/usr/local/src

Download nginx-1.0.10.tar.gz to/usr/local/src

5.2 update package

Yum install zlib * openssl *-y

5.3 install Pcre

Cd/usr/local/src/

Tar zvxf pcre-8.20.tar.gz

Cd pcre-8.20

./Configure

Make & make install

5.4 create www users and groups, create directories used by www Virtual hosts, and the log directories used by Nginx, and grant them appropriate permissions

Groupadd www
Useradd-g www

Mkdir-p/data/www
Chmod + w/data/www
Chown-R www: www/data/www

Add a directory for tcmalloc and grant appropriate permissions

Mkdir-p/tmp/tcmalloc/

Chown-R www: www/tmp/tcmalloc/

5.1 install Nginx (the pcre google-perftools Library is required)

5.5.1 installation

Cd/usr/local/src/

Tar zvxf nginx-1.0.10.tar.gz

Camouflage server information (not modified)

Cd nginx-1.0.10/src/core

Vim./src/core/nginx. h

Change NGINX_VERSION to the version number you want to display

Change NGINX_VER to the name you want to display

Change NGINX_VAR to the name you want to display

Save

Start Installation

./Configure -- user = www -- group = www -- prefix =/opt/nginx -- with-http_stub_status_module -- with-http_ssl_module -- with-google_perftools_module

Make & make install

5.4.2 modify nginx. conf so that nginx can be accelerated by google-perftools

Vim/opt/nginx/conf/nginx. conf

Modify the previous behavior:

User www;
Worker_processes 8;
Error_log logs/error. log crit;
Pid logs/nginx. pid;
Google_perftools_profiles/tmp/tcmalloc /;
Events {
Use epoll;
Worker_connections 65535;
}

5.4.3 test and run

Cd/opt/nginx

./Sbin/nginx-t

If the following information is displayed, the configuration is correct.

Nginx: the configuration file/opt/nginx/conf/nginx. conf syntax is OK
Nginx: configuration file/opt/nginx/conf/nginx. conf test is successful

Enter the code to run the nginx service

./Sbin/nginx

Ps au | grep nginx

If the following information is displayed, it indicates that nginx has been started.

Root 2013 0.0 0.0 103156 856 pts/0 S + grep nginx

Enter code to check whether acceleration is supported

Lsof-n | grep tcmalloc

If the following information is displayed, tcmalloc acceleration is supported (both mysqld and nginx threads support)

Mysqld 20818 mysql mem REG 253,0 2177570 281050/usr/local/lib/libtcmalloc. so.0.2.2

Nginx 29454 www 25 w REG 253,0 0 288399/tmp/tcmalloc/. 29454

Nginx 29455 www 27 w REG 253,0 0 288403/tmp/tcmalloc/. 29455

5.5.4 Open Firewall port 80

Write rules, save and restart services

Iptables-I INPUT-p tcp -- dport 80-j ACCEPT

/Etc/rc. d/init. d/iptables save

/Etc/init. d/iptables restart

View firewall information
/Etc/init. d/iptables status

If the following information is displayed, port 80 is enabled.

1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt: 80

5.5.5 compile nginx startup service

Cd/etc/init. d

Vim nginx

Enter the following code and save it.

#! /Bin/sh
#
# Nginx-this script starts and stops the nginx daemon
#
# Chkconfig:-85 15
# Description: Nginx is an HTTP (S) server, HTTP (S) reverse/
# Proxy and IMAP/POP3 proxy server
# Processname: nginx
# Config:/etc/nginx. conf
# Config:/etc/sysconfig/nginx
# Pidfile:/var/run/nginx. pid

# Source function library.
./Etc/rc. d/init. d/functions

# Source networking configuration.
./Etc/sysconfig/network

# Check that networking is up.
["$ NETWORKING" = "no"] & exit 0

Nginx = "/opt/nginx/sbin/nginx"
Prog = $ (basename $ nginx)

NGINX_CONF_FILE = "/opt/nginx/conf/nginx. conf"

[-F/etc/sysconfig/nginx] &./etc/sysconfig/nginx

Lockfile =/var/lock/subsys/nginx

Start (){
[-X $ nginx] | exit 5
[-F $ NGINX_CONF_FILE] | exit 6
Echo-n $ "Starting $ prog :"
Daemon $ nginx-c $ NGINX_CONF_FILE
Retval =$?
Echo
[$ Retval-eq 0] & touch $ lockfile
Return $ retval
}

Stop (){
Echo-n $ "Stopping $ prog :"
Killproc $ prog-QUIT
Retval =$?
Echo
[$ Retval-eq 0] & rm-f $ lockfile
Return $ retval
Killall-9 nginx
}

Restart (){
Configtest | return $?
Stop
Sleep 1
Start
}

Reload (){
Configtest | return $?
Echo-n $ "Reloading $ prog :"
Killproc $ nginx-HUP
RETVAL =$?
Echo
}

Force_reload (){
Restart
}

Configtest (){
$ Nginx-t-c $ NGINX_CONF_FILE
}

Rh_status (){
Status $ prog
}

Rh_status_q (){
Rh_status>/dev/null 2> & 1
}

Case "$1" in
Start)
Rh_status_q & exit 0
$1
;;
Stop)
Rh_status_q | exit 0
$1
;;
Restart | configtest)
$1
;;
Reload)
Rh_status_q | exit 7
$1
;;
Force-reload)
Force_reload
;;
Status)
Rh_status
;;
Condrestart | try-restart)
Rh_status_q | exit 0
;;
*)
Echo $ "Usage: $0 {start | stop | status | restart | condrestart | try-restart | reload | force-reload | configtest }"
Exit 2
Esac

After saving, set permissions and add them to the startup service list.

Chmod 755/etc/init. d/nginx

Chkconfig -- add nginx

Chkconfig -- level nginx

Service nginx start



6. install PHP

6.1 prepare for installation

Download php-5.3.6.tar.gz to/usr/local/src
Download libiconv-1.14.tar.gz to/usr/local/src
Download libmcrypt-2.5.8.tar.gz to/usr/local/src
Download mcrypt-2.6.8.tar.gz to/usr/local/src
Download mhash-0.9.9.tar.gz to/usr/local/src
Download libmcrypt-2.5.8.tar.gz to/usr/local/src

yum -y install autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libXpm* gcc gcc-c++

5.2 install libiconv (enhance the system's support for character encoding conversion)

Cd/usr/local/src/

Tar zvxf libiconv-1.14.tar.gz

Cd libiconv-1.14

./Configure -- prefix =/usr/local

Make & make install

5.3 install libmcrypt)

5.3.1 install libmcrypt

Cd/usr/local/src/

Tar zvxf libmcrypt-2.5.8.tar.gz

Cd libmcrypt-2.5.8

./Configure

Make & make install

5.3.2 install libltdl

Cd libltdl/

./Configure -- enable-ltdl-install

Make & make install

5.3.3 update sharing

Ln-sf/usr/local/lib/libmcrypt. */usr/lib64/
Ln-sf/usr/local/bin/libmcrypt-config/usr/lib64/
# Ln-sf/usr/local/lib/libiconv. so.2/usr/lib64/

Ldconfig

5.4 install mhash (hash Encryption Algorithm Library)

5.4.1 install mhash

Cd/usr/local/src/

Tar zvxf mhash-0.9.9.9.tar.gz

Cd mhash-0.9.9.9

./Configure

Make & make install

5.4.2 update sharing

Ln-sf/usr/local/lib/libmhash. */usr/lib64/

Ldconfig

5.5 install mcrypt

Cd/usr/local/src/

Tar zvxf mcrypt-2.6.8.tar.gz

Cd mcrypt-2.6.8

Ldconfig

./Configure

Make & make install

5.6 install php

5.6.1 create a mysql soft connection and an ldap soft connection

mkdir -p /opt/mysql/include/mysql
ln -s /opt/mysql/include/* /opt/mysql/include/mysql/

Ln-s/usr/lib64/libldap */usr/lib

5.6.2 installation

Cd/usr/local/src/

Tar zvxf php-5.3.8.tar.gz

Cd php-5.3.8

./configure --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-mysql=/opt/mysql --with-mysqli=/opt/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --disable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap

make ZEND_EXTRA_LIBS='-liconv'

Make install

5.6.3 copy the configuration file

cp php.ini-production /opt/php/etc/php.ini

5.6.4 installationmemcacheExtension (PHP already installed)

Cd/usr/local/src/

Tar zvxfmemcache-2.2.6.Tar.gz

Cdmemcache-2.2.6

/opt/php/bin/phpize

Cdmemcache-2.2.6

Ldconfig

./configure --with-php-config=/opt/php/bin/php-config

Make & make install

Modify the php configuration file and support memcache

Vim/opt/php/etc/php. ini

Search for extension_dir and extension in the file, and add the following two lines in the corresponding location
Extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20090626 /"
Extension = "memcache. so"

5.6.5 installationeacceleratorExtension (PHP already installed)

Cd/usr/local/src/

tar jxvf eaccelerator-0.9.6.1.tar.bz2

/opt/php/bin/phpize

./configure --enable-eaccelerator=shared --with-php-config=/opt/php/bin/php-config

Make & make install

Modify the php configuration file. eaccelerator is supported.

Vim/opt/php/etc/php. ini

Add the following code at the end of the file

[Eaccelerator]
Zend_extension = "/opt/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator. so"
Eaccelerator. shm_size = "32"
Eaccelerator. cache_dir = "/tmp/eaccelerator"
Eaccelerator. enable = "1"
Eaccelerator. optimizer = "1"
Eaccelerator. check_mtime = "1"
Eaccelerator. debug = "0"
Eaccelerator. log_file = "/opt/php/var/log/eaccelerator_log"
Eaccelerator. filter = ""
Eaccelerator. shm_max = "0"
Eaccelerator. shm_ttl = "3600"
Eaccelerator. shm_prune_period = "3600"
Eaccelerator. shm_only = "0"
Eaccelerator. compress = "1"
Eaccelerator. compress_level = "9"

Add the eaccelerator Directory
Mkdir-p/tmp/eaccelerator


5.6.5 install php-fpm

Cp/opt/php/etc/php-fpm.conf.default/opt/php/etc/php-fpm.conf
Vim/opt/php/etc/php-fpm.conf

Modify the following
[Global]
Pid = run/php-fpm.pid
Error_log = log/php-fpm.log
Emergency_restart_threshold = 10
Emergency_restart_interval = 1 m
Process_control_timeout = 5S
Pm. start_servers = 20
Pm. min_spare_servers = 5
Pm. max_spare_servers = 35

[Www]
User = www
Group = www

5.6.6 modify nginx and support php

Vim/opt/nginx/conf/nginx. conf

Find and modify the following code

Location ~ /. Php $ {
Root html;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME/data/www $ fastcgi_script_name;
Include fastcgi_params;
}

5.6.7 run php-fpm as a Service

Cd/usr/local/src/php-5.3.8
Cp./sapi/fpm/init. d. php-fpm/etc/init. d/php-fpm
Chmod 700/etc/init. d/php-fpm
Chkconfig -- add php-fpm
Chkconfig -- level 345 php-fpm on
Start php-fpm in service mode
Service php-fpm restart

5.6.8 compile the test page

Vim/data/www/index. php

Enter code


Hello php





5.6.8 open a browser for testing

BitsCN.com

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.