CentOS 6.2 Compile and install nginx1.2.0+mysql5.5.25+php5.3.13
2013-10-24 15:31:12
Tags: server firewall file configuration file written
First, configure IP, DNS, gateway, ensure the use of Remote Connection tool to connect to the server
Second, configure the firewall, open 80 port, 3306 port
1 Vi/etc/sysconfig/iptables #编辑防火墙配置文件
1-a input-m State--state new-m tcp-p TCP--dport 80-j ACCEPT (allow port 80 via firewall)
2-a input-m State--state new-m tcp-p TCP--dport 3306-j ACCEPT (Allow port 3306 via firewall)
Special Note: Many netizens add these two rules to the last line of the firewall configuration, causing the firewall to fail to start
The correct one should be added to the default 22 port under this rule, after adding the firewall rule as follows:
01 #########################################################
# Firewall configuration written by System-config-firewall
# Manual Customization of this file are not recommended.
*filter, Geneva
05:input ACCEPT [0:0]
06:forward ACCEPT [0:0]
07:output ACCEPT [0:0]
08-a input-m State--state established,related-j ACCEPT
09-a input-p icmp-j ACCEPT
10-a input-i lo-j ACCEPT
11-a input-m State--state new-m tcp-p TCP--dport 22-j ACCEPT
12-a input-m State--state new-m tcp-p TCP--dport 80-j ACCEPT
13-a input-m State--state new-m tcp-p TCP--dport 3306-j ACCEPT
14-a input-j REJECT--reject-with icmp-host-prohibited
15-a forward-j REJECT--reject-with icmp-host-prohibited
COMMIT
17 #########################################################
1/etc/init.d/iptables Restart #最后重启防火墙使配置生效
Third, close SELinux
1 Vi/etc/selinux/config #编辑
1 #SELINUX =enforcing #注释掉
2 #SELINUXTYPE =targeted #注释掉
3 selinux=disabled #增加
4:wq #保存退出
1 Shutdown-r now #重启系统
Iv. System Conventions
Software source code Package storage location:/USR/LOCAL/SRC
Source Package Compilation Installation location:/usr/local/software Name
V. Download the package
1, download Nginx (currently the latest stable version)
Http://nginx.org/download/nginx-1.2.0.tar.gz
2, download pcre (support Nginx pseudo-static)
Ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
3, download MySQL (currently stable version)
Http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.5/mysql-5.5.25.tar.gz
4. Download PHP
http://www.php.net/releases/
5. Download CMake (MySQL compilation tool)
Http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
6. Download Libmcrypt (phplibmcrypt module)
Ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
Vi. install the compilation tools and library files (install using the CentOS Yum command)
Yum install make apr* autoconf automake curl-devel gcc gcc-c++ zlib-devel OpenSSL openssl-devel pcre-devel gd kernel Keyut Ils 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* L ibtool* libxml2 libxml2-devel Patch Freetype-devel
Installation article
First, install the CMake
1 cd/usr/local/src
2 TARZXVF cmake-2.8.8.tar.gz
3 cdcmake-2.8.8
4./configure
5 make# Compilation
6 makeinstall# Installation
Second, install MySQL
Groupadd MySQL #添加mysql组
useradd-g MySQL mysql-s/bin/false# create user MySQL and join the MySQL group, do not allow MySQL users to log in directly to the system
Mkdir-p/data/mysql #创建MySQL数据库存放目录
Chown-r Mysql:mysql/data/mysql #设置MySQL数据库目录权限
Mkdir-p/usr/local/mysql #创建MySQL安装目录
Cd/usr/local/src
TARZXVF mysql-5.5.25.tar.gz #解压
cdmysql-5.5.25
CMake. -dcmake_install_prefix=/usr/local/mysql-dmysql_datadir=/data/mysql-dsysconfdir=/etc #配置
Ten make# Compile
One-makeinstall# installation
Cd/usr/local/mysql
CP./SUPPORT-FILES/MY-HUGE.CNF/ETC/MY.CNF #拷贝配置文件 (Note: If the/etc directory has a my.cnf under the default, you can directly overwrite it)
VI/ETC/MY.CNF #编辑配置文件, add the following line in the [mysqld] section
DataDir =/data/mysql #添加MySQL数据库路径
16:wq! #保存退出
/scripts/mysql_install_db--user=mysql #生成mysql系统数据库
Cp./support-files/mysql.server/etc/rc.d/init.d/mysqld #把Mysql加入系统启动
Chmod755/etc/init.d/mysqld #增加执行权限
Chkconfig mysqld on #设置开机启动
Vi/etc/rc.d/init.d/mysqld #编辑
Basedir =/usr/local/mysql #MySQL程序安装路径
DataDir =/data/mysql #MySQl数据库存放目录
Service mysqld Start #启动
Vi/etc/profile #把mysql服务加入系统环境变量: Add the following line at the end
Exportpath= $PATH:/usr/local/mysql/bin
27:wq! #保存退出
28 The following two lines link the MYSLQ library file to the default location of the system, and you can compile software like PHP without specifying the MySQL library file address.
Ln-s/usr/local/mysql/lib/mysql/usr/lib/mysql
Ln-s/usr/local/mysql/include/mysql/usr/include/mysql
Shutdown-r now #需要重启系统, wait for the system to restart after the operation continues under the terminal command line
Mysql_secure_installation #设置Mysql密码
33 Press Y to enter as prompted (the default password is empty)
34 then enter 2 times the password
35 continue to press Y to enter until Setup is complete
36 or modify the password directly/usr/local/mysql/bin/mysqladmin-u root-p password "123456" #修改密码
PNS Service mysqld Restart #重启
38 to this, MySQL installation is complete!
Third, installation Pcre
1 cd/usr/local/src
2 Mkdir/usr/local/pcre #创建安装目录
3 TARZXVF pcre-8.30.tar.gz
4 cdpcre-8.30
5./configure--prefix=/usr/local/pcre #配置
6 Make
7 Makeinstall
Iv. installation of Nginx
Cd/usr/local/src
Groupadd www #添加www组
Useradd-g www www-s/bin/false# create nginx run account www and add to www Group, do not allow WWW users to log directly into the system
TARZXVF nginx-1.2.0.tar.gz
cdnginx-1.2.0
/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.30
#注意:--with-pcre=/usr/local/src/pcre-8.30 points to the path of the source package decompression, not the installation path, otherwise it will be an error
Make
Makeinstall
10/usr/local/nginx/sbin/nginx #启动nginx
Vi/etc/rc.d/init.d/nginx #设置nginx开启启动, edit the startup file to add the following content
01 #################################################################
#!/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.
The It had 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.
17. /etc/rc.d/init.d/functions
# Source Networking configuration.
19. /etc/sysconfig/network
# Check that networking are up.
[${networking} = "No"] && exit0
[-X $nginxd] | | Exit0
# Start Nginx daemons functions.
Start () {
if[-e $nginx _pid];then
echo "Nginx already running ..."
Exit1
-Fi
Echo-n $ "Starting $prog:"
Daemon $nginxd-C ${nginx_config}
Retval=$?
Echo
[$RETVAL = 0] && Touch/var/lock/subsys/nginx
Return$retval
35}
The # Stop Nginx daemons functions.
PNs Stop () {
Echo-n $ "Stopping $prog:"
Killproc $nginxd
Retval=$?
Echo
[$RETVAL = 0] && rm-f/var/lock/subsys/nginx/usr/local/nginx/logs/nginx.pid
43}
Reload () {
Echo-n $ "Reloading $prog:"
#kill-hup ' Cat ${nginx_pid} '
Killproc $nginxd-hup
Retval=$?
Echo
50}
# How we were called.
The case "$" in
+ start)
Si start
55;;
+ stop)
$ stop
58;;
Reload)
Reload
61;;
Restart)
The Stop
Start
65;;
66
Status)
Status $prog
Retval=$?
70;;
71 *)
echo$ "Usage: $prog {start|stop|restart|reload|status|help}"
Exit1
Esac
Exit$retval
76 #################################################################
1:wq! #保存退出
2 Chmod775/etc/rc.d/init.d/nginx #赋予文件执行权限
3 Chkconfig Nginx on #设置开机启动
4/etc/rc.d/init.d/nginx Restart #重启
V. Installation of Libmcrypt
1 cd/usr/local/src
2 TARZXVF libmcrypt-2.5.7.tar.gz #解压
3 cdlibmcrypt-2.5.7 #进入目录
4./configure #配置
5 make# Compilation
6 makeinstall# Installation
Vi. Installation of PHP
Cd/usr/local/src
TAR-ZVXF php-5.3.13.tar.gz
cdphp-5.3.13
Mkdir-p/USR/LOCAL/PHP5 #建立php安装目录
/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-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--enable-pcntl--enable-sockets--with-xmlrpc--enable-zip-- Enable-soap--without-pear--with-gettext--enable-session--with-mcrypt--with-curl-- with-jpeg-dir--with-freetype-dir# Configuration
make# compilation
makeinstall# Installation
Cpphp.ini-production/usr/local/php5/etc/php.ini #复制php配置文件到安装目录
Rm-rf/etc/php.ini #删除系统自带配置文件
Ten 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 = www #设置php-fpm run account is www
+ Group = www #设置php-fpm run Group is www
PID = Run/php-fpm.pid #取消前面的分号
CP/USR/LOCAL/SRC/PHP-5.3.13/SAPI/FPM/INIT.D.PHP-FPM/ETC/RC.D/INIT.D/PHP-FPM #设置 php-fpm boot, copy 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 #编辑配置文件
20 Found: Disable_functions =
21 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.
23 Found:;d Ate.timezone =
24 modified to: Date.timezone = PRC #设置时区
25 Found: expose_php = On
26 modified to: expose_php = OFF #禁止显示php版本的信息
In compiling PHP the process may be reported undefined REFERENCE to ' libiconv_open cannot compile PHP LIBICONV error.
Seven, configuration nginx support PHP
Vi/usr/local/nginx/conf/nginx.conf #编辑配置文件
User www www; #首行user去掉注释, modify the Nginx run group to www www; must be the same as the User,group configuration in/usr/local/php5/etc/php-fpm.conf, or PHP will run in error
index.php index index.html index.htm; #添加index. php
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
05 #
Location ~ \.php$ {
root html; #此处和server下面root保持一致, default to HTML
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Ten Fastcgi_param script_filename/usr/local/nginx/html/$fastcgi _script_name;
Include Fastcgi_params;
12}
Note: Uncomment the FASTCGI server section of the location, and note the parameters of the Fastcgi_param row instead of/data/webroot/(this is the site root absolute path) $fastcgi _script_name
1/etc/init.d/nginx Restart #重启nginx
CentOS 6.2 Compilation Installation nginx1.2.0+mysql5.5.25+php5.3.13