码迷,mamicode.com
首页 > 其他好文 > 详细

lanmp 环境搭建

时间:2016-05-29 23:31:24      阅读:335      评论:0      收藏:0      [点我收藏+]

标签:lamp lnmp


软件分享:链接:http://pan.baidu.com/s/1dEbn229 密码:91xm 

一,安装Apache

    1,mini Linux安装必要包

    yum -y grouplist
    yum -y groupinstall ‘Development tools,Desktop Platform Development‘
    yum -y groupinstall ‘开发工具,桌面平台开发‘


    2,安装apr-1.5.0

    # tar xf apr-1.5.0.tar.gz
    # cd apr-1.5.0
    # ./configure --prefix=/usr/local/apr
    # make && make install

    3,安装apr-util-1.5.3

    # tar xf apr-util-1.5.3.tar.bz2
    # cd apr-util-1.5.3
    # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
    # make && make install

    4,安装pcre

  unzip pcre-8.32.zip
  cd pcre-8.32
  ./configure --prefix=/usr/local/pcre
  make && make install

    5,安装Apache

5.1 出现openssl错误:
yum -y install openssl-devel

tar xf httpd-2.4.10.tar.gz
cd httpd-2.4.10
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre=/usr/local/pcre/ --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event

5.2 make && make install
编辑/etc/httpd24/httpd.conf,添加如下行即可:shift+g定位到行尾
PidFile  "/var/run/httpd.pid"

5.3 编辑一个/etc/rc.d/init.d/httpd
-------------------------------------
#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve \#        HTML files and CGI.
# processname: httpd
# config: /etc/httpd24/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi
 
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
 
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
 
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
 
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
 
start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}
 
stop() {
  echo -n $"Stopping $prog: "
  killproc -p ${pidfile} -d 10 $httpd
  RETVAL=$?
  echo
  [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=$?
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
    fi
    echo
}
 
# See how we were called.
case "$1" in
  start)
  start
  ;;
  stop)
  stop
  ;;
  status)
        status -p ${pidfile} $httpd
  RETVAL=$?
  ;;
  restart)
  stop
  start
  ;;
  condrestart)
  if [ -f ${pidfile} ] ; then
    stop
    start
  fi
  ;;
  reload)
        reload
  ;;
  graceful|help|configtest|fullstatus)
  $apachectl $@
  RETVAL=$?
  ;;
  *)
  echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
  exit 1
esac
 
exit $RETVAL
-----------------------------------------------
5.4 添加脚本的执行权限
chmod +x /etc/rc.d/init.d/httpd
service httpd start | stop

二,安装nginx

6,安装zlib

tar zxvf zlib-1.2.8.tar.gz 
cd zlib-1.2.8
./configure --prefix=/usr/local/zlib
make && make install

7,安装openssl

tar zxvf openssl-1.0.2-latest.tar.gz
tar zxvf nginx-1.7.12.tar.gz 
cp -R openssl-1.0.2a/ /usr/local/src/nginx-1.7.12

8,安装nginx

groupadd www
whereis nologin
useradd -g www -s /sbin/nologin www
mkdir /usr/local/nginx/
cd nginx-1.7.12
./configure --prefix=/usr/local/nginx --user=www --group=www --sbin-path=/usr/local/nginx/sbin --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --error-log-path=/usr/local/nginx/nginx-error.log  --with-http_ssl_module --with-pcre=/soft/lamp_linux/pcre-8.32 --with-zlib=/soft/lamp_linux/zlib-1.2.8 --with-openssl=/soft/lamp_linux/openssl-1.0.2e
make && make install
mkdir /usr/local/nginx/access 保持日志
mkdir /usr/local/nginx/vhost 保持虚拟配置文件
vi /etc/rc.d/init.d/nginx
启动脚本:
----------------------------------
#!/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_config=/usr/local/nginx/nginx.conf
nginx_pid=/usr/local/nginx/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 $nginx_pid
}

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
--------------------------------------
授权:
 chmod 755 /etc/rc.d/init.d/nginx 
 chkconfig nginx on
service nginx restart

三,安装MySQL

    9,安装MySQL

tar zxvf mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz  -C /usr/local/
cd /usr/local/
ln -sv mysql-5.6.15-linux-glibc2.5-x86_64/ mysql
groupadd -r mysql
useradd -g mysql -r -s /sbin/nologin  -M -d /usr/local/mysql/data mysql
chown  -R mysql:mysql .
cd mysql
cp support-files/my-default.cnf  /etc/my.cnf
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
yum -y install libaio-devel
scripts/mysql_install_db --user=mysql
service mysqld start
./bin/mysqladmin -u root password ‘hadoop123‘
./bin/mysql -u root -p

四,安装php

    10,安装bzip2

 yum -y install bzip2-devel

       11,安装libmcrypt

tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure --prefix=/usr/local/libmcrypt
make && make install

    12,安装libiconv

  tar xf libiconv-1.14.tar.gz 
  cd libiconv-1.14
  ./configure --prefix=/usr/local/libiconv
  make && make install

        13,安装libxml

  cd libxml2-2.9.0
  ./configure --prefix=/usr/local/libxml2 --with-zlib=/usr/local/zlib/
  make && make install

    14,安装curl

tar zxvf curl-7.42.0.tar.gz
cd curl-7.42.0
./configure --prefix=/usr/local/curl
make && make install

    15,安装php

./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --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/local/libxml2 --enable-xml --enable-sockets   --with-mcrypt=/usr/local/libmcrypt/ --with-config-file-path=/etc/ --with-config-file-scan-dir=/etc/php.d  --with-bz2 --enable-maintainer-zts --enable-fpm --disable-fileinfo  --with-iconv=/usr/local/libiconv --with-curl=/usr/local/curl 
make && make install
cp php.ini-production /usr/local/php5.4/php5.4.ini
ln -sv  /usr/local/php5.4/php5.4.ini /etc/php5.4.ini
vi /etc/php5.4.ini 
------------------------------------------------------------------------
修改为:date.timezone = PRC #设置时区
-----------------------------------------------------------------------
cp /usr/local/php5.4/etc/php-fpm.conf.default  /usr/local/php5.4/etc/php-fpm.conf
rm -rf /etc/php.d/*
vi /usr/local/php5.4/etc/php-fpm.conf
----------------------------------------------------------------------------
 pid = run/php-fpm5.4.pid #取消前面的分号 
--------------------------------------------------------------------------
cp  sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php5.4-fpm
chmod +x /etc/rc.d/init.d/php5.4-fpm

vi /etc/rc.d/init.d/php5.4-fpm

技术分享


16,附上 nginx 与php整合配置

nginx.conf
----------------------------------
#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 8m;
        sendfile on;
        tcp_nopush     on;
        keepalive_timeout 60;
        tcp_nodelay on;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 128k;
        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.0;
        gzip_comp_level 2;
        gzip_types       text/plain application/x-javascript text/css application/xml;
        gzip_vary on;
        #limit_zone  crawler  $binary_remote_addr  10m;
        log_format ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;
    include /usr/local/nginx/vhost/*.conf;
}
-----------------------------------------------------
vhost/test.conf
------------------------------------------------------
server{    
    listen 80;
    #ssl on;
        server_name  localhost;
     #ssl_certificate      /ssl/server.crt;
     #ssl_certificate_key  /ssl/server.key;
    #error_page 404 /404.html;
    location /404.html{
    }    
     location / {
            autoindex on;
        root   /opt/php/php_test/; 
        index  index.php index.html index.htm;
            if (-e $request_filename) {
                       break;
               }
               if (!-e $request_filename) {
                       rewrite ^/(.*)$ /index.php/$1 last;
                       break;
               }
        }
    location ~ .+\.php($|/) {
            root       /opt/php/php_test/;
            fastcgi_index  index.php;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param   PATH_INFO               $fastcgi_path_info;
            fastcgi_param   PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_pass   127.0.0.1:9000;
            include        fastcgi_params;
        }
             location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { 
                root /opt/php/php_test/; 
                if (-f $request_filename) { 
                        expires 1d; 
                        break; 
                        } 
                }   
    #include /alidata/server/nginx/conf/rewrite/phpwind.conf;
        access_log  /usr/local/nginx/access/localhost.log;
}

----------------------------END--------------------------------







本文出自 “dsczs博客” 博客,请务必保留此出处http://dsczs.blog.51cto.com/9480367/1784251

lanmp 环境搭建

标签:lamp lnmp

原文地址:http://dsczs.blog.51cto.com/9480367/1784251

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!