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.repo

下载软件包:
  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.gz

安装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 cmake

新建nginx用户和用户组:
  groupadd nginx
  useradd -g nginx -s /sbin/nologin nginx

安装nginx1.15.3 

  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/client

新建nginx启动脚本
  vim /etc/init.d/nginx

 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 start

安装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 bison

新建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.bak

安装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();
?>

  

原文地址:https://www.cnblogs.com/chenxiaoweiworkinghard/p/9746291.html

时间: 2024-10-11 11:51:06

Centos7编译安装nginx1.15+MariaDB10.3+php-7.2的相关文章

[原创]CentOS7编译安装OpenResty1.15.8.2(填坑之旅)

原创文章,转载请注明出处:https://blog.51cto.com/indian/2445786 一.安装前置环境 1.编译工具安装 yum install -y epel-release yum install -y gcc gcc-c++ curl 2.调整系统时区 date timedatectl sudo timedatectl set-timezone Asia/Shanghai sudo dnf install -y chrony 3.其它自己需要的工具 yum install

CentOS7编译安装nginx1.8.1

1.Nginx介绍:   Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.由俄 罗斯的程序设计师IgorSysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамбле р)使用.其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表 现较好,中国大陆使用nginx网站用户有:百度.京东.新浪.网易.腾讯.淘宝等.   2.软件安装环境: 操作系统版本:Ce

CentOS7编译安装nginx-1.8.1和编译参数

Web服务器Nginx LNMP是一组众所周知的Web网站服务器架构环境,即由Linux+Nginx+MySQL+PHP(MySQL有时也指 Mariadb)组合成一个高性能.轻量.稳定.扩展性强的Web网站服务器架构环境. Nginx ("engine x") 作为Web服务器软件,是一个轻量级.高性能的HTTP和反向代理服务器,负 载均衡服务器,及电子邮件IMAP/POP3/SMTP 服务器.Nginx性能稳定.功能丰富.运维简单.效率高 .并发能力强.处理静态文件速度快且消耗系统

centos7 编译安装nginx1.16.0( 完整版 )

一.安装依赖包 yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel 依赖包说明: 1.编译依赖 gcc 环境,所以需要:gcc gcc-c++; 2.PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库.nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcr

Centos7 编译安装mariadb-10.1.22

mariadb-10.1.22 源码编译安装 下载文件https://mariadb.com/ 1.安装开发环境 yum groupinstall "Development Tools" 安装需要包: yum install -y ncurses-devel openssl-devel openssl 2.安装cmake tar -xf cmake-3.8.0.tar.gz cd cmake-3.8.0 ./bootstrap make make install 3.安装前准备 3.1

开发人员学Linux(6):CentOS7编译安装MySQL5.17.8多实例及主从复制

1.前言上一篇讲述了如何在CentOS7下编译安装Nginx-1.12.0并如何配置反向代理,本篇将讲述如何编译安装MySQL5.7.18并配置多实例.2.准备2.1下载MySQL5.7.18源码注意最新版本的MySQL需要Boost才能编译安装,在MySQL提供的下载中有不带boost的源码,还有带boost的源码,如果下载不带boost的源码还需要再去下载boost源码,为省事起见,建议下载带boost的源码,下载地址:https://cdn.mysql.com//Downloads/MyS

一、Centos6.7编译安装Nginx1.81

声明:本系列教程由马哥教育提供指导: Centos6.7编译安装Nginx1.81 +mysql-5.5.33 + php-5.5 1.nginx简介: Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用.其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表

CentOS7 编译安装LNMP

LNMP(Linux-Nginx-Mysql-PHP),本文在CentOS7.0上编译LNMP尝尝鲜,全文基本上都是采用手动编译部署...依赖yum帮我安装了GCC和automake..写这个东西耗时有点久了...尼玛 太花时间啦,Linux运维交流群:344177552 主要软件版本: nginx-1.6.0php-5.3.5mysql-5.5.6 yum源配置(其实没什么改动) [[email protected] ~]# cat /etc/yum.repos.d/1.repo [1]nam

二、Ubuntu下编译安装Nginx1.8.0

    在Ubuntu下搭建LNMP环境.编译安装mysql,nginx,php.最后在LNMP前提下安装composer,并且安装laravel框架.首先,第二步开始编译安装Nginx1.8.0 1.先进入"/usr/local/src"文件夹中,接着键入 "sudo wget http://nginx.org/download/nginx-1.8.0.tar.gz"回车,等待下载完毕.下载完毕后,执行"sudo tar zxvf nginx-1.8.0