安装lemp:
#!/bin/bash root=/opt/app if [ $(id -u) != "0" ]; then echo "Error: You must be root to run this script, please use root to install lnmp" exit 1 fi rpm -e php php-comman mysql mysql-server yum install -y gcc gcc-c++ openssl-devel zlib-devel libXpm-devel libxml2 libxml2-devel curl-devel libtool-ltdl.x86_64libtool-ltdl-devel.x86_64 openssl zlib-devel openssl-devel ncurses ncurses-devel glibc patch libtool libtool-devel groupadd mysql useradd -s /sbin/nologin -M -g mysql mysql mkdir /usr/local/mysql mkdir /usr/local/mysql/data wget http://wwwNaNake.org/files/v2.8/cmake-2.8.4.tar.gz tar -zxvpf cmake-2.8.4.tar.gz cd cmake-2.8.4 ./configure --prefix=/usr/local/cmake2.8.4 && make && make install echo -e "PATH=$PATH:$HOME/bin:/usr/local/cmake2.8.4/bin:$PATH/nexport PATH" >> path.sh bash path.sh cd $root tar zxf mysql-5.5.33.tar.gz cd mysql5.53 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DSYSCONFDIR=/usr/local/mysql/etc \ -DMYSQL_TCP_PORT=3306 \ -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \ -DMYSQL_USER=mysql \ -DEXTRA_CHARSETS=all \ -DWITH_READLINE=1 \ -DWITH_SSL=system \ -DWITH_EMBEDDED_SERVER=1 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 cp support-files/my-medium.cnf /etc/my.cnf sed -i 's:#innodb:innodb:g' /etc/my.cnf sed -i 's:/usr/local/mysql/data:/usr/local/mysql/var:g' /etc/my.cnf cp support-files/mysql.server /etc/init.d/mysqld /usr/local/mysql/bin/./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql datadir=/usr/local/mysql/var chown -R root:mysql /usr/local/mysql/ chown -R mysql /usr/local/mysql/var ln -s /usr/local/mysql/bin/* /usr/local/bin ln -s /usr/local/mysql/include/* /usr/include/ cp/usr/local/mysql/lib/* /usr/lib cp support-files/mysql.server /etc/init.d/mysql chkconfig --add mysqld chmod a+x /etc/init.d/mysqld tar xf mhash-0.9.9.9.tar.gz d mhash-0.9.9.9 ./configure && make && make install cd $root tar xf libmcrypt-2.5.7.tar.gz cd libmcrypt-2.5.7 ./configure && make && make install ./configure --prefix=/usr/local/libmcrypt && make && make install /sbin/ldconfig cd libltdl/ ./configure --enable-ltdl-install make && make install cd $root tar zxf zlib-1.2.8.tar.gz cd zlib-1.2.8 ./configure && make && make install ./configure --prefix=/usr/local/zlib && make && make install cd $root tar zxf libxml2-2.7.2.tar.gz cd libxml2-2.7.2 ./configure --with-zlib=/usr/local/zlib && make && make install cd $root tar xf libpng-1.5.19.tar.gz cd libpng-1.5.19 ./configure --prefix=/usr/local/libpng && make && make install cd $root tar xf freetype-2.4.9.tar.gz cd freetype-2.4.9 ./configure --prefix=/usr/local/freetype && make && make install Cd $root ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg/ --with-png=/usr/local/libpng/ --with-freetype=/usr/local/freetype/ && make && make install Cd $root tar xf php-5.3.6.tar.gz cd php-5.3.6 ./configure \ --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --with-mysql=/usr/local/mysql/ \ --with-libxml-dir=/usr/local/libxml2/ \ --with-png-dir=/usr/local/libpng/ \ --with-jpeg-dir=/usr/local/jpeg/ \ --with-freetype-dir=/usr/local/freetype/ \ --with-gd=/usr/local/gd/ \ --with-zlib-dir=/usr/local/zlib/ \ --with-mcrypt=/usr/local/libmcrypt/ \ --with-mysqli=/usr/local/mysql/bin/mysql_config \ --enable-soap \ --enable-mbstring=all \ --enable-sockets \ -enable-soap --enable-mbstring=all --enable-sockets --enable-fpm make && makeinstall cp php.ini-development /usr/local/php/etc/php.ini cd $root tar xf pcre-8.34.tar.gz cd pcre-8.34 ./configure && make && make install cd $root cd nginx-1.4.7 tar xf nginx-1.4.7.tar.gz cd nginx-1.4.7 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module make && make install ln-s/usr/local/lib/libpcre.so.1 /lib64/ cp php.ini.develepment /usr/local/php/etc/php.ini cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf sed -i 's:;pid = run/php-fpm.pid:pid=run/php-fpm.pid:' /usr/local/php/etc/php-fpm.conf sed -i 's:;pm.start_servers = 20:pm.start_servers=20:' /usr/local/php/etc/php-fpm.conf sed -i 's:;pm.min_spare_servers = 5:pm.min_spare_servers = 5:' /usr/local/php/etc/php-fpm.conf sed -i 's:;pm.max_spare_servers = 35:pm.max_spare_servers = 35:' /usr/local/php/etc/php-fpm.conf
NGINX控制脚本:
[root@centos-server ~]# vim /etc/init.d/nginx #!/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: /usr/local/nginx/local/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 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 [root@centos-server ~]# chkconfig --add nginx [root@centos-server ~]# chmod a+x /etc/init.d/nginx
NGINX主要配置:
user nobody; worker_processes 1; error_log logs/error.log; pid logs/nginx.pid; events { worker_connections 10240; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log ; sendfile on; tcp_nopush on; keepalive_timeout 30; gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.php index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; } } }
[root@centos-server ~]# cat >/usr/local/nginx/html/index.php<<end
<?phpinfo();?>
end
访问动态网页: