Always been imitated
Never surpassed

centos下 ngnix安装

wget http://nginx.org/download/nginx-1.5.13.tar.gz
wget –no-check-certificate http://sourceforge.net/projects/pcre/files/pcre/8.35/pcre-8.35.tar.gz
wget http://cn2.php.net/distributions/php-5.5.33.tar.gz
#http://php.net/get/php-5.5.33.tar.gz/from/a/mirror
wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.55.tar.gz

#安装编译工具及库文件(使用CentOS yum命令安装)
yum install make apr* autoconf automake curl-devel gcc gcc-c++ zlib-devel openssl 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  mysql-devel
(centos7 ibpng有新版,去掉ibpng)
Transaction Check Error:
file /usr/lib64/libxcb-icccm.so.1.0.0 from install of compat-xcb-util-0.3.6-6.el6.x86_64 conflicts with file from package xcb-util-0.3.6-1.el6.x86_64
(报错重复安装需卸载再执行安装)

yum -y remove xcb-util-0.3.6-1*

#安装libiconv
wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
tar -xvf libiconv-1.15.tar.gz
cd libiconv-1.15
./configure –prefix=/usr/local/libiconv
make && make install  -j4

#安装cmake

cd /home
wget –no-check-certificate http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
tar -xvf cmake-2.8.8.tar.gz
cd cmake-2.8.8
./configure
make && make install  -j4
#安装mysql
cd /home
wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.55.tar.gz
groupadd mysql
useradd -g mysql mysql -s /bin/false
mkdir -p /home/mysql
chown -R mysql:mysql /home/mysql
mkdir -p /usr/local/mysql
cd /home
tar -xvf mysql-5.5.55.tar.gz
cd mysql-5.5.55
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/home/mysql -DSYSCONDIR=/etc/
make && make install  -j4

cd /usr/local/mysql
cp ./support-files/my-huge.cnf /etc/my.cnf
vi /etc/my.cnf
#vi /etc/my.cnf #编辑配置文件,在 [mysqld] 部分增加
#datadir = /home/mysql #添加MySQL数据库路径

./scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql/ –datadir=/home/mysql  #生成mysql系统数据库
cp ./support-files/mysql.server  /etc/rc.d/init.d/mysqld  #把Mysql加入系统启动
chmod 755 /etc/init.d/mysqld -R   #增加权限
vi /etc/rc.d/init.d/mysqld
#basedir = /usr/local/mysql #MySQL程序安装路径
#datadir = /home/mysql #MySQl数据库存放目录
export PATH=$PATH:/usr/local/mysql/bin  #添加环境变量
service mysqld restart
/usr/local/mysql/bin/mysqladmin -S /tmp/mysql.sock -u root password ‘123.com’
chkconfig mysqld on               #加入开机启动
#php需要调用环境变量
ln -s /home/mysql/lib/mysql /usr/lib/mysql
ln -s /home/mysql/include/mysql /usr/include/mysql

#安装PCRE
cd /usr/local/src
mkdir /usr/local/pcre
wget –no-check-certificate http://sourceforge.net/projects/pcre/files/pcre/8.35/pcre-8.35.tar.gz
tar xvf pcre-8.35.tar.gz
cd pcre-8.35
./configure –prefix=/usr/local/pcre/
make && make install  -j4
安装nginx
groupadd www
useradd -g www www -s /bin/false
cd /home/
wget http://nginx.org/download/nginx-1.5.13.tar.gz
tar -xvf nginx-1.5.13.tar.gz
cd nginx-1.5.13
./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.35
make && make install  -j4
vi /etc/init.d/nginx  (脚本ngnix.txt中)

#!/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.
#              It has 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=/var/run/nginx.pid
RETVAL=0
prog=”nginx”
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = “no” ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo “nginx already running….”
exit 1
fi
echo -n $”Starting $prog: ”
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $”Stopping $prog: ”
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $”Reloading $prog: ”
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case “$1″ in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $”Usage: $prog {start|stop|restart|reload|status|help}”
exit 1
esac
exit $RETVAL

#!/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: /etc/sysconfig/nginx
# pidfile: /var/run/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
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
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
killall -9 nginx
}
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

chmod 755 /etc/rc.d/init.d/nginx
chkconfig nginx on
/etc/init.d/nginx  start

#安装libmcrypt
wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar -xvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install  -j4
#安装php
cd /home/
wget http://cn2.php.net/distributions/php-5.5.33.tar.gz
tar -xvf php-5.5.33.tar.gz
cd php-5.5.33
./configure –prefix=/usr/local/php5 –with-config-file-path=/usr/local/php5/etc –with-mysql=/usr/local/mysql –with-mysqli –with-gd –with-iconv –with-zlib –enable-xml –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 –with-pear –with-gettext –enable-session –with-mcrypt –with-curl
make && make install  -j4
cp php.ini-production /usr/local/php5/etc/php.ini
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
vi /usr/local/php5/etc/php-fpm.conf
user = www #设置php-fpm运行账号为www
group = www #设置php-fpm运行组为www
pid = run/php-fpm.pid #取消前面的分号

cp /home/php-5.5.33/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm  #拷贝php-fpm到启动目录

chmod +x /etc/rc.d/init.d/php-fpm
chkconfig php-fpm on
vi /usr/local/php5/etc/php.ini
修改为:date.timezone = PRC #设置时区
vi /usr/local/nginx/conf/nginx.conf
user  www www;
worker_processes  1;
events {
worker_connections  1024;
}

http {
include       mime.types;
default_type  application/octet-stream;

sendfile        on;
keepalive_timeout  65;
server {
listen       80;
root /usr/local/nginx/html;
server_name localhost;
index  index.html index.php index.htm;
location ~ \.php(.*)$ {
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
include        fastcgi_params;
}
location ~ /\.ht {
deny  all;
}
location ~* /themes\/.*\.(html|xml)$ {

return 403;

}
}
} 保存

cd /usr/local/nginx/html/
vi index.php
chown www.www /usr/local/nginx/html/ -R
chmod 755 /usr/local/nginx/html/ -R
export PATH=$PATH=/etc/init.d/nginx
service nginx restart
service nginx reload  测试

赞(0)
@请尊重原创,未经允许不得转载:军S小站 » centos下 ngnix安装

抢沙发

评论前必须登录!

 

智慧源于勤奋,伟大出自平凡

联系我们

© 2019 军S小站   ©备案号: 蜀ICP备17043886号-2    网站地图   友情链接