CentOS6.5 compiling and installing Nginx1.70 +php5.59+mysql5.6.16

Source: Internet
Author: User
Download the SOFTWARE toolkit:

1. Download Nginx

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

2, download pcre (support 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 of the above packages to the new/data/soft directory

">" stands for command line prompt


To install the compilation tools and library files:

>yum install make apr* autoconf automake bzip2 bzip2-devel Curl curl-devel gcc gcc-c++ gcc-g77 e2fsprogs e2fsprogs-deve L zlib* zlib-devel OpenSSL openssl-devel pcre-devel gd 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 libselinux-devel Krb5-devel zlib-devel libxpm* freetype freetype-devel libpng* libpng10 libpng10-devel libpng-devel php-common php-gd ncur ses* ncurses-devel libtool* libtool-libs libxml2-devel patch glibc glibc-devel glib2 glib2-devel krb5 krb5-devel libevent Libevent-devel libidn libidn-devel nss_ldap openldap openldap-clients openldap-devel openldap-servers OpenSSL Openssl-devel Pspell-devel net-snmp* net-snmp-devel-y


Installing CMake

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

>CD cmake-2.8.12.2

>./configure && make && make install


Install MySQL

>groupadd MySQL #添加mysql组

>useradd-g MySQL mysql-s/bin/false #创建用户mysql并加入到mysql组, does not allow MySQL users to log in directly to the system

>mkdir-p/data/mysqldata #创建MySQL数据库存放目

>chown-r Mysql:mysql/data/mysqldata #设置MySQL数据库目录权限

>mkdir-p/usr/local/mysql #创建MySQL安装目录

>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_sharedir=share

>make && make Install

Detailed compilation parameters Reference: http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html


Configure MySQL

>mkdir/tmp #用作缓存

>chown-r mysql:mysql/tmp/#必须为目录授权, otherwise cannot write

>CP./support-files/my-default.cnf/etc/my.cnf #拷贝配置文件 (Note: If the/etc directory has a my.cnf under the default, you can overwrite it directly)

>VI/ETC/MY.CNF #编辑配置文件, add the following line in the [mysqld] section

DataDir =/data/mysqldata #添加MySQL数据库路径

: wq! #保存退出

>cd/usr/local/mysql

>./scripts/mysql_install_db--user=mysql--datadir=/data/mysqldata/#生成mysql系统数据库

>CP./support-files/mysql.server/etc/rc.d/init.d/mysql #把Mysql加入系统启动

>chmod 755/etc/init.d/mysql #增加执行权限

>chkconfig MySQL on #加入开机启动

>vi/etc/rc.d/init.d/mysql #编辑

Basedir =/usr/local/mysql #MySQL程序安装路径

DataDir =/data/mysqldata #MySQl数据库存放目录

: wq! #保存退出

>service MySQL start #启动

>vi/etc/profile #把mysql服务加入系统环境变量: Add the following line at the end

Export path= $PATH:/usr/local/mysql/bin

: wq! #保存退出

The following line links the MYSLQ library file to the default location of the system, so you can compile software like PHP without specifying the MySQL library file address.

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

>reboot #需要重启系统, wait for the system to restart after the operation continues under the terminal command line

>mysql_secure_installation #设置Mysql密码

Press Y to enter as prompted

Then enter the password 2 times

Continue to press Y to enter until Setup is complete

or modify the password directly/usr/local/mysql/bin/mysqladmin-u root-p password "123456" #修改密码

>service MySQL Restart #重启

To this, MySQL installation is complete!


Installing Pcre

>cd/data/soft

>mkdir/usr/local/pcre #创建安装目录

>tar ZXVF pcre-8.35.tar.gz

>CD pcre-8.35

>./configure--prefix=/usr/local/pcre #配置

>make && make Install


Installing Nginx

>cd/data/soft

>groupadd WebUser #添加webuser组

>useradd-g webuser webuser-s/bin/false #创建nginx运行账户webuser并加入到webuser组, do not allow webuser users to log in directly to the system

>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 source package decompression path, not the installation path, otherwise it will be an error

>make && make Install

>/usr/local/nginx/sbin/nginx #启动nginx


Set Nginx on Start

>vi/etc/rc.d/init.d/nginx

#编辑启动文件添加下面内容

#!/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 $ 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 $} ' | Xargs Kill-hup

echo "Done"

;;

Restart

$ stop

$ start

;;

Show

Ps-aux|grep Nginx

;;

*)

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

;;

Esac

: wq! #保存退出

>chmod 775/etc/rc.d/init.d/nginx #赋予文件执行权限

>chkconfig Nginx on #设置开机启动

>/etc/rc.d/init.d/nginx Restart #重启

>service nginx Restart


Installing Libmcrypt

>cd/data/soft

>tar ZXVF libmcrypt-2.5.8.tar.gz

>CD libmcrypt-2.5.8

>./configure && make && 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 #复制php配置文件到安装目录

>rm-rf/etc/php.ini #删除系统自带配置文件

>ln-s/usr/local/php5/etc/php.ini/etc/php.ini #添加软链接

>cp/usr/local/php5/etc/php-fpm.conf.default/usr/local/php5/etc/php-fpm.conf #拷贝模板文件为php-fpm configuration file

>vi/usr/local/php5/etc/php-fpm.conf #编辑

user = webuser# Set php-fpm run account is WebUser

Group = webuser# Set PHP-FPM run Group is WebUser

PID = Run/php-fpm.pid #取消前面的分号

Set PHP-FPM boot up

: wq! #保存退出

>CP/DATA/SOFT/PHP-5.5.9/SAPI/FPM/INIT.D.PHP-FPM/ETC/RC.D/INIT.D/PHP-FPM #拷贝php-fpm to startup directory

>chmod +X/ETC/RC.D/INIT.D/PHP-FPM #添加执行权限

>chkconfig PHP-FPM on #设置开机启动

>vi/usr/local/php5/etc/php.ini #编辑配置文件

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_uname

#列出PHP可以禁用的函数, if some programs need to use this function, you can delete, cancel disable.

Found:;d Ate.timezone =

Modified to: Date.timezone = PRC #设置时区

Found: expose_php = On

Modified to: expose_php = Off #禁止显示php版本的信息

Found: Short_open_tag = Off

Modified to: Short_open_tag = on #支持php短标签

: wq! #保存退出


Configuring Nginx Support PHP

>vi/usr/local/nginx/conf/nginx.conf

#编辑配置文件, you need to make the following changes

User WebUser WebUser; #首行user去掉注释, modify Nginx run group to WebUser WebUser; must be the same as User,group configuration in/usr/local/php5/etc/php-fpm.conf, or PHP will run in error

Index index.php index.html index.htm; #添加index. php

#取消FastCGI the comment for the server section location, and note the parameters of the Fastcgi_param row, change to $document_root$fastcgi_script_name, or use the absolute path

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

Location ~ \.php$ {

Root/data/wwwroot; #修改根目录到/data/wwwroot, the default 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;

}

#同时在下面增加以下部分支持图片和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! #保存退出

>/etc/init.d/nginx Restart #重启nginx

>chown webuser.webuser/data/wwwroot/-R #设置默认网站根目录所有者, default is/usr/local/nginx/html

>chmod 700/usr/local/nginx/html/-R #设置目录权限

>shutdown-r now #重启系统


Modify firewall allows access to ports 80 and 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 that the configuration is complete, create a new index.php test

>vi/data/wwwroot/index.php #在nginx网站根目录新建index. php

Phpinfo ();

?>

: wq! #保存退出

Access to your site through http://yourip/index.php, such as see PHP information instructions to run properly


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

server-related operations commands

Service Nginx Restart #重启nginx

Service MySQL Restart #重启mysql

/USR/LOCAL/PHP5/SBIN/PHP-FPM #启动php-FPM

/ETC/RC.D/INIT.D/PHP-FPM Restart #重启php-fpm

/ETC/RC.D/INIT.D/PHP-FPM Stop #停止php-FPM

/ETC/RC.D/INIT.D/PHP-FPM 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

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