lnmp编译安装和虚拟主机配置

一.系统环境:Centos6.8

二.需要软件包:在下面进行查看

三.环境准备:

#将yum源更换为阿里yum源
        cd /etc/yum.repos.d
mkdir bak
mv CentOS-* bak    (将系统自带的yum源放入bak目录备份)
wget	 http://mirrors.aliyun.com/repo/Centos-6.repo (下载阿里yum源)
yum makecache	(生成yum缓存)
yum -y install make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf 	kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd 	gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 	glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl 	openssl-devel gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip 	libcap lsof  

setenforce 0 (关闭selinux机制)
service iptables stop (关闭防火墙,注:本次为测试机,公司服务器因配置防 火墙,开放相应端口)
rpm -e httpd
rpm -e mysql
rpm -e php
yum -y remove httpd
yum -y remove mysql
yum -y remove php (清理系统自带已安装软件包)
rpm -qa |grep http
rpm -e --nodeps 上条命令搜索出的软件包(搜索已安装的apache的包并强制 卸载,避免冲突)

四.安装Mysql

cd /usr/src/		(进去一个软件存放目录)
groupadd mysql	 (创建mysql用户组)
useradd -s /sbin/nologin -g mysql -M mysql  (创建一个mysql用户,不允许登											陆和不创建主目录)
rpm -qa|grep mysql
rpm -e mysql-libs-5.1.73-7.el6.x86_64 --nodeps (检查系统自带mysql的库,并											 卸载)

#MySQL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具。 因此,我们首先要在系统中源码编译安装cmake工具。
wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
tar zxvf cmake-2.8.12.2.tar.gz -C /usr/src/ (解压并指定目录)
cd cmake-2.8.12.2
./configure
make && make install (编译安装cmake)

#安装mysql
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz
tar zvxf mysql-5.6.17.tar.gz -C /usr/src/ (解压到指定目录)
cd mysql-5.6.17
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0 \
-DWITH_SSL=system
make &&make install  (编译安装mysql)
#在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索”$basedir/my.cnf” 就是安装目录下 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置!
cd support-files/
cp my-default.cnf /etc/my.cnf (创建mysql主配置文件)
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data  --user=mysql (初始化																mysql)
cp mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld (创建mysql启动脚本)
chkconfig mysqld on (设置开机启动mysql)

vim /etc/profile
在末尾处添加:
PATH=/usr/local/mysql/bin:$PATH
export PATH (添加环境变量)
source /etc/profile (使配置文件生效)
###至此,Mysql就已经安装完成

五.安装PHP5.5.12

5.1 安装PHP所需要的依赖关系

1.libiconv库为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换。 错误提示:configure: error: Please reinstall the iconv library.
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zvxf libiconv-1.14.tar.gz -C /usr/src/ (解压到指定目录)
cd libiconv-1.14
./configure
Make && make install (编译安装libconv)
2.	libmcrypt是加密算法扩展库。 错误提示:configure: error: Cannot find imap library (libc-client.a). Please check your c-client installation.
wget http://iweb.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar zvxf libmcrypt-2.5.8.tar.gz -C /usr/src/ (解压到指定目录)
cd libmcrypt-2.5.8
./configure
Make && make install (编译安装ibmcrypt)
3.	Mhash是基于离散数学原理的不可逆向的php加密方式扩展库,其在默认情况下不开启。 mhash的可以用于创建校验数值,消息摘要,消息认证码,以及无需原文的关键信息保存 错误提示:configure: error: “You need at least libmhash 0.8.15 to compile this program. http://mhash.sf.net/”
wget http://soft.7dot.com/soft/mhash-0.9.9.9.tar.gz
tar zvxf mhash-0.9.9.9.tar.gz -C /usr/src/
cd mhash-0.9.9.9
./configure
make && make install (编译安装Mhash)
4.	mcrypt 是 php 里面重要的加密支持扩展库,Mcrypt扩展库可以实现加密解密功能,就是既能将明文加密,也可以密文还原。
wget http://iweb.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
tar zvxf mcrypt-2.6.8.tar.gz -C /usr/src/ (解压到指定目录)
cd mcrypt-2.6.8
./configure
Make && make install (编译安装mcrypt)
注:编译mcrypt可能会报错:configure: error: *** libmcrypt was not found
解决方法:vim /etc/ld.so.conf
最后一行添加 /usr/local/lib/
Ldconfig

5.2 正式安装PHP

wget http://mirrors.sohu.com/php/php-5.5.12.tar.gz
tar zvxf php-5.5.12.tar.gz -C /usr/src/ (解压到指定目录)
cd php-5.5.12
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
make && make install (编译安装PHP)
注:安装PHP时可能会出现“make: *** [sapi/cli/php] 错误 1”错误
解决方法:vim Makefile
在EXTRA_LIBS=这一行添加-liconv,再次make即可
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf (创建php-fpm配置文件)
cp php.ini-production /usr/local/php/etc/php.ini (创建php.ini文件)
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm (创建php.fpm启动脚本)
chkconfig --add php-fpm (设置为启动项)
chkconfig php-fpm on (设置开机自启动)
groupadd www
useradd -s /sbin/nologin -g www -M www (为php-fpm创建服务用户及组)

#至此PHP就已经安装完成

六.安装Nginx

nginx所需的依赖关系,一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。如果系统已经yum 安装了这些库也没关系,无需卸载。直接编译安装最新的就可以了。为了一次性完成编译,先准备编译下面的依赖关系!

#安装pcre库
wget http://exim.mirror.fr/pcre/pcre-8.35.tar.gz
tar -zxvf pcre-8.35.tar.gz -C /usr/src/ (解压到指定目录)
cd pcre-8.35
./configure
Make && make install (编译安装pcre库)
#安装zlib库
wget http://down1.chinaunix.net/distfiles/zlib-1.2.3.tar.gz
tar zvxf zlib-1.2.3.tar.gz -C /usr/src/ (解压到指定目录)
cd zlib-1.2.3
./configure
Make && make install (编译安装zlib)
#安装openssl(自由选择是否编译)
wget http://distfiles.macports.org/openssl/openssl-1.0.1g.tar.gz
tar zvxf openssl-1.0.1g.tar.gz -C /usr/src/
./config --prefix=/usr/local/openssl
Make && make install (编译安装openssl)
#ngx_pagespeed库 ngx_pagespeed 是一个 Nginx 的扩展模块,可以加速你的网站,减少页面加载时间,它会自动将一些提升web性能的实践应用到网页和相关的资源(CSS、JS和图片)上,无需你修改内容和流程。
wget https://github.com/pagespeed/ngx_pagespeed/archive/v1.8.31.2-beta.zip
unzip v1.8.31.2-beta.zip
cd ngx_pagespeed-1.8.31.2-beta/
wget https://dl.google.com/dl/page-speed/psol/1.8.31.2.tar.gz
tar -xzvf 1.8.31.2.tar.gz
#使用google-perftools提供的TCMalloc工具优化nginx和mysql,TCMalloc (google-perftools) 是用于优化C++写的多线程应用,比glibc 2.3的malloc快。这个模块可以用来让MySQL在高并发下内存占用更加稳定.TCMalloc是google-perftools的其中一个工具,用于优化内存分配的效率和速度,帮助在高并发的情况下很好的控制内存的使用
#安装google-perftools必须先安装libunwind,否则会报错
wget http://nongnu.askapache.com/libunwind/libunwind-1.1.tar.gz
tar zxvf libunwind-1.1.tar.gz -C /usr/src/ (解压到指定目录)
cd libunwind-1.1
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install (编译安装libunwind)
#安装google-perftools
wget http://www.cs.cmu.edu/~jinlianw/third_party/gperftools-2.1.tar.gz
tar zvxf gperftools-2.1.tar.gz -C /usr/src/
cd gperftools-2.1
./configure --prefix=/usr/local
Make && make install (编译安装google-perftools)

6.2 正式安装Nginx

wget http://nginx.org/download/nginx-1.7.0.tar.gz
tar zvxf nginx-1.7.0.tar.gz -C /usr/src/
cd nginx-1.7.0
./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-pcre=/usr/src/pcre-8.35 \
--with-zlib=/usr/src/zlib-1.2.3 \
--with-openssl=/usr/src/openssl-1.0.1g \
--add-module=/usr/src/ngx_pagespeed-1.8.31.2-beta \
--with-google_perftools_module
make && make install (编译安装nginx)

#创建nginx启动脚本
cat /etc/init.d/nginxd

#!/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 0

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

sysconfig="/etc/sysconfig/$prog"
lockfile="/var/lock/subsys/nginx"
pidfile="/usr/local/nginx/logs/nginx.pid"

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

[ -f $sysconfig ] && . $sysconfig


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 -p $pidfile $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest_q || return 6
    stop
    start
}

reload() {
    configtest_q || return 6
    echo -n $"Reloading $prog: "
    killproc -p $pidfile $prog -HUP
    echo
}

configtest() {
    $nginx -t -c $NGINX_CONF_FILE
}

configtest_q() {
    $nginx -t -q -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

# Upgrade the binary with no downtime.
upgrade() {
    local oldbin_pidfile="${pidfile}.oldbin"

    configtest_q || return 6
    echo -n $"Upgrading $prog: "
    killproc -p $pidfile $prog -USR2
    retval=$?
    sleep 1
    if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]];  then
        killproc -p $oldbin_pidfile $prog -QUIT
        success $"$prog online upgrade"
        echo 
        return 0
    else
        failure $"$prog online upgrade"
        echo
        return 1
    fi
}

# Tell nginx to reopen logs
reopen_logs() {
    configtest_q || return 6
    echo -n $"Reopening $prog logs: "
    killproc -p $pidfile $prog -USR1
    retval=$?
    echo
    return $retval
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest|reopen_logs)
        $1
        ;;
    force-reload|upgrade) 
        rh_status_q || exit 7
        upgrade
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    status|status_q)
        rh_$1
        ;;
    condrestart|try-restart)
        rh_status_q || exit 7
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}"
        exit 2
esac

chmod +x /etc/init.d/nginxd
service nginxd start (启动nginx)
mkdir -p /www/wwwroot (创建网站根目录)
mkdir -p /www/wwwlogs (创建网站日志目录)

nginx开启google_perftools 调优支持

mkdir /tmp/tcmalloc
chmod 0777 /tmp/tcmalloc/
vim /usr/local/nginx/logs/nginx.pid
添加上google_perftools_profiles /tmp/tcmalloc;
service nginxd restart (重启nginx服务,只能restart,不能reload)

#到此nginx安装完毕

七.使用xcache优化php性能

wget http://xcache.lighttpd.net/pub/Releases/3.1.0/xcache-3.1.0.tar.gz
tar zxvf xcache-3.1.0.tar.gz -C /usr/src/ (解压到指定目录)
cd xcache-3.1.0
/usr/local/php/bin/phpize
./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
make && make install

cp htdocs/ /www/wwwroot/xcache -rf (将文件放到网站根目录下)

Vim /usr/local/php/etc/php.ini 
添加:
[xcache-common]
;注意路径
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20121212/xcache.so

[xcache.admin]
xcache.admin.enable_auth = on
xcache.admin.user = "admin"
xcache.admin.pass = "e10adc3949ba59abbe56e057f20f883e"
;运行: echo -n "password" |md5sum |awk '{print $1}' 计算出MD5加密过的密码
;替换xcache.admin.pass=的值

[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 64M
xcache.count = 1
xcache.slots = 8K
xcache.ttl = 3600
xcache.gc_interval = 60
xcache.var_size = 16M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 3600
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.readonly_protection = Off
xcache.mmap_path = "/dev/zero"
xcache.coredump_directory = "/tmp/phpcore"
xcache.coredump_type = 0
xcache.disable_on_crash = Off
xcache.experimental = Off
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off

[xcache.coverager]
xcache.coverager = Off
xcache.coverager_autostart =  On
xcache.coveragedump_directory = "/tmp/pcov"

至此,lnmp安装完毕

八 安装wordpress

8.1 在nginx 下配置虚拟主机

下面是虚拟主机配置内容
server
{
    listen 80;
#OPEN-PORT-443
    #listen 443 ssl http2;
    server_name www.a.com;
#DEFAULT-INDEX-START
	index  index.html index.htm index.php;
#DEFAULT-INDEX-END
    root /www/teset_cn;
    
    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    error_page 404 /404.html;
    error_page 502 /502.html;
    #ERROR-PAGE-END
    
   #PHP-START     
           #location ~ [^/]\.php(/|$)
             location ~ \.php(/|$)
           {
           try_files $uri =404;
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          include fastcgi_params;  
            include pathinfo.conf;
	
             }
  #PHP-END
 
   
    #IMAGE-CONTROL-START    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    #    error_log off;
    #    access_log off;
    }
    
    location ~ .*\.(js|css)?$
    {
        expires      12h;
    #    error_log off;
    #    access_log off; 
    }
#IMAGE-CONTROL-END
    access_log  /www/www.test.cn.log;
    error_log  /www/www.test.cn.error.log;
}

安装wordpress程序,将程序包上传到对应的网站目录下

查看下面的这篇文章

wordpress安装

链接地址点击

发布了77 篇原创文章 · 获赞 0 · 访问量 3232

猜你喜欢

转载自blog.csdn.net/liaowunonghen/article/details/105074323