I. Install related dependent components
First install the basic dependency components in yum:
Yum install make apr * autoconf automake 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
(After yum is installed, the basic components are installed properly. You can install the latest components by compiling and installing the following code)
1: install zlib
Zlib official website: http://zlib.net
Wget http://zlib.net/zlib-1.2.8.tar.gz
Tar-xvzf zlib-1.2.8.tar.gz
Cd zlib-1.2.8.tar.gz
./Configure
Make
Make install
2: install freetype
Wget http://download.savannah.gnu.org/releases/freetype/freetype-2.5.0.1.tar.gz
Cd/usr/local/src
Tar-zxvf freetype-2.5.0.1.tar.gz
Cd freetype-2.5.0.1
./Configure -- prefix =/usr/local/freetype
Make
Make install
An error may occur during make:
/Usr/include/libpng12/pngconf. h: 336: error: expected '=', ';', 'asm 'or' _ attribute _ 'before '. 'token
/Usr/include/libpng12/pngconf. h: 337: error: expected '=', ';', 'asm 'or' _ attribute _ 'before' include'
Make: *** [/usr/local/src/freetype-2.5.0.1/objs/sfnt. lo] Error 1
Solution:
./Configure-prefix =/usr/local/freetype-without-png (add this option)
3: install libpng
Wget http://sourceforge.net/projects/libpng/files/libpng12/older-releases/1.2.31/libpng-1.2.31.tar.gz/download
Cd/usr/local/src
Tar-zxvf libpng-1.2.31.tar.gz
Cd libpng-1.2.31
./Configure
Make
Make install
4: install libxml2
Wget http://xmlsoft.org/sources/old/libxml2-2.7.1.tar.gz
Cd/usr/local/src
Tar-xzvf libxml2-2.7.1.tar.gz
Cd libxml2-2.7.1
./Configure -- prefix =/usr/local/libxml2 -- without-zlib (remember to add the following sentence, otherwise an error will occur)
Make
Make install
5. Install libmcypt.
Wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
Cd/usr/local/src
Tar zxvf libmcrypt-2.5.7.tar.gz
Cd libmcrypt-2.5.7
./Configure -- prefix =/usr/local/libmcrypt
Mak
Make install
6: install gd2 (the gd library of php will be used to compress and process images)
Wget http://ring.u-toyama.ac.jp/archives/graphics/gd/gd-2.0.35.tar.gz
Cd/usr/local/src
Tar-zxvf gd-2.0.35.tar.gz
Mkdir-p/usr/local/gd
Cd gd-2.0.35
. /Configure -- prefix =/usr/local/gd -- enable-m4_pattern_allow -- with-jpeg -- with-png -- with-zlib -- with-freetype =/usr/local/freetype -- with-libmcrypt =/usr/local/libmcrypt
Make
Make instal
(-With-jpeg: enables jpeg image processing;-with-png: supports png image processing)
An error may occur during compilation:
Compile and install gettext first.
Wget http://ftp.gnu.org/pub/gnu/gettext/gettext-0.18.3.1.tar.gz
Tar xzf gettext-0.18.3.1.tar.gz
Cd gettext-0.18.3.1
./Configure
Make
Make install
Note: If the gd Library version is gd-2.0.35 or above, you need./configure-enable-m4_pattern_allow or compile and install the gettext component and then re-compile gd
7. Install openssl
Wget https://www.openssl.org/source/openssl-1.0.1c.tar.gz # openssldir is the configuration file directory, it is recommended to install twice, the role of shared is to generate dynamic connection Library.
Tar-zxf openssl-1.0.1c.tar.gz
Cd openssl-1.0.1c/
./Config -- prefix =/usr/local/openssl -- openssldir =/usr/local/openssl/ssl
Make
Make install
./Config shared -- prefix =/usr/local/openssl -- openssldir =/usr/local/openssl/ssl
Make clean
Make
Make install
8: install curl
Wget http://curl.haxx.se/download/curl-7.17.1.tar.gz
Tar-zxvf curl-7.17.1.tar.gz
Cd curl-7.17.1
./Configure -- prefix =/usr/local/curl
Make
Make install
If an error occurs:
Curl. so-lz-lrt-Wl,-rpath-Wl,/usr/local/curl/lib
../Lib/. libs/libcurl. so: undefined reference to 'err _ remove_thread_state'
Collect2: ld returned 1 exit status
Make [2]: *** [curl] Error 1
Make [2]: Leaving directory '/usr/local/src/curl-7.32.0/src'
Make [1]: *** [all] Error 2
Make [1]: Leaving directory '/usr/local/src/curl-7.32.0/src'
Make: *** [all-recursive] Error 1
We recommend that you install the old version, especially if the openssl version is earlier than 1.0.
II. Install components required by nginx
1: install pcre
Wget http://sourceforge.net/projects/pcre/files/pcre/8.33/pcre-8.33.tar.gz/download
Tar-zxvf pcre-8.33.tar.gz
Cd pcre-8.33
./Configure -- enable-utf8
Make
Make install
III. Install nginx
Wget http://nginx.org/download/nginx-1.5.5.tar.gz
Tar xf nginx-1.5.5.tar.gz
Cd nginx-1.5.5
. /Configure -- prefix =/usr/local/nginx -- without-http_memcached_module -- user = www -- group = www -- with-http_stub_status_module -- with-openssl =/usr/local/openssl -- with-pcre =/ usr/local/src/pcre-8.33
# Note: -- with-pcre =/usr/local/src/pcre-8.31 points to the path of the source package decompression, rather than the installation path, otherwise the error will be reported
Make
Make install
Add the nginx boot script:
#! /Bin/sh
#
# Nginx-this script starts and stops the nginx daemon
# By www.osyunwei.com
# 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:/usr/local/nginx/conf/nginx. conf
# Pidfile:/usr/local/nginx/logs/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 = "/usr/local/nginx/sbin/nginx"
Prog = $ (basename $ nginx)
NGINX_CONF_FILE = "/usr/local/nginx/conf/nginx. conf"
[-F/etc/sysconfig/nginx] &./etc/sysconfig/nginx
Lockfile =/var/lock/subsys/nginx
Make_dirs (){
# Make required directories
User = '$ nginx-V 2> & 1 | grep "configure arguments:" | sed's/[^ *] * -- user = \ ([^] * \). */\ 1/g '-'
If [-z "'grep $ user/etc/passwd '"]; then
Useradd-M-s/bin/nologin $ user
Fi
Options = '$ nginx-V 2> & 1 | grep' configure arguments :''
For opt in $ options; do
If ['echo $ opt | grep'. *-temp-Path'']; then
Value = 'echo $ opt | cut-d "="-f 2'
If [! -D "$ value"]; then
# Echo "creating" $ value
Mkdir-p $ value & chown-R $ user $ value
Fi
Fi
Done
}
Start (){
[-X $ nginx] | exit 5
[-F $ NGINX_CONF_FILE] | exit 6
Make_dirs
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
}
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
#===================================================== ======================
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
Service nginx restart
4. Install mysql
Mysql official website: http://dev.mysql.com/downloads/ download source package
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/usr/local/mysql # create the MySQL installation directory
Mkdir-p/usr/local/mysql/data # Create a MySQL data storage directory
Tar zxvf mysql-5.5.21.tar.gz
Cd mysql-5.5.21
Cmake. -DCMAKE_INSTALL_PREFIX =/usr/local/mysql-DMYSQL_DATADIR =/usr/local/mysql/data-DSYSCONFDIR =/etc-DMYSQL_UNIX_ADDR =/tmp/mysql. sock-DWITH_INNOBASE_STORAGE_ENGINE = 1-DWITH_MYISAM_STORAGE_ENGINE = 1-DENABLED_LOCAL_INFILE = 1-DMYSQL_TCP_PORT = 3306-dwith_extra_sets char: STRING = utf8, gbk-DDEFAULT_CHARSET = utf8-DDEFAULT_COLLATION = utf8_general_ci-DWITH_DEBUG = 0-DWITH_READLINE = 1-DWITH_SSL = yes
# (Sometimes warnings such as/usr/local/mysql/data cannot be found. Continue to compile the program regardless of it)
Make
Make install
Cd/usr/local/mysql
Cp./support-files/my-huge.cnf/etc/my. cnf # directly overwrite if the file is prompted
Vim/etc/my. cnf # Added in [mysqld]
Datadir =/usr/local/mysql/data # Database storage path
./Scripts/mysql_install_db -- basedir =/usr/local/mysql -- datadir =/usr/local/mysql/data -- 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
Vim/etc/rc. d/init. d/mysqld # Edit
Basedir =/usr/local/mysql # MySQL installation path
Datadir =/usr/lcoal/mysql/data # MySQl database storage directory
Service mysqld start # start
/Usr/local/mysql/bin/mysql-u root-p # log on to mysql
# Modify the root user password after successful installation:
/Usr/local/mysql/bin/mysqladmin-u root-p password "new password" # press enter to enter the old password. After successful input, the password is successfully revised.
/Etc/init. d/mysqld restart # restart mysql. The installation is successful!
V. Install php
Wget http://cn2.php.net/get/php-5.3.27.tar.gz/from/ar2.php.net/mirror
. /Configure -- prefix =/usr/local/php -- with-config-file-path =/usr/local/php/etc -- with-mysql =/usr/local/mysql -- with-mysqli =/usr/local/mysql/bin/mysql_config -- with-mysql-sock =/tmp/mysql. sock -- with-pdo-mysql =/usr/local/mysql -- with-gd =/usr/local/gd -- with-png-dir =/usr/lib -- with-jpeg -dir =/usr/local/defaults 9 -- with-freetype-dir =/usr/local/freetype -- with-iconv -- with-zlib -- enable-xml -- enable-magic-quotes -- enable-safe-mode -- 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 =/usr/local/openssl -- enable-pcntl -- enable-sockets -- with-xmlrpc -- enable-zip -- enable-soap -- without-pear -- with-gettext -- enable-session -- with-mcrypt =/usr/local/libmcrypt -- with-curl =/usr/local/curl -- enable- ctype
Make
Make install
(-With-jpeg-dir use the default yum version)
Cp php. ini-production/usr/local/php/etc/php. ini
Cp sapi/fpm/init. d. php-fpm/etc/init. d/php-fpm
Cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
Vim/usr/local/php/etc/php-fpm.conf
Pid = run/php-fpm.pid # uncomment the following line:
Chmod + x/etc/init. d/php-fpm
Chkconfig -- add php-fpm
Chkconfig php-fpm on
Service php-fpm start # start php-fpn
Ps aux | grep php-fpm # check whether startup is normal
Netstat-ant | grep: 9000 # check whether the port is listening
Problems that may occur during configure configuration:
Checking for cURL in default path... Not found
Configure: error: Please reinstall the libcurl distribution-
Because the dev package of curl is not installed
Solution: yum-y install curl-devel
Problems that may occur during make compilation:
Virtual memory exhausted: Cannot allocate memory
Cause: the compilation process is a memory-consuming action. The memory is tight and cannot be allocated.
Solution: add the-disable-fileinfo parameter to the configuration item and re-compile it.
6. Configure nginx to support php
Vim/usr/local/nginx/conf/nginx. conf
User www; # remove comments from the first line of user and change the Nginx running group to www
Index. php index.html index.htm; # find this line and 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. Change the parameter of the fastcgi_param row to $ document_root $ fastcgi_script_name, or use the absolute path.
Vim/usr/local/php/etc/php-fpm.conf # Change user, group to www
# Restart nginx:
/Usr/local/nginx/sbin/nginx-t
/Usr/local/nginx/sbin/nginx-s reload
Kill-USR2 'cat/usr/local/php/var/run/php-fpm.pid '// restart php for the www user group and user to take effect
Vim/usr/local/nginx/html/index. php # Create a php file for testing
<? Php phpinfo ();?>
Enter the host IP address in the browser. The phpinfo information is displayed successfully.