Centos7編譯安裝nginx1.15+MariaDB10.3+php-7.2

環境準備:
  yum源:wget -c http://mirrors.163.com/.help/CentOS7-Base-163.repo -O /etc/yum.repo.d/CentOS7-Base-163.repophp

下載軟件包:
  wget -c https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.3.9/source/mariadb-10.3.9.tar.gz
  wget -c http://nginx.org/download/nginx-1.15.3.tar.gz
  wget -c http://cn2.php.net/distributions/php-7.2.10.tar.gzhtml

安裝nginx依賴包:
  yum update -y 
  yum -y groupinstall "Development tools"
  yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel cmakemysql

新建nginx用戶和用戶組:
  groupadd nginx
  useradd -g nginx -s /sbin/nologin nginxnginx

安裝nginx1.15.3 c++

  tar -xvf nginx-1.15.3.tar.gz
  cd nginx-1.15.3
  ./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.pid --lock-path=/var/run/nginx.lock --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 --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --user=nginx --group=nginx --with-pcre --with-http_v2_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --with-threads --with-stream --with-stream_ssl_module 
  make
  make install
  mkdir -pv /var/tmp/nginx/clientsql


新建nginx啓動腳本
  vim /etc/init.d/nginxjson

 1 #!/bin/sh 
 2 #  3 # nginx - this script starts and stops the nginx daemon  4 #  5 # chkconfig:   - 85 15 
 6 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \  7 #               proxy and IMAP/POP3 proxy server  8 # processname: nginx  9 # config:      /etc/nginx/nginx.conf 10 # config:      /etc/sysconfig/nginx 11 # pidfile:     /var/run/nginx.pid 12 # Source function library. 13 . /etc/rc.d/init.d/functions 14 # Source networking configuration. 15 . /etc/sysconfig/network 16 # Check that networking is up. 17 [ "$NETWORKING" = "no" ] && exit 0
18 nginx="/usr/sbin/nginx"
19 prog=$(basename $nginx) 20 NGINX_CONF_FILE="/etc/nginx/nginx.conf"
21 [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx 22 lockfile=/var/lock/subsys/nginx 23 start() { 24     [ -x $nginx ] || exit 5
25     [ -f $NGINX_CONF_FILE ] || exit 6
26     echo -n $"Starting $prog: " 
27     daemon $nginx -c $NGINX_CONF_FILE 28     retval=$?
29     echo 
30     [ $retval -eq 0 ] && touch $lockfile
31  return $retval 32 } 33 stop() { 34     echo -n $"Stopping $prog: " 
35     killproc $prog -QUIT 36     retval=$?
37     echo 
38     [ $retval -eq 0 ] && rm -f $lockfile
39  return $retval 40 killall -9 nginx 41 } 42 restart() { 43     configtest || return $?
44  stop 45     sleep 1
46  start 47 } 48 reload() { 49     configtest || return $?
50     echo -n $"Reloading $prog: " 
51     killproc $nginx -HUP 52 RETVAL=$?
53     echo 
54 } 55 force_reload() { 56  restart 57 } 58 configtest() { 59 $nginx -t -c $NGINX_CONF_FILE 60 } 61 rh_status() { 62  status $prog 63 } 64 rh_status_q() { 65     rh_status >/dev/null 2>&1
66 } 67 case "$1" in
68  start) 69         rh_status_q && exit 0
70     $1
71  ;; 72  stop) 73         rh_status_q || exit 0
74         $1
75  ;; 76     restart|configtest) 77         $1
78  ;; 79  reload) 80         rh_status_q || exit 7
81         $1
82  ;; 83     force-reload) 84  force_reload 85  ;; 86  status) 87  rh_status 88  ;; 89     condrestart|try-restart) 90         rh_status_q || exit 0
91  ;; 92     *) 93       echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 
94         exit 2
95 esac

  chmod u+x /etc/init.d/nginx
  chkconfig --add nginx
  chkconfig nginx on
  service nginx startvim

安裝MariaDB依賴包
  yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel cmake ncurses-devel bisonapi

新建mysql用戶及用戶組
  groupadd mysql
  useradd -g mysql -s /sbin/nologin mysql
  mkdir -pv /var/mysql/data
  chown -R mysql.mysql /var/mysql
  mv /etc/my.cnf /etc/my.cnf.baksession

安裝MariaDB10.3.9
  tar -xvf mariadb-10.3.9.tar.gz
  cd mariadb-10.3.9
  cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/mysql/data -DSYSCONFDIR=/etc  -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_TCP_PORT=3306  -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/tmp/mysql.sock
  make
  make install
  chown -R mysql:mysql /usr/local/mysql/

新建MariaDB啓動腳本
  cp  /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
  chmod u+x /etc/init.d/mysqld
  chkconfig --add mysqld
  chkconfig mysqld on

初始化MariaDB
  /usr/local/mysql/scripts/mysql_install_db  --user=mysql --datadir=/var/mysql/data/ --basedir=/usr/local/mysql
  vim /etc/my.cnf

 1 [mysqld]  2 datadir=/var/mysql/data  3 basedir=/usr/local/mysql  4 socket=/tmp/mysql.sock  5 log_bin=/var/mysql/logbin  6 user=mysql  7 port=3306
 8 # Disabling symbolic-links is recommended to prevent assorted security risks  9 symbolic-links=0
10 # Settings user and group are ignored when systemd is used. 11 # If you need to run mysqld under a different user or group, 12 # customize your systemd unit file for mariadb according to the 13 # instructions in http://fedoraproject.org/wiki/Systemd
14 
15 [mysqld_safe] 16 log-error=/var/log/mariadb/mariadb.log 17 pid-file=/var/lib/mysql/mysql.pid 18 # 19 # include all files from the config directory 20 # 21 !includedir /etc/my.cnf.d

  service mysqld start
  /usr/local/mysql/bin/mysql_secure_installation #設置MairiaDB密碼

添加mysql至環境變量

  echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
  source /etc/profile

安裝php依賴包
  yum install epel-release -y
  yum install libmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2 bzip2-devel libpng-devel libjpeg-devel  freetype-devel  libtidy-devel libtidy  libcurl-devel  gmp-devel libicu-devel openldap openldap-devel   libsmbclient ImageMagick-devel readline-devel libc-client-devel  zlib1g-dev -y 
  ln -s /usr/lib64/libc-client.so /usr/lib/
  ln -s /usr/lib64/libssl.so /usr/lib/
  ln -s /usr/lib64/libldap.so /usr/lib/
  cp -frp /usr/lib64/libldap* /usr/lib/

安裝php-7.2

  tar -xvf php-7.2.10.tar.gz
  cd php-7.2.10
  ./configure --prefix=/usr/local/php  --with-config-file-path=/usr/local/php/etc  --with-fpm-user=nginx  --with-fpm-group=nginx --enable-fpm --with-mhash --with-openssl --enable-bcmath --enable-mbstring --enable-calendar  --enable-json --enable-ftp  --enable-sockets --enable-session --enable-soap --with-gmp --with-kerberos --with-imap --with-imap-ssl --with-mysqli --with-pdo-mysql --enable-inline-optimization  --with-mhash  --with-gd --with-jpeg-dir --with-png-dir --with-pcre-dir  --with-freetype-dir --with-curl --with-gettext --with-bz2   --enable-mysqlnd   --with-gettext  --enable-bcmath   --with-iconv-dir  --without-pear
  make
  make install 
  mkdir -p /var/lib/php/session
  chown nginx:nginx -R /var/lib/php/session/

建立php啓動腳本

  cp /root/php-7.2.10/php.ini-production /usr/local/php/etc/php.ini
  cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
  cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
  ln -s /usr/local/php/etc/php.ini /usr/local/etc/
  ln -s /usr/local/php/etc/php-fpm.conf /usr/local/etc/
  ln -s /usr/local/php/etc/php-fpm.d/www.conf /usr/local/etc/
  cp /root/php-7.2.10/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  chmod u+x /etc/init.d/php-fpm
  chkconfig --add php-fpm
  chkconfig php-fpm on
  service php-fpm start

添加php至環境變量
  echo "export PATH=$PATH:/usr/local/php/bin" >>/etc/profile
  source /etc/profile

nginx支持php
  vim /etc/nginx.nginx.conf
  

 1 #user nobody;  2 worker_processes  1;  3 
 4 #error_log  logs/error.log;  5 #error_log  logs/error.log notice;  6 #error_log  logs/error.log  info;  7 
 8 #pid        logs/nginx.pid;  9 
 10 
 11 events {  12     worker_connections  1024;  13 }  14 
 15 
 16 http {  17  include mime.types;  18     default_type  application/octet-stream;  19 
 20     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 21     #                  '$status $body_bytes_sent "$http_referer" '
 22     #                  '"$http_user_agent" "$http_x_forwarded_for"';  23 
 24     #access_log  logs/access.log main;  25 
 26  sendfile on;  27  #tcp_nopush on;  28 
 29     #keepalive_timeout  0;  30     keepalive_timeout  65;  31 
 32     #gzip on;  33 
 34  server {  35         listen       80;  36  server_name localhost;  37 
 38         #charset koi8-r;  39 
 40         #access_log  logs/host.access.log main;  41 
 42         location / {  43             root   /usr/local/nginx/html;  44  index index.php index.html index.htm;  45  }  46 
 47         #error_page  404              /404.html;  48 
 49         # redirect server error pages to the static page /50x.html  50  #  51         error_page   500 502 503 504  /50x.html;  52         location = /50x.html {  53             root   /usr/local/nginx/html;  54  }  55 
 56         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
 57  #  58         #location ~ \.php$ {  59         #    proxy_pass   http://127.0.0.1;
 60  #}  61 
 62         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 63  #  64         location ~ \.php$ {  65             root           /usr/local/nginx/html;  66             fastcgi_pass   127.0.0.1:9000;  67  fastcgi_index index.php;  68             fastcgi_param  SCRIPT_FILENAME  usr/local/nginx/html/$fastcgi_script_name;  69  include fastcgi_params;  70  }  71 
 72         # deny access to .htaccess files, if Apache's document root
 73         # concurs with nginx's one
 74  #  75         #location ~ /\.ht {  76  # deny all;  77  #}  78  }  79 
 80 
 81     # another virtual host using mix of IP-, name-, and port-based configuration  82  #  83  #server {  84     #    listen       8000;  85     #    listen       somename:8080;  86  # server_name somename alias another.alias;  87 
 88     #    location / {  89  # root html;  90  # index index.html index.htm;  91  # }  92  #}  93 
 94 
 95  # HTTPS server  96  #  97  #server {  98     #    listen       443 ssl;  99  # server_name localhost; 100 
101  # ssl_certificate cert.pem; 102  # ssl_certificate_key cert.key; 103 
104  # ssl_session_cache shared:SSL:1m; 105  # ssl_session_timeout 5m; 106 
107     #    ssl_ciphers  HIGH:!aNULL:!MD5; 108  # ssl_prefer_server_ciphers on; 109 
110     #    location / { 111  # root html; 112  # index index.html index.htm; 113  # } 114  #} 115 
116 }

添加測試頁面

  vim /usr/local/nginx/html/index.php

<?php $conn=mysqli_connect('127.0.0.1','root','yh984664'); if ($conn){ echo "LNMP platform connect to mysql is successful!"; }else{ echo "LNMP platform connect to mysql is failed!"; } phpinfo(); ?>
相關文章
相關標籤/搜索