代码改变世界
[登录 · 注册]
  • Deepin 15.4 编译安装 LNMP(PHP 5.6.31 + Nginx 1.12.1 + MySQL 5.6.36)
  • 先查看先前的文章:Ubuntu 14 编译安装 PHP 5.4.45 + Nginx 1.4.7 + MySQL 5.6.26 笔记

    编译 Nginx

    #安装依赖库
    sudo apt-get -y install libpcre3 libpcre3-dev
    sudo apt-get -y install libssl-dev openssl libcurl4-openssl-dev
    sudo apt-get -y install build-essential libtool
     
    #安装pcre库
    cd /alidata/tmp/deepin-sdk/source2/nginx
    sudo tar -xzvf ./pcre-8.36.tar.gz
    cd ./pcre-8.36
    sudo ./configure
    sudo make && sudo make install
     
    #安装zlib库
    cd /alidata/tmp/deepin-sdk/source2/nginx
    sudo tar -xzvf ./zlib-1.2.8.tar.gz
    cd ./zlib-1.2.8
    sudo ./configure
    sudo make && sudo make install
     
    #安装ssl
    cd /alidata/tmp/deepin-sdk/source2/nginx
    sudo tar -xzvf ./openssl-1.0.1e.tar.gz
    cd openssl-1.0.1e
     
    #添加nginx用户组及用户
    #sudo groupadd www
    #sudo useradd -g www -s /usr/sbin/nologin www #不让www用户直接登录
     
    #安装nginx
    cd /alidata/tmp/deepin-sdk/source2/nginx
    sudo tar -xzvf ./nginx-1.12.1.tar.gz
    cd ./nginx-1.12.1
    sudo mkdir /alidata/server/nginx/nginx-1.12
     
    sudo ./configure 
    --prefix=/alidata/server/nginx/nginx-1.12 
    --user=wenjianbao 
    --group=wenjianbao 
    --sbin-path=/alidata/server/nginx/nginx-1.12/nginx 
    --conf-path=/alidata/server/nginx/nginx-1.12/conf/nginx.conf 
    --pid-path=/alidata/server/nginx/nginx-1.12/logs/nginx.pid 
    --with-http_stub_status_module 
    --with-http_ssl_module 
    --with-http_realip_module 
    --with-pcre=/alidata/tmp/deepin-sdk/source2/nginx/pcre-8.36 
    --with-zlib=/alidata/tmp/deepin-sdk/source2/nginx/zlib-1.2.8 
    --with-openssl=/alidata/tmp/deepin-sdk/source2/nginx/openssl-1.0.1e
     
    sudo make && sudo make install
     
    #复制配置文件
    sudo cp -rf /alidata/tmp/deepin-sdk/config/nginx-1.12/nginx.conf  /alidata/server/nginx/nginx-1.12/conf/nginx.conf
      
    #创建虚拟主机配置文件目录
    sudo mkdir /alidata/server/nginx/nginx-1.12/conf/vhost
      
    #设置权限
    sudo chmod -R +x /alidata/server/nginx/nginx-1.12
    sudo chown -R wenjianbao:wenjianbao /alidata/server/nginx/nginx-1.12
      
    #设置开机自动启动
    sudo cp -rf /alidata/tmp/deepin-sdk/config/nginx-1.12/nginx.init /etc/init.d/nginx
    sudo chmod +x /etc/init.d/nginx #添加执行权限
    sudo update-rc.d nginx defaults
    
    #sudo service nginx start #启动nginx
    sudo /etc/init.d/nginx start
    

    文件 /etc/init.d/nginx 的内容:

    #!/bin/bash  
    # nginx Startup script for the Nginx HTTP Server  
    # it is v.0.0.2 version.  
    # chkconfig: - 85 15  
    # description: Nginx is a high-performance web and proxy server.  
    #              It has a lot of features, but it's not for everyone.  
    # processname: nginx  
    # pidfile: /var/run/nginx.pid  
    # config: /usr/local/nginx/conf/nginx.conf  
      
    #注意:这里的三个变量需要根据具体的环境而做修改。  
    nginxd=/alidata/server/nginx/nginx-1.12/nginx
    nginx_config=/alidata/server/nginx/nginx-1.12/conf/nginx.conf  
    nginx_pid=/alidata/server/nginx/nginx-1.12/logs/nginx.pid  
    
    RETVAL=0  
    prog="nginx"  
      
    # Check that networking is up.  
    [ -x $nginxd ] || exit 0  
    # Start nginx daemons functions.  
    start() {  
    if [ -e $nginx_pid ];then  
       echo "nginx already running...."  
       exit 1  
    fi  
       echo -n $"Starting $prog: "  
       $nginxd -c ${nginx_config}  
       RETVAL=$?  
       echo  
       [ $RETVAL = 0 ]    
       return $RETVAL  
    }  
    # Stop nginx daemons functions.  
    stop() {  
      echo -n $"Stopping $prog: "  
      $nginxd -s stop  
      RETVAL=$?  
      echo  
      [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx $nginx_pid  
    }  
    # reload nginx service functions.  
    reload() {  
      echo -n $"Reloading $prog: "  
      kill -HUP `cat ${nginx_pid}`  
      RETVAL=$?  
      echo  
    }  
    # See how we were called.  
    case "$1" in  
      start)  
              start  
              ;;  
      stop)  
              stop  
              ;;  
      reload)  
              reload  
              ;;  
      restart)  
              stop  
              start  
              ;;  
      status)  
              status $prog  
              RETVAL=$?  
              ;;  
      *)  
              echo $"Usage: $prog {start|stop|restart|reload|status|help}"  
              exit 1  
    esac  
    exit $RETVAL
    

    编译 PHP

    #!/bin/bash
    
    ##################################################
    ### 1、安装 依赖库
    ##################################################
    # 安装 C/C++编译器
    sudo apt-get -y install gcc build-essential make
    
    # 安装依赖库
    sudo apt-get -y install libxml2-dev libjpeg-dev libpng-dev libfreetype6-dev libcurl4-gnutls-dev pkg-config libfreetype6-dev 
    
    #安装 libmcryp
    cd /alidata/tmp/deepin-sdk/source2/php/
    sudo tar -xzvf ./libmcrypt-2.5.8.tar.gz
    cd ./libmcrypt-2.5.8
    sudo ./configure --prefix=/usr
    sudo make && sudo make install
      
    #安装 mhash
    cd /alidata/tmp/deepin-sdk/source2/php/
    sudo tar -xzvf ./mhash-0.9.9.9.tar.gz
    cd ./mhash-0.9.9.9
    sudo ./configure --prefix=/usr
    sudo make && sudo make install
      
    #安装 mcrypt
    sudo /sbin/ldconfig  #搜索出可共享的动态链接库
    cd /alidata/tmp/deepin-sdk/source2/php/
    sudo tar -xzvf ./mcrypt-2.6.8.tar.gz
    cd ./mcrypt-2.6.8
    sudo ./configure
    sudo make && sudo make install
      
    #安装 libiconv
    #报错:http://www.cnblogs.com/52php/p/7619696.html
    
    cd /alidata/tmp/deepin-sdk/source2/php/
    sudo tar -xzvf ./libiconv-1.14.tar.gz
    cd ./libiconv-1.14
    sudo ./configure --prefix=/usr
    sudo make && sudo make install 
    
    #安装bzip2
    cd /alidata/tmp/deepin-sdk/source2/php/
    sudo tar -xzvf ./bzip2-1.0.6.tar.gz
    cd ./bzip2-1.0.6
    sudo make && sudo make install
    
    
    ##################################################
    ### 2、安装 PHP php-5.6.31
    ##################################################
    cd /alidata/tmp/deepin-sdk/source2/php/
    sudo tar -xzvf ./php-5.6.31.tar.gz
    cd ./php-5.6.31
      
    #生成配置
    sudo ./configure 
    --prefix=/alidata/server/php/php-5.6 
    --with-config-file-path=/alidata/server/php/php-5.6/etc 
    --with-openssl 
    --with-zlib 
    --with-bz2 
    --with-gd 
    --with-jpeg-dir 
    --with-png-dir 
    --with-gettext 
    --with-mhash 
    --with-freetype-dir 
    --with-mcrypt 
    --with-iconv 
    --with-curl 
    --with-xmlrpc 
    --with-pdo-mysql 
    --with-mysqli 
    --enable-zip 
    --enable-mbstring 
    --enable-mbregex 
    --enable-bcmath 
    --enable-soap 
    --enable-sockets 
    --enable-ftp 
    --enable-gd-native-ttf 
    --enable-shmop 
    --enable-sysvmsg 
    --enable-sysvsem 
    --enable-sysvshm 
    --enable-pcntl 
    --enable-fpm 
    --with-fpm-user=wenjianbao 
    --with-fpm-group=wenjianbao 
    --without-pear
    
      
    #编译安装
    sudo make && make install
      
    ##################################################
    ### 3、配置 php.ini
    ##################################################
    #cp ./php.ini-production /alidata/server/php/php-5.6/etc/php.ini
    sudo mv /etc/php.ini /etc/php.ini.old
    sudo cp -rf /alidata/tmp/deepin-sdk/config/php-5.6/php.ini  /alidata/server/php/php-5.6/etc/
    sudo ln -s /alidata/server/php/php-5.6/etc/php.ini /etc/php.ini
      
    ##################################################
    ### 4、配置 php 命令行
    ##################################################
    sudo rm /usr/local/bin/php
    sudo rm /usr/local/bin/phpize
    sudo rm /usr/local/bin/php-config
    
    sudo ln -s /alidata/server/php/php-5.6/bin/php /usr/local/bin/php
    sudo ln -s /alidata/server/php/php-5.6/bin/phpize /usr/local/bin/phpize
    sudo ln -s /alidata/server/php/php-5.6/bin/php-config /usr/local/bin/php-config
    
    ##################################################
    ### 5、配置 php-fpm
    ##################################################
    #拷贝模板文件为php-fpm配置文件
    #sudo cp /alidata/server/php/php-5.6/etc/php-fpm.conf.default /alidata/server/php/php-5.6/etc/php-fpm.conf 
    sudo cp -rf /alidata/tmp/deepin-sdk/config/php-5.6/php-fpm.conf /alidata/server/php/php-5.6/etc/
    
      
    #设置 php-fpm 开机启动,拷贝php-fpm到启动目录
    #sudo cp -rf /alidata/tmp/deepin-sdk/config/php-5.6/php-fpm.init  /etc/init.d/php-fpm 
    sudo cp -rf /alidata/tmp/deepin-sdk/source2/php/php-5.6.31/sapi/fpm/init.d.php-fpm  /etc/init.d/php-fpm
    sudo chmod +x /etc/init.d/php-fpm #添加执行权限
    sudo update-rc.d php-fpm defaults #设置开机启动
      
    #sudo service php-fpm start  #启动php-fpm
    #sudo service nginx restart  #重启nginx
    sudo killall php-fpm  # 关闭 php-fpm
    sudo /etc/init.d/php-fpm start
    sudo /etc/init.d/nginx restart 
     
      
    sudo cp -rf /alidata/tmp/deepin-sdk/source2/index.php  /alidata/server/nginx/nginx-1.12/html/
    sudo chmod -R +x /alidata/server/nginx/nginx-1.12/html/
    sudo chown -R wenjianbao:wenjianbao /alidata/server/nginx/nginx-1.12/html/
    

    编译PHP遇到的问题:

    (1) 编译 libiconv 时报错:./stdio.h:1010:1: error: 'gets' undeclared here (not in a function)

    解决方案:

    先找到stdio.in.h

    vim  ./libiconv-1.14/srclib/stdio.in.h

    然后跳到 698 行,把

    _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");

    替换成

    #if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
    _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
    #endif

     (2) 编译 PHP,configure时报错:configure: error: Cannot find OpenSSLs evp.h

    解决方案:

    sudo apt-get -y install libssl-dev
    sudo ln -s /usr/lib/x86_64-linux-gnu/libssl.so  /usr/lib

    参考:http://blog.windigniter.com/2016/05/php-openssl-evp/

    (3) 编译 PHP,configure时报错:configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/

    解决方案:

    sudo apt-get -y install libcurl4-gnutls-dev
    ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/curl

    参考:Compiling php with curl, where is curl installed ?

    for 64 bit ubuntu 17.** and after, curl is moved to /usr/include/x86_64-linux-gnu/curl, so just make a symlink cd /usr/include sudo ln -s x86_64-linux-gnu/curl

    (4) 编译 PHP,configure时报错:configure: error: freetype-config not found

    解决方案:

    apt-get -y install libfreetype6-dev

    (5) 编译PHP,make时报错:

    Makefile:594: recipe for target 'ext/openssl/openssl.lo' failed
    make: *** [ext/openssl/openssl.lo] Error 1

    解决方案:

    (a) 怀疑 openssl 的版本过高,当前版本为 

    wenjianbao@wjb-pc:~$ openssl version
    OpenSSL 1.1.0e  16 Feb 2017

    (b) 重新安装低版本  OpenSSL 1.0.1e

    sudo ./config --prefix=/usr/local --openssldir=/usr/local/openssl
    sudo make
    rm -f /usr/bin/pod2man # 否则会报错:POD document had syntax errors at /usr/bin/pod2man line 69. make: *** [install_docs]
    sudo make install

    (6) 编译PHP,make时报错:

    Makefile:271: recipe for target 'sapi/cli/php' failed
    make: *** [sapi/cli/php] Error 1

    (a) 方法一:vim Makefile

    在安裝 PHP 到系统中时要是发生「undefined reference to libiconv_open'」之类的错误信息,那表示在「./configure 」沒抓好一些环境变数值。错误发生点在建立「-o sapi/cli/php」是出错,没給到要 link 的 iconv 函式库参数。 解决方法:编辑Makefile 大约77 行左右的地方: EXTRA_LIBS = ..... -lcrypt 在最后加上 -liconv,例如: EXTRA_LIBS = ..... -lcrypt -liconv 然后重新再次 make 即可。

    (b) 【推荐】方法二:make 命令后,追加 liconv,即

    sudo make ZEND_EXTRA_LIBS='-liconv'
    

    编译 MySQL

    #!/bin/bash
     
    # 安装 依赖库
    sudo apt-get -y install make cmake gcc g++ bison openssl libssl-dev  libncurses5-dev
     
    # 创建 数据 文件夹
    sudo mkdir -pv /alidata/data/mysql
     
    # 创建 mysql 用户及用户组(直接用当前登录账号:wenjianbao:wenjianbao)
    #groupadd mysql
    #useradd -g mysql -s /usr/sbin/nologin mysql # 不让 mysql 用户直接登录
     h
    # 解压 mysql-5.6.36
    cd /alidata/tmp/deepin-sdk/source2/mysql
    sudo rm -rf ./mysql-5.6.36
    sudo tar -xzvf ./mysql-5.6.36.tar.gz
    cd ./mysql-5.6.36
    sudo mkdir -pv /alidata/server/mysql/mysql-5.6
     
    # 设置 权限
    sudo chown -R wenjianbao:wenjianbao  ../mysql-5.6.36
    sudo chown -R wenjianbao:wenjianbao /alidata/server/mysql/
     
    # 生成 配置
    sudo cmake 
    -DCMAKE_INSTALL_PREFIX=/alidata/server/mysql/mysql-5.6 
    -DMYSQL_DATADIR=/alidata/data/mysql 
    -DDEFAULT_CHARSET=utf8 
    -DDEFAULT_COLLATION=utf8_unicode_ci 
    -DWITH_READLINE=1 
    -DWITH_EMBEDDED_SERVER=1 
    -DENABLED_LOCAL_INFILE=1 
    -DDEFAULT_COLLATION=utf8_general_ci 
    -DWITH_MYISAM_STORAGE_ENGINE=1 
    -DWITH_INNOBASE_STORAGE_ENGINE=1 
    -DWITH_DEBUG=0
     
    # 安装
    sudo chown -R wenjianbao:wenjianbao /alidata/server/mysql/  #不然会报错,提示 没权限
    sudo make && make install
     
    # 复制 配置文件
    #cp ./support-files/my-medium.cnf /etc/my.cnf
    #sudo mv /etc/my.cnf /etc/my.cnf.$(date "+%Y-%m-%d.%s")
    
    sudo cp -rf /alidata/tmp/deepin-sdk/config/mysql-5.6/my.cnf /alidata/server/mysql/mysql-5.6/conf/
    sudo ln -s /alidata/server/mysql/mysql-5.6/conf/my.cnf /etc/my.cnf
     
    # 设置 权限
    sudo chmod -R 755 /alidata/server/mysql/mysql-5.6
    sudo chown -R wenjianbao:wenjianbao /alidata/server/mysql/mysql-5.6
    sudo chown -R wenjianbao:wenjianbao /alidata/data/mysql
     
    # 设置 开机自动启动
    # cp ./support-files/mysql.server /etc/init.d/mysqld
    sudo cp -rf /alidata/tmp/deepin-sdk/config/mysql-5.6/mysqld.init /etc/init.d/mysqld
    
    sudo chmod +x /etc/init.d/mysqld #添加执行权限
    sudo update-rc.d mysqld defaults
    #sudo service mysqld start #启动mysql
    sudo /etc/init.d/mysqld start
     
    # 添加 mysql 的软链接以适应 init 脚本
    sudo ln -sv /alidata/server/mysql/mysql-5.6/bin/mysql  /usr/sbin/mysql
    sudo ln -sv /alidata/server/mysql/mysql-5.6/bin/mysqladmin  /usr/sbin/mysqladmin
    sudo ln -sv /alidata/server/mysql/mysql-5.6/bin/mysqldump  /usr/sbin/mysqldump
     
    # 初始化 数据库
    sudo /alidata/server/mysql/mysql-5.6/scripts/mysql_install_db 
    --user=wenjianbao 
    --basedir=/alidata/server/mysql/mysql-5.6 
    --datadir=/alidata/data/mysql
     
    # 启动 mysql
    sudo killall mysqld
    #sudo service mysqld start
    sudo /etc/init.d/mysqld start
     
    # 修改 root 密码
    # 注意:先输入旧密码(默认为空密码),然后让你输入新密码(123456)
    # /alidata/server/mysql/mysql-5.6/bin/mysqladmin -u root -p password
    

    运行 MySQL 报错

    wenjianbao@wjb-pc:/alidata/server/mysql/mysql-5.6/bin$ sudo /etc/init.d/mysqld start
    [....] Starting mysqld (via systemctl): mysqld.serviceJob for mysqld.service failed because the control process exited with error code.
    See "systemctl  status mysqld.service" and "journalctl  -xe" for details.
     failed!

    为了更清晰地看最近出错日志,我把原已有的日志文件 ./log/mysql.err 给删除了,结果因为上面报错,一直不生成错误日志文件(mysql.err)

    解决方案:

    不走服务启动,直接通过原有的命令行启动:

    wenjianbao@wjb-pc:/alidata/server/mysql/mysql-5.6/bin$ ./mysqld_safe --defaults-file=/etc/my.cnf --user=wenjianbao
    171005 23:00:38 mysqld_safe Logging to '/alidata/server/mysql/mysql-5.6/log/mysql.err'.
    171005 23:00:38 mysqld_safe Starting mysqld daemon with databases from /alidata/data/mysql
    171005 23:00:40 mysqld_safe mysqld from pid file /alidata/server/mysql/mysql-5.6/log/mysql.pid ended

    看上面的输出,貌似产生了错误日志,赶紧看看去!!!

  • 【推广】 阿里云小站-上云优惠聚集地(新老客户同享)更有每天限时秒杀!
    【推广】 云服务器低至0.95折 1核2G ECS云服务器8.1元/月
    【推广】 阿里云老用户升级四重礼遇享6.5折限时折扣!
  • 原文:https://www.cnblogs.com/52php/p/7623775.html
走看看 - 开发者的网上家园