Note:
Operating System: CentOS 6.3 32-bit
Preparation:
1. Configure the IP address, DNS, and gateway to ensure that the remote connection tool can be used to connect to the server.
2. configure the firewall and enable port 80 and port 3306
Vi/etc/sysconfig/iptables
-A input-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT # Allow port 80 to pass the Firewall
-A input-m state -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT # Allow port 3306 to pass the Firewall
Note: many users add these two rules to the last line of the firewall configuration, which causes firewall startup failure. The correct rule should be added to the default port 22.
The firewall rules are as follows:
######################################## #################
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
* Filter
: Input accept [0: 0]
: Forward accept [0: 0]
: Output accept [0: 0]
-A input-m state -- state ESTABLISHED, RELATED-j ACCEPT
-A input-p icmp-j ACCEPT
-A input-I lo-j ACCEPT
-A input-m state -- state NEW-m tcp-p tcp -- dport 22-j ACCEPT
-A input-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT
-A input-m state -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT
-A input-j REJECT -- reject-with icmp-host-prohibited
-A forward-j REJECT -- reject-with icmp-host-prohibited
COMMIT
######################################## #################
/Etc/init. d/iptables restart # restart the firewall to make the configuration take effect.
3. Disable SELINUX
Vi/etc/selinux/config
# SELINUX = enforcing # comment out
# SELINUXTYPE = targeted # comment out
SELINUX = disabled # Add
: Wq save, close
Shutdown-r now # restart the system
Iv. system conventions
Software source code package storage location:/usr/local/src
Source code package compilation and installation location:/usr/local/software name
5. download the software package
1. Download nginx (current stable version)
Http://nginx.org/download/nginx-1.2.2.tar.gz
2. Download pcre (support for nginx pseudo-static)
Ftp://ftp.csx.cam.ac.uk/pub/soft... re/pcre-8.31.tar.gz
4. Download MySQL
Http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.25a.tar.gz
5. Download php
Http://cn.php.net/distributions/php-5.4.5.tar.gz
6. Download cmake (MySQL compilation tool)
Http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
7. Download libmcrypt (PHPlibmcrypt module)
Http://nchc.dl.sourceforge.net/p... mcrypt-2.5.8.tar.gz
The preceding Software Package uploads data to the/usr/local/src directory using tools.
6. Install the compilation tool and library file (use the CentOS yum command for installation)
Yum install make apr * autoconf automake curl-devel gcc-c ++ zlib-devel openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat * mpfr cpp glibc libgomp libstdc ++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm * freetype libjpeg * libpng * php-common php-gd ncurses * libtool * libxml2 libxml2-devel patch
Installation
Use putty to remotely log on to the server.
1. Install cmake
Cd/usr/local/src
Tar zxvf cmake-2.8.8.tar.gz
Cd cmake-2.8.8
./Configure
Make # compile
Make install # install
Ii. Install mysql
Groupadd mysql # Add a mysql Group
Useradd-g mysql-s/bin/false # create a user mysql and add it to the mysql group. mysql users are not allowed to log on directly to the system.
Mkdir-p/data/mysql # create a directory for storing MySQL Databases
Chown-R mysql: mysql/data/mysql # Set MySQL database Directory Permissions
Mkdir-p/usr/local/mysql # create the MySQL installation directory
Cd/usr/local/src
Tar zxvf mysql-5.5.25a.tar.gz # Extract
Cd mysql-5.5.25a
Cmake.-DCMAKE_INSTALL_PREFIX =/usr/local/mysql-DMYSQL_DATADIR =/data/mysql-DSYSCONFDIR =/etc # Configuration
Make # compile
Make install # install
Cd/usr/local/mysql
Cp./support-files/my-huge.cnf/etc/my. cnf # copy the configuration file (Note: if there is a my. cnf under the/etc directory by default, directly overwrite it)
Vi/etc/my. cnf # edit the configuration file and add the following line in the [mysqld] Section
Datadir =/data/mysql # Add the MySQL database path
: Wq! # Save and exit
./Scripts/mysql_install_db -- user = mysql # generate a mysql System Database
Cp./support-files/mysql. server/etc/rc. d/init. d/mysqld # Add Mysql to the system to start
Chmod 755/etc/init. d/mysqld # Add execution permission
Chkconfig mysqld on # Add to startup
Vi/etc/rc. d/init. d/mysqld # Edit
Basedir =/usr/local/mysql # MySQL installation path
Datadir =/data/mysql # MySQl database storage directory
Service mysqld start # start
Vi/etc/profile # Add the mysql service to the system environment variable: Add the following line at the end
Export PATH = $ PATH:/usr/local/mysql/bin
: Wq! # Save and exit
The following two lines link the myslq library file to the default system location, so that you do not need to specify the mysql library file address when compiling software such as PHP.
Ln-s/usr/local/mysql/lib/mysql/usr/lib/mysql
Ln-s/usr/local/mysql/include/mysql/usr/include/mysql
Shutdown-r now # restart the system. Wait until the system is restarted and continue to perform the following operations on the terminal command line.
Mysql_secure_installation # Set the Mysql password
Press Y to press enter as prompted.
Enter the password twice.
Press Y and press enter until the setting is complete.
Or directly change the password/usr/local/mysql/bin/mysqladmin-u root-p password "123456" # change the password
Service mysqld restart # restart
At this point, mysql installation is complete!
3. Install pcre
Cd/usr/local/src
Mkdir/usr/local/pcre # create the installation directory
Tar zxvf pcre-8.31.tar.gz
Cd pcre-8.31
./Configure -- prefix =/usr/local/pcre # Configuration
Make
Make install
4. Install nginx
Cd/usr/local/src
Groupadd www # Add a www Group
Useradd-g www-s/bin/false # create an nginx Running Account www and add it to the www group. www users are not allowed to log on to the system directly.
Tar zxvf nginx-1.2.2.tar.gz
Cd nginx-1.2.2
. /Configure -- prefix =/usr/local/nginx -- without-http_memcached_module -- user = www -- group = www -- with-http_stub_status_module -- with-openssl =/usr/-- with-pcre =/usr/local /src/pcre-8.31
Note: -- with-pcre =/usr/local/src/pcre-8.31 points to the path of the source package decompression, rather than the installation path, otherwise an error will be reported
Make
Make install
/Usr/local/nginx/sbin/nginx # Start nginx
Enable nginx startup
Vi/etc/rc. d/init. d/nginx # edit the Startup File and add the following content
========================================================== ====================
#! /Bin/bash
# Nginx Startup script for the Nginx HTTP Server
# It is v.0.0.2 version.
# Chkconfig:-85 15
# Description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# Processname: nginx
# Pidfile:/var/run/nginx. pid
# Config:/usr/local/nginx/conf/nginx. conf
Nginxd =/usr/local/nginx/sbin/nginx
Nginx_config =/usr/local/nginx/conf/nginx. conf
Nginx_pid =/usr/local/nginx/logs/nginx. pid
RETVAL = 0
Prog = "nginx"
# Source function library.
./Etc/rc. d/init. d/functions
# Source networking configuration.
./Etc/sysconfig/network
# Check that networking is up.
[$ {NETWORKING} = "no"] & exit 0
[-X $ nginxd] | exit 0
# Start nginx daemons functions.
Start (){
If [-e $ nginx_pid]; then
Echo "nginx already running ...."
Exit 1
Fi
Echo-n $ "Starting $ prog :"
Daemon $ nginxd-c $ {nginx_config}
RETVAL =$?
Echo
[$ RETVAL = 0] & touch/var/lock/subsys/nginx
Return $ RETVAL
}
# Stop nginx daemons functions.
Stop (){
Echo-n $ "Stopping $ prog :"
Killproc $ nginxd
RETVAL =$?
Echo
[$ RETVAL = 0] & rm-f/var/lock/subsys/nginx/usr/local/nginx/logs/nginx. pid
}
Reload (){
Echo-n $ "Reloading $ prog :"
# Kill-HUP 'cat $ {nginx_pid }'
Killproc $ nginxd-HUP
RETVAL =$?
Echo
}
# See how we were called.
Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Reload)
Reload
;;
Restart)
Stop
Start
;;
Status)
Status $ prog
RETVAL =$?
;;
*)
Echo $ "Usage: $ prog {start | stop | restart | reload | status | help }"
Exit 1
Esac
Exit $ RETVAL
========================================================== ====================
: Wq! # Save and exit
Chmod 775/etc/rc. d/init. d/nginx # grant the File Execution permission
Chkconfig nginx on # Set startup
/Etc/rc. d/init. d/nginx restart # restart
Service nginx restart
5. Install libmcrypt
Cd/usr/local/src
Tar zxvf libmcrypt-2.5.8.tar.gz # Extract
Cd libmcrypt-2.5.8 # Go To The Directory
./Configure # Configuration
Make # compile
Make install # install
6. install php
Cd/usr/local/src
Tar-zvxf php-5.4.5.tar.gz
Cd php-5.4.5
Mkdir-p/usr/local/php5 # create a php installation directory
. /Configure -- prefix =/usr/local/php5 -- with-config-file-path =/usr/local/php5/etc -- with-mysql =/usr/local/mysql -- with-mysqli =/usr/local/mysql/bin/mysql_config -- with-mysql-sock =/tmp/mysql. sock -- with-gd -- with-iconv -- with-zlib -- enable-xml -- enable-bcmath -- enable-shmop -- enable-sysvsem -- enable-inline-optimization -- with-curlwrappers -- enable-mbregex -- enable-fpm -- enable-mbstring -- enable-ftp -- enable-gd-native-ttf -- with-openssl -- enable-pcntl -- enable-sockets -- with-xmlrpc -- enable-zip -- enable-soap -- without-pear -- with-gettext -- enable-session -- with-mcrypt -- with-curl # Configuration
Make # compile
Make install # install
Cp php. ini-production/usr/local/php5/etc/php. ini # copy the php configuration file to the installation directory
Rm-rf/etc/php. ini # Delete the built-in configuration file of the system
Ln-s/usr/local/php5/etc/php. ini/etc/php. ini # Add soft link
Cp/usr/local/php5/etc/php-fpm.conf.default/usr/local/php5/etc/php-fpm.conf # copy the template file as the php-fpm configuration file
Vi/usr/local/php5/etc/php-fpm.conf # Edit
User = www # Set the php-fpm runtime account to www
Group = www # Set the php-fpm running group to www
Pid = run/php-fpm.pid # Remove the semicolon above
Set the startup of php-fpm
Cp/usr/local/src/php-5.4.5/sapi/fpm/init. d. php-fpm/etc/rc. d/init. d/php-fpm # copy php-fpm to the startup directory
Chmod + x/etc/rc. d/init. d/php-fpm # Add execution permission
Chkconfig php-fpm on # Set startup
Vi/usr/local/php5/etc/php. ini # edit the configuration file
Find: disable_functions =
To:
Disable_functions = passthru, exec, system, chroot, scandir, chgrp, chown, shell_exec, proc_open, proc_get_status, ini_alter, ini_alter, disconnect, dl, openlog, syslog, readlink, symlink, release, delimiter, delimiter, dll, popen, disk_free_space, checkdnsrr, checkdnsrr, getservbyname, getservbyport, delimiter, posix_getgrnam, posix_getgroups, posix_getlogin, delimiter, delimiter, posix_getpid, delimiter, delimiter, posix_getpwuid, delimiter, posix_getsid, posix_getuid, delimiter, posix_kill, posix_mkfifo, delimiter, posix_setsid, posix_setuid, posix_strerror, posix_times, posix_ttyname, posix_uname
# List functions that can be disabled by PHP. If some programs need this function, they can be deleted and disabled.
Locate:; date. timezone =
Change to: date. timezone = PRC # set the time zone
Find: expose_php = On
Change to: expose_php = OFF # disable display of php version information
Find: short_open_tag = Off
Changed to: short_open_tag = ON # php short labels supported
VII. Configure nginx to support php
Vi/usr/local/nginx/conf/nginx. conf # modify the configuration file as follows:
User www; # Remove comments from the first line of user and change the Nginx runtime group to www; the group configuration must be the same as the user in the/usr/local/php5/etc/php-fpm.conf, otherwise, an error occurred while running php.
Index. php index.html index.htm; # add index. php
# Pass the PHP scripts to FastCGI server listening on Fig: 9000
#
Location ~ \. Php $ {
Root html;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Include fastcgi_params;
}
# Cancel the location comment of the FastCGI server and change the parameter of the fastcgi_param line to $ document_root $ fastcgi_script_name or use the absolute path.
/Etc/init. d/nginx restart # restart nginx
Test
Cd/usr/local/nginx/html/# enter the default nginx website root directory
Rm-rf/usr/local/nginx/html/* # Delete the default test page
Vi index. php # Edit
<? Php
Phpinfo ();
?>
: Wq! # Save and exit
Chown www. www/usr/local/nginx/html/-R # Set the directory owner
Chmod 700/usr/local/nginx/html/-R # Set Directory Permissions
Shutdown-r now # restart the system
Open the Server IP address in the browser and you will see the following interface. The configuration is successful.
Server-related operation commands
Service nginx restart # restart nginx
Service mysqld restart # restart mysql
/Usr/local/php5/sbin/php-fpm # Start php-fpm
/Etc/rc. d/init. d/php-fpm restart # restart php-fpm
/Etc/rc. d/init. d/php-fpm stop # stop php-fpm
/Etc/rc. d/init. d/php-fpm start # start php-fpm
######################################## #####################################
Note:
The default nginx site directory is/usr/local/nginx/html/
Permission settings: chown www: www/usr/local/nginx/html/-R
The MySQL database directory is/data/mysql.
Permission settings: chown mysql. mysql-R/data/mysql
So far, CentOS 6.3 compilation and installation of Nginx1.2.2 + mysql5.25a + PHP5.4.5 are complete