思路:根据Linux系统以及公司网站系统的信息,选择合适的安装包进行安装

一、查看系统信息

# uname -a                        # 查看内核/操作系统/CPU信息
# head -n /etc/issue # 查看操作系统版本
# grep MemTotal /proc/meminfo # 查看内存总量
#fdisk -l # 查看所有分区

二、具体安装

常规依赖包安装

 yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openldap openldap-devel openldap-clients openldap-servers make zlib-devel pcre-devel openssl-devel libtool* git tree bison perl gd gd-devel

安装libiconv库

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

安装libmcrypt,mhash,mcrypt库

 tar zxvf libmcrypt-2.5..tar.gz
cd libmcrypt-2.5.
./configure
make && make install
cd ..
tar jxvf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9
./configure
make && make install
cd ..
tar zxvf mcrypt-2.6..tar.gz
cd mcrypt-2.6.
./configure
make && make install
cd ..

编译 mcrypt 如果报错:configure: error: * libmcrypt was not found,则

echo '/usr/local/lib/'>>/etc/ld.so.conf
ldconfig

编译 mcrypt 如果报错:/bin/rm: cannot remove 'libtoolT': No such file or directory,则修改 configure 文件,找到 RM='$RM' 并改为 RM='$RM -rf'。

安装CMake工具

 tar zxvf cmake-3.7..tar.gz
cd cmake-3.7.
./bootstrap && make && make install
cd..

安装MySQL

 #卸载旧版本
rpm -e mysql --nodeps
#创建mysql用户
groupadd mysql && useradd -g mysql -M mysql
tar zxvf mysql-5.6..tar.gz
cd mysql-5.6.
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE= \
-DWITH_INNOBASE_STORAGE_ENGINE= \
-DWITH_ARCHIVE_STORAGE_ENGINE= \
-DWITH_MEMORY_STORAGE_ENGINE= \
-DWITH_READLINE= \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT= \
-DENABLED_LOCAL_INFILE= \
-DENABLE_DOWNLOADS= \
-DWITH_PARTITION_STORAGE_ENGINE= \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG= \
-DMYSQL_MAINTAINER_MODE= \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled
make && make install
#修改目录权限
chown -R mysql:mysql /usr/local/mysql
#拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)
cp support-files/my-default.cnf /etc/my.cnf
#编辑配置文件,在 [mysqld] 部分增加下面一行
vi /etc/my.cnf
datadir = /usr/local/mysql/data #添加MySQL数据库路径
#执行初始化配置脚本,创建系统自带的数据库和表
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
#加入系统服务
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
#启动mysql
service mysqld start
#开机启动
chkconfig mysqld on
#加入环境变量
echo 'PATH=/usr/local/mysql/bin:$PATH'>>/etc/profile
export PATH
#让配置生效
source /etc/profile
#设置root密码,默认是没有密码的
/usr/local/mysql/bin/mysqladmin -uroot -p password
cd ..

启动 mysql 时如果报错:mysqld_safe Directory '/var/lib/mysqld' for UNIX socket file don't exists,则

mkdir -p /var/lib/mysqld
chown mysql:mysql /var/lib/mysqld

安装PHP

 tar zxvf php-5.6..tar.gz
cd php-5.6.
./configure \
--prefix=/usr/local/php \
--with-fpm-user=www --with-fpm-group=www \
--with-config-file-path=/usr/local/php/etc \
--with-mhash --with-mcrypt --enable-bcmath \
--enable-mysqlnd --with-mysql --with-mysqli --with-pdo-mysql \
--with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir \
--enable-fpm \
--enable-mbstring \
--enable-pcntl \
--enable-sockets \
--enable-opcache \
--with-openssl \
--with-zlib \
--with-curl \
--with-libxml-dir \
--with-iconv-dir
make && make install
#移动生成php-fpm配置文件
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
#复制生成一份php配置文件
cp php.ini-production /usr/local/php/etc/php.ini
#将php-fpm加入系统服务
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#赋予执行权限
chmod +x /etc/init.d/php-fpm
#开机启动
chkconfig php-fpm on#创建www用户
groupadd www && useradd -d /home/www -g www www
#启动php-fpm
service php-fpm start
cd ..
vim /etc/profile
修改PATH=/usr/local/php/bin:/usr/local/mysql/bin:$PATH
export PATH
source /etc/profile

安装Nginx

tar zxvf nginx-1.10..tar.gz
cd nginx-1.10.
./configure \
--user=www \
--group=www \
--prefix=/usr/local/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.pid \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_ssl_module \
--with-pcre
make && make install

添加Nginx启动管理脚本/etc/init.d/nginx

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - # 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 nginx="/usr/local/nginx/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 >& | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -n "$user" ]; then
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V >& | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f `
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
fi
} start() {
[ -x $nginx ] || exit
[ -f $NGINX_CONF_FILE ] || exit
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq ] && touch $lockfile
return $retval
} stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq ] && rm -f $lockfile
return $retval
} restart() {
configtest || return $?
stop
sleep
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 >&
} case "$1" in
start)
rh_status_q && exit
$
;;
stop)
rh_status_q || exit
$
;;
restart|configtest)
$
;;
reload)
rh_status_q || exit
$
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit
esac

用法指南

chmod +x /etc/init.d/nginx
service nginx start #启动nginx服务
chkconfig nginx on #开机启动
cd ..

至此,LNMP环境已搭建完毕。

最新文章

  1. 初学 Java Web 开发,请远离各种框架,从 Servlet 开发
  2. 收集入侵Windows系统的证据
  3. python 格式化字符串的三种方法
  4. PHP OO 编程笔记
  5. Core Text概述
  6. Uiviewcontroller 控制器的生命周期
  7. VR全景智慧城市—城市就在你眼前
  8. JAVA中的按值传递
  9. 19.QT-事件发送函数sendEvent()、postEvent()
  10. Scrapy 1.4 文档 01 初窥 Scrapy
  11. Navicat permium工具连接Oracle的配置
  12. Java重写toString和泛型的使用
  13. 未能加载文件或程序集“System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它的某一个依赖项
  14. C# winform右击导入手机号码
  15. 安装MySQL后经常弹出taskeng.exe~
  16. Redis 的 GEO 特性将在 Redis 3.2 版本释出
  17. BZOJ5418:[NOI2018]屠龙勇士(exCRT,exgcd,set)
  18. mac 下 python链接mysql
  19. docker创建nginx镜像
  20. LCD驱动程序

热门文章

  1. Python编程学习笔记 随时更新
  2. JDK7集合框架源码阅读(七) ArrayDeque
  3. CSS,HTML页面定制
  4. ES6 Promise的resolved深入理解
  5. [xsy2579]counting
  6. 集合框架(01)Collection
  7. [转]WCF RESTful service and WebGrid in ASP.NET MVC 5
  8. VUE -- ejs模板的书写
  9. [置顶] kubernetes资源对象--limitranges
  10. centos7 安装LNMP(php7)之mysql安装,更改密码,远程授权