CentOS6.5 compile and install Nginx1.70 + PHP5.59 + MySQL5.6.16

Source: Internet
Author: User
Tags openldap
CentOS6.5 compile and install Nginx1.70 + PHP5.59 + MySQL5.6.16 Download the software toolkit:

1. download nginx

Http://nginx.org/download/nginx-1.7.0.tar.gz

2. download pcre (support for nginx pseudo-static)

Http://jaist.dl.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

4. download MySQL5.6.16

Http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.16.tar.gz

5. download php-5.5.9

Http://mirrors.sohu.com/php/php-5.5.9.tar.gz

6. download cmake (MySQL compilation tool)

Http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz

7. download libmcrypt (PHPlibmcrypt module)

Http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz


Conventions:

Upload all the preceding software packages to the new/data/soft directory.

">" Indicates a command line prompt.


Install the compilation tool and library files:

> Yum install make apr * autoconf automake bzip2 bzip2-devel curl-devel gcc-c ++ gcc-g77 e2fsprogs e2fsprogs-devel zlib * zlib-devel openssl-devel pcre-devel gd-devel kernel keyutils patch perl kernel-headers compat * mpfr cpp glibc libgomp libstdc ++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel kernel-devel krb5-devel zlib-devel libXpm * freetype freetype-devel libpng * libpng10 libpng10-devel libpng-devel php-common php-gd ncurses * ncurses-devel libtool * libtool-libs libxml2-devel patch glibc-devel glib2 glib2-devel krb5 krb5-devel libevent kernel-devel libidn-devel nss_ldap openldap-clients openldap-devel openldap-servers openssl-devel pspell-devel net-snmp * net-snmp-devel-y


Install cmake

> Cmake-2.8.12.2.tar.gz cd/data/soft & tar zxvf

> Cd cmake-2.8.12.2

>./Configure & make install


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 to the system directly.

> Mkdir-p/data/mysqldata # Create a MySQL database storage object

> Chown-R mysql: mysql/data/mysqldata # set MySQL database directory permissions

> Mkdir-p/usr/local/mysql # create the MySQL installation directory

> Cd/data/soft

> Tar zxvf mysql-5.6.16.tar.gz

> Cd mysql-5.6.16

>/Usr/local/bin/cmake-DCMAKE_INSTALL_PREFIX =/usr/local/mysql \

-DMYSQL_UNIX_ADDR =/tmp/mysql. sock \

-DDEFAULT_CHARSET = utf8 \

-DDEFAULT_COLLATION = utf8_general_ci \

-DWITH_EXTRA_CHARSETS: STRING = utf8, gbk \

-DWITH_MYISAM_STORAGE_ENGINE = 1 \

-DWITH_INNOBASE_STORAGE_ENGINE = 1 \

-DWITH_MEMORY_STORAGE_ENGINE = 1 \

-DWITH_READLINE = 1 \

-DENABLED_LOCAL_INFILE = 1 \

-DMYSQL_DATADIR =/data/mysqldata \

-DMYSQL_USER = mysql \

-DMYSQL_TCP_PORT = 3306 \

-DSYSCONFDIR =/etc \

-Dinstall_1_dir = share

> Make & make install

For detailed compilation parameter reference: http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html


Configure MySQL

> Mkdir/tmp # Used as cache

> Chown-R mysql: mysql/tmp/# The directory must be authorized; otherwise, data cannot be written.

> Cp./support-files/my-default.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/mysqldata # add the MySQL database path

: Wq! # Save and exit

> Cd/usr/local/mysql

>./Scripts/mysql_install_db -- user = mysql -- datadir =/data/mysqldata/# generate a mysql system database

> Cp./support-files/mysql. server/etc/rc. d/init. d/mysql # Add Mysql to the system to start

> Chmod 755/etc/init. d/mysql # Add execution permission

> Chkconfig mysql on # add to startup

> Vi/etc/rc. d/init. d/mysql # Edit

Basedir =/usr/local/mysql # MySQL installation path

Datadir =/data/mysqldata # MySQl database storage directory

: Wq! # Save and exit

> Service mysql 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 line links the myslq library file to the default location of the system, so that you do not need to specify the mysql library file address when compiling software such as PHP.

> Ln-s/usr/local/mysql/include/mysql/usr/include/mysql

> Reboot # 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 mysql restart # restart

At this point, mysql installation is complete!


Install pcre

> Cd/data/soft

> Mkdir/usr/local/pcre # create the installation directory

> Tar zxvf pcre-8.35.tar.gz

> Cd pcre-8.35

>./Configure -- prefix =/usr/local/pcre # configuration

> Make & make install


Install nginx

> Cd/data/soft

> Groupadd webuser # Add a webuser Group

> Useradd-g webuser-s/bin/false # Create a nginx running account webuser and add it to the webuser group. webuser users are not allowed to log on to the system directly.

> Tar zxvf nginx-1.7.0.tar.gz

> Cd nginx-1.7.0

>. /Configure -- prefix =/usr/local/nginx -- without-http_memcached_module -- user = webuser -- group = webuser -- with-http_stub_status_module -- with-openssl =/usr/-- with-pcre =/data/soft pcre-8.35

Note: -- with-pcre =/data/pcre-8.35 points to the path of the source package unzipping, 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

#

# Chkconfig:-85 15

# Description: Nginx is a World Wide Web server.

# Processname: nginx

Nginx =/usr/local/nginx/sbin/nginx

Conf =/usr/local/nginx/conf/nginx. conf

Case $1 in

Start)

Echo-n "Starting Nginx ..."

$ Nginx-c $ conf

Echo "done"

;;

Stop)

Echo-n "Stopping Nginx ..."

Killall-9 nginx

Echo "done"

;;

Test)

$ Nginx-t-c $ conf

;;

Reload)

Echo-n "Reloading Nginx ..."

Ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill-HUP

Echo "done"

;;

Restart)

$0 stop

$0 start

;;

Show)

Ps-aux | grep nginx

;;

*)

Echo-n "Usage: $0 {start | restart | reload | stop | test | show }"

;;

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 # restart

> Service nginx restart


Install libmcrypt

> Cd/data/soft

> Tar zxvf libmcrypt-2.5.8.tar.gz

> Cd libmcrypt-2.5.8

>./Configure & make install



Install PHP

> Cd/data/soft

> Tar zxvf php-5.5.9.tar.gz

> Cd php-5.5.9

> Mkdir-p/usr/local/php5

>. /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 -- 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

> Make & make install


Configure php

> 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 a soft link

> Cp/usr/local/php5/etc/php-fpm.conf.default/usr/local/php5/etc/php-fpm.conf # copy the template file to the php-fpm configuration file

& Gt; vi/usr/local/php5/etc/php-fpm.conf # Edit

User = webuser # set the php-fpm runtime account to webuser

Group = webuser # set the php-fpm runtime group to webuser

Pid = run/php-fpm.pid # Remove the semicolon above

Set the startup of php-fpm

: Wq! # Save and exit

& Gt; cp/data/soft/php-5.5.9/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

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

: Wq! # Save and exit


Configure nginx to support php

> Vi/usr/local/nginx/conf/nginx. conf

# Modify the configuration file as follows:

User webuser; # remove comments from the first line of user, modify Nginx runtime group to webuser; must be the same as the user in/usr/local/php5/etc/php-fpm.conf, group configuration, otherwise, an error occurred while running php.

Index. php index.html index.htm; # Add index. php

# 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.

# Pass the PHP scripts to FastCGI server listening on Fig: 9000

Location ~ \. Php $ {

Root/data/wwwroot; # Modify the root directory to/data/wwwroot. the default value is html.

Fastcgi_pass 127.0.0.1: 9000;

Fastcgi_index index. php;

Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;

Include fastcgi_params;

}

# Add the following sections below to support Image and js/css cache

Location ~. * \. (Jpg | jpeg | gif | css | png | ico | html )? $ {

Root/data/wwwroot /;

Expires 10d;

Break;

}

Location ~ . * \. (Js | css )? $ {

Root/data/wwwroot /;

Expires 30d;

Break;

}

: Wq! # Save and exit

>/Etc/init. d/nginx restart # restart nginx

> Chown webuser. webuser/data/wwwroot/-R # set the default website root directory owner. the default value is/usr/local/nginx/html.

> Chmod 700/usr/local/nginx/html/-R # set directory permissions

> Shutdown-r now # restart the system


Modify the firewall to allow access to port 80 and Port 3306

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

> Iptables-I INPUT-p tcp -- dport 3306-j ACCEPT

>/Etc/init. d/iptables save



Now the configuration is complete, and a new index. php test is created.

> Vi/data/wwwroot/index. php # Create index. php in the root directory of the nginx website

Phpinfo ();

?>

: Wq! # Save and exit

Visit your site through http: // yourip/index. php. if you see the php information, it indicates that it is running normally.


######################################## ###################################

Server-related operation commands

Service nginx restart # restart nginx

Service mysql 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


######################################## ###################################

Software installation directory description

Nginx:/usr/local/nginx

Php:/usr/local/php5

Mysql:/usr/local/mysql


Mysql database storage path:/data/mysqldata

Website Storage path:/data/wwwroot

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.