博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CentOS6.8 编译安装LNMP
阅读量:6502 次
发布时间:2019-06-24

本文共 7182 字,大约阅读时间需要 23 分钟。

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

一、查看系统信息

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

二、具体安装

常规依赖包安装

1 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
View Code

安装libiconv库

1 tar zxvf libiconv-1.14.tar.gz2 cd libiconv-1.143 ./configure --prefix=/usr/local/libiconv4 make && make install5 cd ..
View Code

安装libmcrypt,mhash,mcrypt库

1 tar zxvf libmcrypt-2.5.8.tar.gz 2 cd libmcrypt-2.5.8 3 ./configure 4 make && make install 5 cd .. 6 tar jxvf mhash-0.9.9.9.tar.bz2 7 cd mhash-0.9.9.9 8 ./configure 9 make && make install10 cd ..11 tar zxvf mcrypt-2.6.8.tar.gz12 cd mcrypt-2.6.813 ./configure14 make && make install15 cd ..
View Code

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

echo '/usr/local/lib/'>>/etc/ld.so.confldconfig

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

安装CMake工具

1 tar zxvf cmake-3.7.2.tar.gz2 cd cmake-3.7.23 ./bootstrap && make && make install4 cd..
View Code

安装MySQL

1 #卸载旧版本 2 rpm -e mysql --nodeps 3 #创建mysql用户 4 groupadd mysql && useradd -g mysql -M mysql 5 tar zxvf mysql-5.6.24.tar.gz 6 cd mysql-5.6.24 7 cmake \ 8 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ 9 -DMYSQL_DATADIR=/usr/local/mysql/data \10 -DSYSCONFDIR=/etc \11 -DMYSQL_USER=mysql \12 -DWITH_MYISAM_STORAGE_ENGINE=1 \13 -DWITH_INNOBASE_STORAGE_ENGINE=1 \14 -DWITH_ARCHIVE_STORAGE_ENGINE=1 \15 -DWITH_MEMORY_STORAGE_ENGINE=1 \16 -DWITH_READLINE=1 \17 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \18 -DMYSQL_TCP_PORT=3306 \19 -DENABLED_LOCAL_INFILE=1 \20 -DENABLE_DOWNLOADS=1 \21 -DWITH_PARTITION_STORAGE_ENGINE=1 \22 -DEXTRA_CHARSETS=all \23 -DDEFAULT_CHARSET=utf8 \24 -DDEFAULT_COLLATION=utf8_general_ci \25 -DWITH_DEBUG=0 \26 -DMYSQL_MAINTAINER_MODE=0 \27 -DWITH_SSL:STRING=bundled \28 -DWITH_ZLIB:STRING=bundled29 make && make install30 #修改目录权限31 chown -R mysql:mysql /usr/local/mysql32 #拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)33 cp support-files/my-default.cnf /etc/my.cnf34 #编辑配置文件,在 [mysqld] 部分增加下面一行35 vi /etc/my.cnf36 datadir = /usr/local/mysql/data #添加MySQL数据库路径37 #执行初始化配置脚本,创建系统自带的数据库和表38 /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql39 #加入系统服务40 cp support-files/mysql.server /etc/init.d/mysqld41 chmod +x /etc/init.d/mysqld42 #启动mysql43 service mysqld start44 #开机启动45 chkconfig mysqld on46 #加入环境变量47 echo 'PATH=/usr/local/mysql/bin:$PATH'>>/etc/profile48 export PATH49 #让配置生效50 source /etc/profile51 #设置root密码,默认是没有密码的52 /usr/local/mysql/bin/mysqladmin -uroot -p password53 cd ..
View Code

启动 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

1 tar zxvf php-5.6.30.tar.gz 2 cd php-5.6.30 3 ./configure \ 4 --prefix=/usr/local/php \ 5 --with-fpm-user=www --with-fpm-group=www \ 6 --with-config-file-path=/usr/local/php/etc \ 7 --with-mhash --with-mcrypt --enable-bcmath \ 8 --enable-mysqlnd --with-mysql --with-mysqli --with-pdo-mysql \ 9 --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir \10 --enable-fpm \11 --enable-mbstring \12 --enable-pcntl \13 --enable-sockets \14 --enable-opcache \15 --with-openssl \16 --with-zlib \17 --with-curl \18 --with-libxml-dir \19 --with-iconv-dir20 make && make install21 #移动生成php-fpm配置文件22 mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf23 #复制生成一份php配置文件24 cp php.ini-production /usr/local/php/etc/php.ini25 #将php-fpm加入系统服务26 cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm27 #赋予执行权限28 chmod +x /etc/init.d/php-fpm29 #开机启动30 chkconfig php-fpm on#创建www用户31 groupadd www && useradd -d /home/www -g www www32 #启动php-fpm33 service php-fpm start34 cd ..35 vim /etc/profile36 修改PATH=/usr/local/php/bin:/usr/local/mysql/bin:$PATH37 export PATH38 source /etc/profile
View Code

安装Nginx

tar zxvf nginx-1.10.2.tar.gz cd nginx-1.10.2./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-pcremake && make install
View Code

添加Nginx启动管理脚本/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: /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 0nginx="/usr/local/nginx/sbin/nginx"prog=$(basename $nginx)NGINX_CONF_FILE="/etc/nginx/nginx.conf"[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginxlockfile=/var/lock/subsys/nginxmake_dirs() {  # make required directories  user=`$nginx -V 2>&1 | 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 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  fi}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 2esac
View Code

用法指南

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

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

转载于:https://www.cnblogs.com/afee666/p/6836161.html

你可能感兴趣的文章
iphone UIView的一些基本方法理解
查看>>
sys.check_constraints
查看>>
vue问题
查看>>
Linux常用命令大全
查看>>
ThinkPHP 框架学习
查看>>
yii1框架,事务使用方法
查看>>
css3箭头效果
查看>>
Python学习笔记【第一篇】:认识python和基础知识
查看>>
MathType在手,公式不求人!
查看>>
测试用例设计
查看>>
三层架构
查看>>
Python变量类型(l整型,长整形,浮点型,复数,列表,元组,字典)学习
查看>>
解决方案(.sln)文件
查看>>
理解cookie和session机制
查看>>
【Treap】bzoj1588-HNOI2002营业额统计
查看>>
第六周作业
查看>>
利用ZYNQ SOC快速打开算法验证通路(5)——system generator算法IP导入IP integrator
查看>>
指针和引用的区别
查看>>
运行PHP出现No input file specified错误解决办法
查看>>
【重建】从FJOI2016一试谈起
查看>>