zoukankan      html  css  js  c++  java
  • 手动编译安装LNMP

    yum -y install gcc gcc-c++ autoconf nss_ldap libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-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 openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers pcre pcre-devel make wget vim cmake gd gd-devel libevent libevent-devel zip unzip libtool
    yum基本的rpm包
    
     yum install make apr* autoconf automake curl-devel gcc gcc-c++ gtk+-devel zlib-devel openssl openssl-devel pcre-devel gd gettext gettext-devel  keyutils patch perl  compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel  libXpm* freetype freetype-devel freetype* fontconfig fontconfig-devel libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch
    
    安装完成之后
    
    关闭selinux和防火墙
    
    service iptables stop
    
    chkconfig iptables off
    
    vi /etc/selinux/config 
    
    把SELINUX=enforcing 修改为disabled
    
    centos7是iptables被firewalld替代了
    
    systemctl stop firewalld
    
     记得改完之后reboot重启或者直接service iptables restart
    
    源码存放路径:/usr/local/src
    
    yum install lrzsz
    
    cd /usr/local/src
    
    rz
    
    可以多选

    先安装mysql

    groupadd mysql

    useradd -r -g mysql mysql -s /sbin/nologin
     

    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

     
    make
    make install
    cd /usr/local/mysql
    
    cp ./support-files/my-default.cnf /etc/my.cnf 
    scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
    cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
    chmod 755 /etc/init.d/mysqld
    chkconfig --add mysqld
    chkconfig mysqld on
    chkconfig --list mysqld
    
    vi /etc/rc.d/init.d/mysqld
    
    basedir=/usr/local/mysql/
    datadir=/data/mysql/data/
    加上
    echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile  吧mysql的命令加入
    
    source /etc/profile 启动命令
    
    ln -s /usr/local/mysql/lib/mysql /usr/local/lib64/mysql
    ln -s /usr/local/mysql/include/mysql /usr/local/include/mysql
    
    
    service mysqld start
    
    mysql -uroot  登陆 默认密码为空
    mysql> SET PASSWORD = PASSWORD('123456'); 设置root密码
    mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.16.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
    开始远程访问
    

     完成mysql的安装,接下来安装nginx

    groupadd nginx
    useradd -r -g nginx nginx -s /sbin/nologin
     
    tar -zxvf nginx-1.6.2
    cd nginx-1.6.2
    ./configure 
    --prefix=/usr/local/nginx 
    --sbin-path=/usr/sbin/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/nginx.pid 
    --lock-path=/var/lock/nginx.lock 
    --user=nginx 
    --group=nginx 
    --with-http_ssl_module 
    --with-http_flv_module 
    --with-http_stub_status_module 
    --with-http_gzip_static_module 
    --http-client-body-temp-path=/var/tmp/nginx/client/ 
    --http-proxy-temp-path=/var/tmp/nginx/proxy/ 
    --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
    
     
    
    make && make install
    
    vi /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/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 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


    
    
    chmod +x /etc/init.d/nginxd
    
     
    
    chkconfig --add nginxd        ##让入开机启动选项中
    
     
    
    chkconfig nginxd on          #让其开机自动启动
    
    chkconfig --list       #查看服务是不是加入
    
    service nginxd  start       #立即启动nginx 服务
     

    接下来是php安装 ,会稍微麻烦点,如果有写开发包没有安装成功可以在做so模块在安装成功之后,再次编译进去



    先解决几个编译php的编译选项的依赖库
    libmcrypt
    mhash
    mcrypt
    libiconv
    上面的源码包都有

    
    


    cd /usr/local/src
    tar zxvf libmcrypt-2.5.8.tar.gz
    cd libmcrypt-2.5.8
    ./configure
    make && make install
    /sbin/ldconfig
    cd libltdl

    
    

    ./configure --enable-ltdl-install
    make && make install
    cd ../../
    tar zxvf mhash-0.9.9.9.tar.gz
    cd mhash-0.9.9.9/
    ./configure
    make && make install
    ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
    ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
    ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
    ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
    ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
    ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
    ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
    ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
    ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
    ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
    cd ../
    tar zxvf mcrypt-2.6.8.tar.gz
    cd mcrypt-2.6.8/
    /sbin/ldconfig
    ./configure
    make && make install
    cd ../
    tar zxvf pcre-8.31.tar.gz
    cd pcre-8.31
    ./configure –-prefix=/usr/local/pcre
    make
    make install
    cd ../
    tar zxvf libiconv-1.13.1.tar.gz
    cd libiconv-1.13.1/
    ./configure –-prefix=/usr/local/libiconv

    
    

    这个地方做好指定,因为编译php的时候会搜索不到这个包

    
    


    make && make install
    cd ../
    tar zxvf ImageMagick.tar.gz
    cd ImageMagick-6.5.1-2/
    ./configure
    make && make install
    cd ../

    解压php

    cd php



    ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl --enable-fpm --enable-soap --with-iconv=/usr/local/libiconv  --with-mysqli=/usr/local/mysql/bin/mysql_config  --with-freetype-dir=/usr/local/freetype  --with-gd --with-mysql --with-mysqli

    --enable-maintainer-zts,注意这个选项会导致一个问题 
    
    

    Linux上的PHP同样有NTS和TS版本的区别,默认是NTS版本,configure时加上--enable-maintainer-zts则编译为TS版本.什么时候需要TS版本呢?比如你要使用pthreads这个多线程的PECL扩展时,或者PHP以MOD_PHP嵌入多线程运行下的Apache,比如Apache在Linux上提供的Event MPM就是一个多进程多线程的工作模型,Windows上Apache采用的WinNT MPM也是一个多线程模型,这时都需要TS版本的PHP.

    
    

    而如果以PHP-FPM(比如搭配Nginx或者Apache的mod_fastcgi)或者PHP-CGI(比如搭配Apache的mod_fcgid或者Win上的IIS)来运行PHP,则一般都不需要TS线程安全版本的PHP.



    如果出错

    configure: error: Please reinstall the BZip2 distribution

    yum install bzip2
    yum install bzip2-devel

    在次./configure

    看到欢迎页面
    make && make install


    接下来是配置php-fpm
    和让nginx 接收处理php

    cp php.ini-production /usr/local/php/etc/php.ini
    cp php.ini-production /etc/php.ini
    这个是默认php.ini的路径 cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

    user =nginx
    #设置php-fpm运行账号为nginx

    group =nginx
    #设置php-fpm运行组为nginx

    pid = run/php-fpm.pid #取消前面的分号
    设置 php-fpm开机启动
    cp /usr/local/src/php-5.3.10/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷贝php-fpm到启动目录
    chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限
    chkconfig --add php-fpm

    chkconfig php-fpm on #设置开机启动
     
    vi /etc/nginx/nginx.conf


    改为user  nginx;
    
     
    
    之后找到
    去掉#
     
    
            location ~ .php$ {
                root           /www;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
                include        fastcgi_params;
            }
    
     
    
     server nginxd start

    就可以了







  • 相关阅读:
    第4月第1天 makefile automake
    第3月30天 UIImage imageWithContentsOfFile卡顿 Can't add self as subview MPMoviePlayerControlle rcrash
    第3月第27天 uitableviewcell复用
    learning uboot fstype command
    learning uboot part command
    linux command dialog
    linux command curl and sha256sum implement download verification package
    learning shell script prompt to run with superuser privileges (4)
    learning shell get script absolute path (3)
    learning shell args handing key=value example (2)
  • 原文地址:https://www.cnblogs.com/zx-admin/p/5438986.html
Copyright © 2011-2022 走看看