阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux单机部署LNMP环境

215次阅读
没有评论

共计 10247 个字符,预计需要花费 26 分钟才能阅读完成。

Linux 单机部署 LNMP 环境

1. 软件来源 

  • mysql-5.6.14 下载地址
  • nginx-1.5.1 下载地址
  • php-5.5.6 下载地址
2. 标准库安装

yum -y install wget make vim install gcc gcc-c++ ncurses ncurses-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers pcre pcre-devel  zlip zlip-devel libXpm*

3. php 依赖库安装

libxml2 —— 包含库和实用工具用于解析 XML 文件

wget http://xmlsoft.org/sources/libxml2-2.9.0.tar.gz
tar zxvf libxml2-2.9.0.tar.gz
cd libxml2-2.9.0
./configure
make&&make install

libmcrypt —— 加密算法扩展库 (支持 DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+ 等算法)

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make && make install

默认的 php 安装后 gd 不支持 jpg,只支持 gif、png、bmp。所以首先要安装 gd 库

wget http://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz
tar zxvf libgd-2.1.0.tar.gz
cd libgd-2.1.0
./configure –prefix=/usr/local/webserver/gd2/
make && make install

4. MySQL 配置安装

安装

cd /usr/local
mkdir webserver
cd /usr/local/src
tar zxvf mysql-5.6.14-linux-glibc2.5-i686.tar.gz -C /usr/local/webserver
cd /usr/local/webserver
mv mysql-5.6.14-linux-glibc2.5-i686 mysql

配置

groupadd mysql
useradd -r -g mysql mysql
cd mysql
chown -R mysql .
chgrp -R mysql.
scripts/mysql_install_db –user=mysql
chown -R root .
chown -R mysql data/
cp support-files/my-default.cnf /etc/my.cnf
bin/mysqld_safe –user=mysql &

配置启动 mysql 脚本

vim support-files/mysql.server
# 将
#basedir=
#datadir=
# 改为
#basedir=/usr/local/webserver/mysql
#datadir=/usr/local/webserver/mysql/data
cp support-files/mysql.server /etc/init.d/mysql

启动 / 停止 mysql

# 将 mysql/bin 目录加入系统环境变量中
service mysql start
service mysql stop
service mysql restart

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2013-11/92990p2.htm

 

相关阅读:

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm

CentOS 6.4 下的 LNMP 生产环境搭建及安装脚本 http://www.linuxidc.com/Linux/2013-11/92428.htm

生产环境实用之 LNMP 架构的编译安装 +SSL 加密实现 http://www.linuxidc.com/Linux/2013-05/85099.htm

LNMP 全功能编译安装 for CentOS 6.3 笔记 http://www.linuxidc.com/Linux/2013-05/83788.htm

CentOS 6.3 安装 LNMP (PHP 5.4,MyySQL5.6) http://www.linuxidc.com/Linux/2013-04/82069.htm

在部署 LNMP 的时候遇到 Nginx 启动失败的 2 个问题 http://www.linuxidc.com/Linux/2013-03/81120.htm

Ubuntu 安装 Nginx php5-fpm MySQL(LNMP 环境搭建) http://www.linuxidc.com/Linux/2012-10/72458.htm

5. nginx 安装配置

安装

cd /usr/local/src
tar zxvf nginx-1.5.1.tar.gz
cd nginx-1.5.1
./configure –prefix=/usr/local/webserver/nginx
make && make install

配置启动脚本

每次启动 nginx 都要找到 nginx 的启动目录,这样无疑很麻烦,以下是配置 nginx 在任意目录都可以执行 nginx 的启动、停止、重启的脚本

执行以下命令,书写脚本

vi /etc/init.d/nginx

注:如果从其他系统拷贝到 linux 系统时,需要修改文件格式为 unix. vi 打开后:set ff=unix

#!/bin/sh
#
# nginx – this script starts and stops the nginx daemin
#
# chkconfig:  – 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#              proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/webserver/nginx/conf/nginx.conf
# pidfile:    /usr/local/webserver/nginx/logs/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/webserver/nginx/sbin/nginx”
prog=$(basename $nginx)

NGINX_CONF_FILE=”/usr/local/webserver/nginx/conf/nginx.conf”

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
}

restart() {
    configtest || return $?
    stop
    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

修改 nginx 脚本权限

chmod +x /etc/init.d/nginx 

添加到系统服务

/sbin/chkconfig nginx on

启动 / 停止 nginx

service nginx start
service nginx stop
service nginx restart
service nginx reload

/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
/etc/init.d/nginx reload

6. php 安装配置

安装

tar zxvf php-5.5.6.tar.gz
cd php-5.5.6
./configure –prefix=/usr/local/webserver/php –enable-fpm –with-MySQL=/usr/local/webserver/mysql –with-mysqli=/usr/local/webserver/mysql/bin/mysql_config –with-config-file-path=/usr/local/webserver/php  –with-openssl –enable-mbstring –with-zlib –enable-xml –with-gd=/usr/local/webserver/gd2/ –with-jpeg-dir  –enable-bcmath –with-mcrypt –with-iconv –enable-pcntl –enable-shmop –enable-simplexml –with-xpm-dir=/usr/share/doc/libXpm-3.5.5
make && make install
cp php.ini-development /usr/local/webserver/php/php.ini

配置

php+nginx(/usr/local/webserver/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;
        server_name  192.168.65.144;
        location / {
            root  /data/www;
            index  index.php index.html index.htm;
        }
        error_page  500 502 503 504  /50x.html;
        location = /50x.html {
            root  html;
        }
        location ~ \.php {
            root /data/www;
            include        fastcgi_params;
            set $real_script_name $fastcgi_script_name;
           
            #设置 pathinfo

            set $path_info “”;
            set $real_script_name $fastcgi_script_name;
            if ($fastcgi_script_name ~ “^(.+?\.php)(/.+)$”) {
                set $real_script_name $1;
                set $path_info $2;
            }
            fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;

            fastcgi_param SCRIPT_NAME $real_script_name;
            fastcgi_param PATH_INFO $path_info;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index  index.php;
        }
    }

}

php.ini

date.timezone = prc
enable_dl = On
cgi.force_redirect = 0
cgi.fix_pathinfo=1
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1
allow_url_fopen = On

Linux 单机部署 LNMP 环境

1. 软件来源 

  • mysql-5.6.14 下载地址
  • nginx-1.5.1 下载地址
  • php-5.5.6 下载地址
2. 标准库安装

yum -y install wget make vim install gcc gcc-c++ ncurses ncurses-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers pcre pcre-devel  zlip zlip-devel libXpm*

3. php 依赖库安装

libxml2 —— 包含库和实用工具用于解析 XML 文件

wget http://xmlsoft.org/sources/libxml2-2.9.0.tar.gz
tar zxvf libxml2-2.9.0.tar.gz
cd libxml2-2.9.0
./configure
make&&make install

libmcrypt —— 加密算法扩展库 (支持 DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+ 等算法)

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make && make install

默认的 php 安装后 gd 不支持 jpg,只支持 gif、png、bmp。所以首先要安装 gd 库

wget http://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz
tar zxvf libgd-2.1.0.tar.gz
cd libgd-2.1.0
./configure –prefix=/usr/local/webserver/gd2/
make && make install

4. MySQL 配置安装

安装

cd /usr/local
mkdir webserver
cd /usr/local/src
tar zxvf mysql-5.6.14-linux-glibc2.5-i686.tar.gz -C /usr/local/webserver
cd /usr/local/webserver
mv mysql-5.6.14-linux-glibc2.5-i686 mysql

配置

groupadd mysql
useradd -r -g mysql mysql
cd mysql
chown -R mysql .
chgrp -R mysql.
scripts/mysql_install_db –user=mysql
chown -R root .
chown -R mysql data/
cp support-files/my-default.cnf /etc/my.cnf
bin/mysqld_safe –user=mysql &

配置启动 mysql 脚本

vim support-files/mysql.server
# 将
#basedir=
#datadir=
# 改为
#basedir=/usr/local/webserver/mysql
#datadir=/usr/local/webserver/mysql/data
cp support-files/mysql.server /etc/init.d/mysql

启动 / 停止 mysql

# 将 mysql/bin 目录加入系统环境变量中
service mysql start
service mysql stop
service mysql restart

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2013-11/92990p2.htm

 

相关阅读:

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm

CentOS 6.4 下的 LNMP 生产环境搭建及安装脚本 http://www.linuxidc.com/Linux/2013-11/92428.htm

生产环境实用之 LNMP 架构的编译安装 +SSL 加密实现 http://www.linuxidc.com/Linux/2013-05/85099.htm

LNMP 全功能编译安装 for CentOS 6.3 笔记 http://www.linuxidc.com/Linux/2013-05/83788.htm

CentOS 6.3 安装 LNMP (PHP 5.4,MyySQL5.6) http://www.linuxidc.com/Linux/2013-04/82069.htm

在部署 LNMP 的时候遇到 Nginx 启动失败的 2 个问题 http://www.linuxidc.com/Linux/2013-03/81120.htm

Ubuntu 安装 Nginx php5-fpm MySQL(LNMP 环境搭建) http://www.linuxidc.com/Linux/2012-10/72458.htm

配置 php-fpm 启动脚本

编写脚本(vi /etc/init.d/php-fpm)

#! /bin/sh

### BEGIN INIT INFO
# Provides: php-fpm
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts php-fpm
# Description: starts the PHP FastCGI Process Manager daemon
### END INIT INFO

prefix=/usr/local/webserver/php

php_fpm_BIN=${prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid

php_opts=”–fpm-config $php_fpm_CONF”
php_pid=”–pid $php_fpm_PID”

wait_for_pid () {
try=0

while test $try -lt 35 ; do

case “$1” in
‘created’)
if [-f “$2”] ; then
try=”
break
fi
;;

‘removed’)
if [! -f “$2”] ; then
try=”
break
fi
;;
esac

echo -n .
try=`expr $try + 1`
sleep 1

done

}

case “$1” in
start)
echo -n “Starting php-fpm “

$php_fpm_BIN $php_opts $php_pid

if [“$?” != 0] ; then
echo ” failed”
exit 1
fi

wait_for_pid created $php_fpm_PID

if [-n “$try”] ; then
echo ” failed”
exit 1
else
echo ” done”
fi
;;

stop)
echo -n “Gracefully shutting down php-fpm “

if [! -r $php_fpm_PID] ; then
echo “warning, no pid file found – php-fpm is not running ?”
exit 1
fi

kill -QUIT `cat $php_fpm_PID`

wait_for_pid removed $php_fpm_PID

if [-n “$try”] ; then
echo ” failed. Use force-exit”
exit 1
else
echo ” done”
fi
;;

force-quit)
echo -n “Terminating php-fpm “

if [! -r $php_fpm_PID] ; then
echo “warning, no pid file found – php-fpm is not running ?”
exit 1
fi

kill -TERM `cat $php_fpm_PID`

wait_for_pid removed $php_fpm_PID

if [-n “$try”] ; then
echo ” failed”
exit 1
else
echo ” done”
fi
;;

restart)
$0 stop
$0 start
;;

reload)

echo -n “Reload service php-fpm “

if [! -r $php_fpm_PID] ; then
echo “warning, no pid file found – php-fpm is not running ?”
exit 1
fi

kill -USR2 `cat $php_fpm_PID`

echo ” done”
;;

*)
echo “Usage: $0 {start|stop|force-quit|restart|reload}”
exit 1
;;

esac

赋予脚本执行权限

cd /usr/local/webserver/php/etc
cp php-fpm.conf.default php-fpm.conf
chmod +x /etc/init.d/php-fpm

设置开机启动

/sbin/chkconfig php-fpm on

开启 / 重启 php

service php-fpm start
service php-fpm stop
service php-fpm restart

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计10247字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中