CentOS 6.6 Server Compilation Installation LNMP (nginx1.6.2+mysql5.6.21+php5.6.3) _linux

Source: Internet
Author: User
Tags bz2 chmod create directory fpm gettext install php openssl iptables


Prepare the article:



CentOS 6.6 System Installation Configuration Diagram tutorial



Http://www.jb51.net/os/239738.html



First, configure the firewall, open 80 ports, 3306 ports


Vi/etc/sysconfig/iptables #Edit firewall configuration file
# Firewall configuration written by System-config-firewall
# Manual Customization of this file isn't recommended.
*filter
: INPUT ACCEPT [0:0]
: FORWARD ACCEPT [0:0]
: OUTPUT ACCEPT [0:0]
-A input-m State--state Establis Hed,related-j ACCEPT
-a input-p icmp-j ACCEPT-
a input-i lo-j ACCEPT
-a input-m state--state new-m t Cp-p TCP--dport 22-j ACCEPT
-a input-m state--state new-m tcp-p TCP--dport 3306-j ACCEPT
-a Input-m St Ate--state new-m tcp-p TCP--dport 80-j ACCEPT-
a input-j REJECT---reject-with icmp-host-prohibited
-a FORW Ard-j REJECT--reject-with icmp-host-prohibited
COMMIT



: wq! #Save and exit
Service iptables Restart # Finally restart the firewall for the configuration to take effect



Second, close SELinux


Vi / etc / selinux / config
#SELINUX = enforcing #comment out
#SELINUXTYPE = targeted #comment out
selinux = disabled #Increase


: wq! #Save and exit
Setenforce 0 #Make the configuration take effect immediately



Third, the system agreement



Software source code Package storage location:/USR/LOCAL/SRC
Source Package Compile Installation location:/usr/local/software Name



Four, download the software package


1, download Nginx
Http://nginx.org/download/nginx-1.6.2.tar.gz
2, download MySQL
Http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.21.tar.gz
3, download PHP
Http://cn2.php.net/distributions/php-5.6.3.tar.gz
4, download pcre (support nginx pseudo static)
Ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
5, download OpenSSL (nginx extension)
Http://www.openssl.org/source/openssl-1.0.1j.tar.gz
6, download zlib (nginx extension)
Http://zlib.net/zlib-1.2.8.tar.gz
7, download cmake (MySQL compiler Tool)
Http://www.cmake.org/files/v3.0/cmake-3.0.2.tar.gz
8, download libmcrypt (PHP extension)
Http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
9, download yasm (PHP extension)
Http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
10, t1lib (PHP extension)
Ftp://sunsite.unc.edu/pub/Linux/libs/graphics/t1lib-5.1.2.tar.gz
11, download the GD library installation package
Https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz
12, LIBVPX (GD library needs)
https://webm.googlecode.com/files/libvpx-v1.3.0.tar.bz2
13, TIFF (GD library needs)
Http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz
14, libpng (GD library needs)
Ftp://ftp.simplesystems.org/pub/png/src/libpng16/libpng-1.6.15.tar.gz
15, FreeType (GD library needs)
Http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/freetype-2.5.4.tar.gz
16, JPEGSRC (GD library needs)
Http://www.ijg.org/files/jpegsrc.v9a.tar.gz
The above packages are uploaded to the/USR/LOCAL/SRC directory using the WinSCP tool
WINSCP Download Address: http://winscp.net/download/winscp554.zip
Installation of compilation tools and library files (installed using the yum command)
Yum install-y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp Curl Curl-devel fontconfig Fontconfig-devel FreeType freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils ke Yutils-libs-devel krb5-devel libcom_err-devel libpng libpng* libpng-devel libjpeg* libsepol-devel libselinux-devel Libstdc++-devel libtool* libgomp libxml2 libxml2-devel libxpm* libx* libtiff libtiff* make MPFR ncurses* ntp OpenSSL nasm Openssl-devel Patch Pcre-devel perl php-common php-gd policycoreutils ppl telnet t1lib t1lib* wget zlib-devel nasm*


Installation article



The following is a remote login to the server with the Putty tool, operating below the command line



First, install MySQL



1. Installation CMake
Cd/usr/local/src
Tar zxvf cmake-3.0.2.tar.gz
CD cmake-3.0.2
./configure
Make
Make install



2, install MySQL


Groupadd MySQL #Add mysql group
useradd-g MySQL mysql-s / bin / false #Create user mysql and join to mysql group, MySQL users are not allowed to log on directly to the system
Mkdir-p / data / mysql #Create a MySQL database storage directory
Chown-r Mysql: mysql / data / mysql #Set MySQL database storage directory permissions
Mkdir-p / usr / local / mysql #Create a MySQL installation directory
CD / USR / LOCAL / SRC #Enter the package storage directory
Tar zxvf mysql-5.6.21.tar.gz #Unzip
CD mysql-5.6.21 #Enter the directory
CMake. -Dcmake_install_prefix = / usr / local / mysql-dmysql_datadir = / data / mysql-dsysconfdir = / etc #Configuration
Make #Compile
Make install #Install
Rm-rf / etc / my.cnf #Delete the system default configuration file (not deleted if default is not)
Cd / usr / local / mysql #Enter the MySQL installation directory
./scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql--datadir=/data/mysql #Generate mysql system database
Soft connection of ln-s / usr / local / mysql / my.cnf / etc / my.cnf #Add to / etc Directory
CP./SUPPORT-FILES/MYSQL.SERVER/ETC/RC.D/INIT.D/MYSQLD #Add Mysql to the system and start
chmod 755 / etc / init.d / mysqld #Add execute permission
Chkconfig mysqld on #Join startup
Vi / etc / rc.d / init.d / mysqld #Edit
Basedir = / usr / local / mysql #MySQL program installation path
Datadir = / data / mysql #MySQl database storage directory
: wq! #Save and exit
Service mysqld Start #Start
Vi / etc / profile #Add the mysql service to the system environment variables: Add the following line at the end
Export path = $ PATH: / usr / local / mysql / bin
: wq! #Save and exit
Source / etc / profile #Make the configuration take effect immediately
The following two lines link the MYSLQ library file to the default location of the system, so that you can compile software such as PHP without specifying MySQL's library file address.
Ln-s / usr / local / mysql / lib / mysql / usr / lib / mysql
Ln-s / usr / local / mysql / include / mysql / usr / include / mysql
Mkdir / var / lib / mysql #create directory
Ln-s / tmp / mysql.sock / var / lib / mysql / mysql.sock #Add soft link
Mysql_secure_installation #Set Mysql password, enter 2 times password according to the prompts Y return



Second, install Nginx





1. Installation Pcre
Cd / usr / local / src
Mkdir / usr / local / pcre
Tar zxvf pcre-8.36.tar.gz
CD pcre-8.36
./configure--prefix=/usr/local/pcre
Make
Make install





2. Installation OpenSSL





Cd / usr / local / src
Mkdir / usr / local / openssl
Tar zxvf openssl-1.0.1j.tar.gz
CD openssl-1.0.1j
./config--prefix=/usr/local/openssl
Make
Make install
Vi / etc / profile
Export path = $ PATH: / usr / local / openssl / bin
: wq!
Source / etc / profile
3. Installation zlib
CD / USR / LOCAL / SRC
Mkdir / usr / local / zlib
Tar zxvf zlib-1.2.8.tar.gz
CD zlib-1.2.8
./configure--prefix=/usr/local/zlib
Make
Make install





4. Installation Nginx





Groupadd www
Useradd-g www www-s / bin / false
Cd / usr / local / src
Tar zxvf nginx-1.6.2.tar.gz
CD nginx-1.6.2
./configure--prefix=/usr/local/nginx--without-http_memcached_module--user=www--group=www--with-http_stub_ Status_module--with-http_ssl_module--with-http_gzip_static_module--with-openssl = /usr/local/src/openssl-1.0.1j- -with-zlib = / usr / local / src / zlib-1.2.8--with-pcre = / usr / local / src / pcre-8.36
Note: --with-openssl = / usr / local / src / openssl-1.0.1j--with-zlib = / usr / local / src / zlib-1.2.8--with-pcre = / usr / local / src /pcre-8.36 Point is the source package decompression path, not the installation path, otherwise it will error
Make
Make install
/ usr / local / nginx / sbin / nginx #Start Nginx





Set Nginx Boot





Vi / etc / rc.d / init.d / nginx #Edit the startup file and add the following


#!/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/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 file execution permissions
Chkconfig Nginx on #Set boot
/etc/rc.d/init.d/nginx Restart #Restart
When you open the server IP address in the browser, you will see the following interface, which indicates that the Nginx installation was successful.











Third, the installation of PHP





1. Installation Yasm





Cd / usr / local / src
Tar zxvf yasm-1.3.0.tar.gz
CD yasm-1.3.0
./configure
Make
Make install





2. Installation Libmcrypt





Cd / usr / local / src
Tar zxvf libmcrypt-2.5.8.tar.gz
CD libmcrypt-2.5.8
./configure
Make
Make install





3. Installation LIBVPX





Cd / usr / local / src
Tar xvf libvpx-v1.3.0.tar.bz2
CD libvpx-v1.3.0
./configure--PREFIX=/USR/LOCAL/LIBVPX--enable-shared--ENABLE-VP9
Make
Make install





4. Install TIFF





Cd / usr / local / src
Tar zxvf tiff-4.0.3.tar.gz
CD tiff-4.0.3
./configure--prefix=/usr/local/tiff--enable-shared
Make
Make install





5. Installation libpng





Cd / usr / local / src
Tar zxvf libpng-1.6.15.tar.gz
CD libpng-1.6.15
./configure--prefix=/usr/local/libpng--enable-shared
Make
Make install





6. Installation FreeType





Cd / usr / local / src
Tar zxvf freetype-2.5.4.tar.gz
CD freetype-2.5.4
./configure--prefix=/usr/local/freetype--enable-shared
Make #Compile
Make install #Install





7. Install JPEG





Cd / usr / local / src
Tar zxvf jpegsrc.v9a.tar.gz
CD jpeg-9a
./configure--prefix=/usr/local/jpeg--enable-shared
Make #Compile
Make install #Install





8. Installation LIBGD





Cd / usr / local / src
Tar zxvf libgd-2.1.0.tar.gz #Unzip
CD libgd-2.1.0 #Go to the directory
./configure--PREFIX=/USR/LOCAL/LIBGD--enable-shared--with-jpeg=/usr/local/jpeg--with-png=/usr/local/libpng- With-freetype = / usr / local / freetype--with-fontconfig = / usr / local / freetype--with-xpm = / usr /-with-tiff = / usr / local / TIFF--with-vpx = / usr / local / libvpx #Configuration
Make #Compile
Make install #Install





9. Installation T1lib





Cd / usr / local / src
Tar zxvf t1lib-5.1.2.tar.gz
CD t1lib-5.1.2
./configure--prefix=/usr/local/t1lib--enable-shared
Make Without_doc
Make install





10. Install PHP



Note: If the system is 64 bits, please perform the following two commands, or install PHP will be wrong (32-bit system does not need to do)
\ cp-frp / usr / lib64 / libltdl.so * / usr / lib /
\ cp-frp / usr / lib64 / libxpm.so * / usr / lib /
Cd / usr / local / src
TAR-ZVXF php-5.6.3.tar.gz
CD php-5.6.3
Export Ld_library_path = / usr / local / libgd / lib
./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--with-png-dir = / usr / local / libpng--with-jpeg-dir = / usr / local / jpeg--with-freetype-dir = / usr / local / FreeType--with-xpm-dir = / usr /-with-vpx -dir = / usr / local / libvpx /-with-zlib-dir = / usr / local / zlib--with-t1lib = / usr / Local / t1lib--with-iconv--enable-libxml--enable- xml--enable-bcmath--enable-shmop-- Enable-inline-optimization--enable-opcache--enable-mbregex--enable-fpm--enable-mbstring--enable-ftp-- Enable-gd-native -ttf--with-openssl--enable-pcntl--enable-sockets--with-xmlrpc--enable-zip-- Without-pear--with-gettext--enable-session--with-mcrypt--with -curl--enable-ctype #Configuration
Make #Compile
Make install #Install
CP Php.ini-production / usr / local / php / etc / php.ini #Copy the php configuration file to the installation directory
Rm-rf / etc / php.ini #Delete the system's own configuration file
Ln-s / usr / local / php / etc / php.ini / etc / php.ini #Add soft link to / etc Directory
cp / usr / local / php / etc / php-fpm.conf.default / usr / local / php / etc / php-fpm.conf #Copy the template file to the php-fpm configuration file
Ln-s / usr / local / php / etc / php-fpm.conf / etc / php-fpm.conf #Add soft link to / etc Directory
Vi / usr / local / php / etc / php-fpm.conf #edit
user = www #setting php-fpm running account is www
Group = www #Set php-fpm run Group is www
PID = Run / php-fpm.pid #Cancel the preceding semicolon
: wq! #Save and exit
Set PHP-FPM boot

CP / USR / LOCAL / SRC / PHP-5.6.3 / SAPI / FPM / INIT.D.PHP-FPM / ETC / RC.D / INIT.D / PHP-FPM #Copy php-fpm to startup directory
chmod + x / etc / rc.d / init.d / php-fpm #Add execute permission
Chkconfig PHP-FPM on #
Vi / usr / local / php / etc / php.ini #Edit configuration file
Find: Disable_functions =
Modified to: Disable_functions = Passthru, exec, system, chroot, scandir, chgrp, chown, shell_exec, proc_open, proc_get_status, ini_alter, ini_alter, ini_restore, dl, openlog, syslog, readlink, symlink, popepassthru, stream_socket_server, Escapeshellcmd, dll popen, disk_free_space, checkdnsrr, checkdnsrr, getservbyname, getservbyport, disk_total_space, POSIX_CTERMID, POSIX_GET_LAST_ERROR, POSIX_GETCWD, Posix_getegid, posix_geteuid, posix_getgid, posix_getgrgid, posix_ getgrnam, posix_getgroups, posix_getlogin, posix_getpgid, posix_getpgrp, posix_getpid, Posix_getppid, posix_getpwnam, Posix_getpwuid, Posix_getrlimit, Posix_getsid , posix_getuid, posix_isatty, Posix_kill, posix_mkfifo, posix_setegid, Posix_seteuid, posix_setgid, Posix_setpgid, posix_setsid, posix_setuid, posix_strerror, posix_times, posix_ttyname, Posix_u
#List the functions that PHP can disable, if some programs need to use this function, you can remove it and disable it.
Find:; d Ate.timezone =
Modified as: Date.timezone = PRC #Set the time zone
Find: expose_php = On
Modified to: expose_php = off #Suppress information about PHP version
Find: Short_open_tag = Off
Modified to: Short_open_tag = on #Support php short tags
Find Opcache.enable = 0
Modified to Opcache.enable = 1 #php supports opcode caching
To find :; Opcache.enable_cli = 1 #php supports opcode caching
Modified to: opcache.enable_cli = 0
Add on last line: Zend_extension = opcache.so #Enable opcode caching
: wq! #Save and exit



11, configure Nginx support PHP





Vi / usr / local / nginx / conf / nginx.conf #Configuration modification
User www www. #First line user remove the comment, modify Nginx run group is www www; must be the same as the User, group configuration in / usr / local / php / etc / php-fpm.conf, otherwise PHP will run wrong
Index index.html index.htm index.php; #Add index. Php
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1: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 FastCGI the comments in the Location Server section, note fastcgi_param the parameters of the row, change to $ document_root $ fastcgi_script_name, or use an absolute path
/etc/init.d/nginx Restart #Restart nginx
Service PHP-FPM start #Start php-fpm
Test article
cd / usr / local / nginx / html / # Enter the nginx default website root directory
rm-rf / usr / local / nginx / html / * #Remove the default test page
VI index.php #New index. Php file



<? php
phpinfo ();
?>



: wq! #Save and exit
Chown www.www / usr / local / nginx / html / -R #Set directory owner
chmod 700 / usr / local / nginx / html / -R #Set directory permissions





Open the server IP address in the browser and see the following interface






At this point, CentOS 6.6 compiles the installation nginx1.6.2+mysql5.6.21+php5.6.3 tutorial complete.


Related Article

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.