编译构建LNMP环境(step by step)

时间:2021-12-19 08:10:39
                                              编译构建LNMP环境
所需下载的软件包:
nginx-0.7.67.tar.gz
mysql-5.1.45-linux-i686-glibc23.tar.gz
php-5.3.3.tar.bz2
libevent-1.4.14b-stable.tar.gz
libiconv-1.13.1.tar.gz
安装nginx
#yum install gcc openssl-devel pcre-devel zlib-devel (yum安装开发环境)
# groupadd nginx  -r
# useradd -g -r nginx -s /bin/false -M nginx
#tar zxvf   nginx-0.7.67.tar.gz #cd nginx-0.7.67 #./configure \
  --prefix=/usr \
  --sbin-path=/usr/sbin/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --http-log-path=/var/log/nginx/access.log \
  --pid-path=/var/run/nginx/nginx.pid  \
  --lock-path=/var/lock/nginx.lock \
  --user=nginx \
  --group=nginx \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_stub_status_module \
  --with-http_gzip_static_module \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
#make && make install 关于配置选项的简单说明:(English你们自己看,我就不解释了,英语水平过低…haha) --prefix=<path> - The path relative to which all other Nginx paths will resolve. If not specified, defaults to /usr/local/nginx. --sbin-path=<path> - The path to the nginx executable. Only used for installation. If not specified defaults to <prefix>/sbin/nginx. --conf-path=<path> - The default location of nginx.conf if no -c parameter is provided. If not provided, defaults to <prefix>/conf/nginx.conf. --pid-path=<path> - The path to nginx.pid, if not set via the "pid" directive in nginx.conf. If not provided, defaults to <prefix>/logs/nginx.pid. --error-log-path=<path> - The location of the error log if not set via the "error_log" in nginx.conf. If not set, defaults to <prefix>/logs/error.log. --http-log-path=<path> - The location of the access log if not set via the "access_log" directive in nginx.conf. If not set, defaults to <prefix>/logs/access.log. --user=<user> - The default user that nginx will run as if not set in nginx.conf via the "user" directive. If not set, defaults to "nobody". --group=<group> - The default group that nginx will run under if not set via the "user" directive in nginx.conf. If not set defaults to "nobody". --with-http_ssl_module - Enable ngx_http_ssl_module. Enables SSL support and the ability to handle HTTPS requests. Requires OpenSSL. On Debian, this is libssl-dev. --with-http_flv_module - Enable ngx_http_flv_module --http-client-body-temp-path=PATH - Set path to the http client request body temporary files. If not set, defaults to <prefix>/client_body_temp --http-proxy-temp-path=PATH - Set path to the http proxy temporary files. If not set, defaults to <prefix>/proxy_temp --http-fastcgi-temp-path=PATH - Set path to the http fastcgi temporary files. If not set, defaults to <prefix>/fastcgi_temp --lock-path=<path> - The path to the nginx.lock file. If not provided, defaults to <prefix>/logs/nginx.lock. SYSTEM  V风格的init脚本 #!/bin/sh
#/etc/init.d/nginx
# 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/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/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' -`
   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
加入chkcong管理:
#chkcong   --add  nginx
验证nginx:
我更改了nginx的位置,因为我觉得那个默认的地方很难找,^_^
#vim /etc/nginx/nginx.conf
location / {
            root   /web;     #就这改了
            index  index.html index.htm;
        }
#mkdir /web
#echo "A TEST PAGE" > /web/index.html
#service nginx start
#chkcong nginx on
访问http://192.168.0.199
  编译构建LNMP环境(step by step)
搞定。。。。。 安装mysql-5.1.45
#cp mysql-5.1.45-linux-i686-glibc23.tar.gz  /usr/local/
#cd /usr/local
#tar zxvf  mysql-5.1.45-linux-i686-glibc23.tar.gz
#ln -sv  mysql  mysql-5.1.45-linux-i686-glibc23 
#groupadd -r mysql
#useradd -r -g mysql -s /bin/false -M  mysql
#chown -R mysql.mysql   .      #权限更改
#scripts/mysql_install_db --user=mysql  #初始化mysql
#chown -R root   .          #权限更改
#chown -R mysql data    #权限更改
添加mysql命令到系统环境变量中
vim /etc/profile
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC  之前
添加一行:
PATH=$PATH:/usr/local/mysql/bin
保存退出
重新执行一下该文件,不需要重新启动
# . /etc/profile
此时mysql还能不能找到其库文件的位置,我们来添加库文件的指向
创建/etc/ld.so.conf.d/mysql.conf文件
#touch  /etc/ld.so.conf.d/mysql.conf
#echo “/usr/local/mysql/lib” > /etc/ld.so.conf.d/mysql.conf
重新加载库文件
#ldconfig
此时mysql还不能找到其头文件,我们来给它一个链接
#ln -sv /usr/local/mysql/include  /usr/include/mysql
此时看似mysql大功告成了,呼呼,其实还差两步哈.....
配置文件:
# cp support-files/my-large.cnf  /etc/my.cnf
启动脚本加到chkcong中管理:
#cp  support-files/mysql.server  /etc/init.d/mysqld
#chkcong --add mysqld
好了,mysql配置 搞定了,下面启动测试:
#service  mysqld  start
#chkcong mysqld  on
#mysqladmin -uroot  password ‘123123’
登录测试
#mysql -uroot -p
如果能进入数据库则OK!
安装php-5.3.3 # tar jxvf php-5.3.3.tar.bz2
# cd jxvf php-5.3.3
# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm  --with-libevent-dir=/usr/local --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-iconv-dir=/usr/local
# make ZEND_EXTRA_LIBS='-liconv'       #使其识别liconv
# make install
# cp php.ini-dist /usr/local/php/etc/php.ini    #拷贝配置文件
fastcgi的设置(占用tcp 9000端口)
拷贝配置文件:
# cp /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf
编辑配置文件
vim /php-fpm.conf
保证有如下行
error_log
pm.start_server
pm.max_requests
pm.max_spare_servers
pm.min_spare_servers
pm.max_children
启动fastcgi:
#/usr/local/php/sbin/php-fpm  &
#
加入开机启动
echo “/usr/local/php/sbin/php-fpm &” >> /etc/rc.local
接下来整合nginx和php:
编辑nginx的fastcgi配置文件
#vim /etc/nginx/fastcgi.conf  #保证为以下行
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;
保证两个文件相同(fastcgi.conf fastcgi_params
# cat fastcgi.conf > fastcgi_params
编辑nginx配置文件
vim /etc/nginx/nginx.conf,启用如下选项:
location ~ \.php$ {
            root           /web;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
并在所支持的主页面格式中添加php格式的主页,类似如下:
location / {
            root   /web;
            index  index.php index.html index.htm;
        }
而后重启nginx。
# service nginx restart
验证nginx与php结合:
#rm -f  /web/index.html
#cat >> /web/index.php <<EOF
<?php
phpinfo();
?>
EOF
访问http://192.168.0.199
  编译构建LNMP环境(step by step)
也搞定啦。。。。 最后下我们开始验证三者的结合
#rm -f  /web/index.php
#cat >> /web/index.php <<EOF
<?php
$link=mysql_connect('localhost','root','123123');
if($link)
echo "success";
else
echo "fail";
?>
EOF

访问http://192.168.0.199


编译构建LNMP环境(step by step)   全部搞定,闪。。。。吃饭

本文出自 “一份存档” 博客,请务必保留此出处http://linuxbpm.blog.51cto.com/1823930/388465