新装CentOS 6.7,安装默认服务版本basic server

安装顺序linux(忽略...)--> Nginx--> Mariadb--> PHP

为了不影响测试效果,首先关闭selinux及iptables。校对系统时间。

  1. iptables -F
  2. chkconfig iptables off
  3. vi /etc/selinux/config

  4. SELINUX=enforcing
  5. 更改为
  6. SELINUX=disabled
  7. 修改时区
  8. cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  9. 安装rz上传组件:
  10. yum install lrzsz -y

1、安装Nginx:

安装依赖,新建文件夹,rz上传nginx安装包。

  1. mkdir packet
  2. cd packet/
创建nginx用户及组
  1. groupadd -r nginx
  2. useradd -r -g nginx nginx
解压,编译安装
  1. tar xf nginx-1.11.5.tar.gz
  2. cd nginx-1.11.5
  3. ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/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/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre
  4. make && make install
为nginx编写启用脚本,需要注意两个位置的填写:
  1. nginx="/usr/local/nginx/sbin/nginx" configure参数中--sbin-path参数)
  2. NGINX_CONF_FILE="/etc/nginx/nginx.conf"nginx配置文件,configure参数中 --conf-path参数)
  3. vi /etc/rc.d/init.d/nginx
  4. #!/bin/sh
  5. #
  6. # nginx - this script starts and stops the nginx daemon
  7. #
  8. # chkconfig: - 85 15
  9. # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
  10. # proxy and IMAP/POP3 proxy server
  11. # processname: nginx
  12. # config: /etc/nginx/nginx.conf
  13. # config: /etc/sysconfig/nginx
  14. # pidfile: /var/run/nginx.pid
  15.  
  16. # Source function library.
  17. . /etc/rc.d/init.d/functions
  18.  
  19. # Source networking configuration.
  20. . /etc/sysconfig/network
  21.  
  22. # Check that networking is up.
  23. [ "$NETWORKING" = "no" ] && exit 0
  24.  
  25. nginx="/usr/local/nginx/sbin/nginx"
  26. prog=$(basename $nginx)
  27.  
  28. NGINX_CONF_FILE="/etc/nginx/nginx.conf"
  29.  
  30. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
  31.  
  32. lockfile=/var/lock/subsys/nginx
  33.  
  34. make_dirs() {
  35. # make required directories
  36. user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
  37. options=`$nginx -V 2>&1 | grep 'configure arguments:'`
  38. for opt in $options; do
  39. if [ `echo $opt | grep '.*-temp-path'` ]; then
  40. value=`echo $opt | cut -d "=" -f 2`
  41. if [ ! -d "$value" ]; then
  42. # echo "creating" $value
  43. mkdir -p $value && chown -R $user $value
  44. fi
  45. fi
  46. done
  47. }
  48.  
  49. start() {
  50. [ -x $nginx ] || exit 5
  51. [ -f $NGINX_CONF_FILE ] || exit 6
  52. make_dirs
  53. echo -n $"Starting $prog: "
  54. daemon $nginx -c $NGINX_CONF_FILE
  55. retval=$?
  56. echo
  57. [ $retval -eq 0 ] && touch $lockfile
  58. return $retval
  59. }
  60.  
  61. stop() {
  62. echo -n $"Stopping $prog: "
  63. killproc $prog -QUIT
  64. retval=$?
  65. echo
  66. [ $retval -eq 0 ] && rm -f $lockfile
  67. return $retval
  68. }
  69.  
  70. restart() {
  71. configtest || return $?
  72. stop
  73. sleep 1
  74. start
  75. }
  76.  
  77. reload() {
  78. configtest || return $?
  79. echo -n $"Reloading $prog: "
  80. killproc $nginx -HUP
  81. RETVAL=$?
  82. echo
  83. }
  84.  
  85. force_reload() {
  86. restart
  87. }
  88.  
  89. configtest() {
  90. $nginx -t -c $NGINX_CONF_FILE
  91. }
  92.  
  93. rh_status() {
  94. status $prog
  95. }
  96.  
  97. rh_status_q() {
  98. rh_status >/dev/null 2>&1
  99. }
  100.  
  101. case "$1" in
  102. start)
  103. rh_status_q && exit 0
  104. $1
  105. ;;
  106. stop)
  107. rh_status_q || exit 0
  108. $1
  109. ;;
  110. restart|configtest)
  111. $1
  112. ;;
  113. reload)
  114. rh_status_q || exit 7
  115. $1
  116. ;;
  117. force-reload)
  118. force_reload
  119. ;;
  120. status)
  121. rh_status
  122. ;;
  123. condrestart|try-restart)
  124. rh_status_q || exit 0
  125. ;;
  126. *)
  127. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  128. exit 2
  129. esac
给启动脚本执行权限
  1. chmod +x /etc/rc.d/init.d/nginx
设置开机启动nginx
  1. chkconfig --add nginx
  2. chkconfig nginx on
  3. service nginx start
2、安装mariadb:
rz上传mariadb安装包
创建mariadb数据存放文件夹,并进行挂载至单独的分区(建议使用LVM)
  1. mkdir -p /mydata/data
  2. fdisk /dev/sdb
‘n’一个新分区,‘w’保存退出
  1. mkfs.ext4 /dev/sdb1
编辑/etc/fstab末行新增
  1. vi /etc/fstab
  2. /dev/sdb1 /mydata/data ext4 defaults 0 0
  3.  
  4. 挂载
  5. mount -a 
创建mysql用户及组
  1. groupadd -r mysql
  2. useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
解压并为解压目录创建链接文件
  1. tar xf mariadb-10.1.18-linux-x86_64.tar.gz
  2. ln -sv /root/packet/mariadb-10.1.18-linux-x86_64 /usr/local/mysql
    cd /usr/local/mysql
更改所有文件属主属组为mysql
  1. chown -R mysql:mysql .
使用mysql用户将数据库初始化至上面创建并挂载的目录/mydata/data目录下
  1. scripts/mysql_install_db --user=mysql --datadir=/mydata/data
更改文件属主root属组mysql
  1. chown -R root .
为mysql提供配置文件
  1. cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
更改参数,并新增datadir参数
  1. vi /etc/my.cnf
  2. # Try number of CPU's*2 for thread_concurrency (CPU数量*2)
  3. thread_concurrency = 2
  4. datadir = /mydata/data
为mysql提供启动文件,并设置开机自启
  1. cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
  2. chkconfig --add mysqld
  3. chkconfig mysqld on
配置mysql的man手册,编辑/etc/my.config
  1. vi /etc/man.config
  2. 新增行
  3. MANPATH /usr/local/mysql/man

mysql的头文件输出至系统的头文件

  1. ln -sv /usr/local/mysql/include /usr/include/mysql  
mysql库文件路径输出至系统库文件
  1. echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf  
重载数据库
  1. ldconfig  
修改PATH变量,使系统可直接使用mysql相关命令
  1. vi /etc/profile
  2. 末尾新增行
  3. PATH=/usr/local/mysql/bin:$PATH
  4. export PATH

  

  1. source /etc/profile 
启动数据库
  1. service mysqld start
3、安装PHP
安装依赖
  1. yum -y groupinstall "X Software Development"
  2. yum -y install libxml2 libxml2-devel bzip2-devel curl-devel libjpeg-devel libpng-devel freetype-devel

rz上传php,解压并编译安装

  1. tar xf php-5.6.27.tar.bz2
  2. cd php-5.6.27
  3. ./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
  4. make && make test && make install  
为php提供配置文件(configure编译时未使用--with-config-file-path参数,则默认在/usr/local/php/lib/目录下)
  1. cp packet/php-5.6.27/php.ini-production /etc/php.ini  
为php-fpm提供init文件,并设置开机自启
  1. cp packet/php-5.6.27/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
  2. chmod +x /etc/rc.d/init.d/php-fpm
  3. chkconfig --add php-fpm
  4. chkconfig php-fpm on  
为php-fpm提供配置文件
  1. cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf  
编辑php-fpm配置文件
  1. vi /usr/local/php/etc/php-fpm.conf
  2. pm.max_children = 150
  3. pm.start_servers = 8
  4. pm.min_spare_servers = 5
  5. pm.max_spare_servers = 10
  6. pid = /usr/local/php/var/run/php-fpm.pid 
 启动
  1. service php-fpm start
4、整合php和nginx
  1. vi /etc/nginx/nginx.conf
  2. 添加index.php
  3. location / {
  4. root html;
  5. index index.html index.htm index.php;
  6. }
  7.  
  8. 启用php
  9. location ~ \.php$ {
  10. root html;
  11. fastcgi_pass 127.0.0.1:9000;
  12. fastcgi_index index.php;
  13. fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  14. include fastcgi_params;
  15. }  
编辑/etc/nginx/fastcgi_params
  1. vi /etc/nginx/fastcgi_params
  2. fastcgi_param GATEWAY_INTERFACE CGI/1.1;
  3. fastcgi_param SERVER_SOFTWARE nginx;
  4. fastcgi_param QUERY_STRING $query_string;
  5. fastcgi_param REQUEST_METHOD $request_method;
  6. fastcgi_param CONTENT_TYPE $content_type;
  7. fastcgi_param CONTENT_LENGTH $content_length;
  8. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  9. fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  10. fastcgi_param REQUEST_URI $request_uri;
  11. fastcgi_param DOCUMENT_URI $document_uri;
  12. fastcgi_param DOCUMENT_ROOT $document_root;
  13. fastcgi_param SERVER_PROTOCOL $server_protocol;
  14. fastcgi_param REMOTE_ADDR $remote_addr;
  15. fastcgi_param REMOTE_PORT $remote_port;
  16. fastcgi_param SERVER_ADDR $server_addr;
  17. fastcgi_param SERVER_PORT $server_port;
  18. fastcgi_param SERVER_NAME $server_name;
重载nginx
  1. service nginx reload
在nginx的web主目录下添加index.php文件
  1. cd /usr/local/nginx/ html/
  2. vi index.php
  3. <?php
  4. phpinfo();
  5. ?>
浏览器中访问http://主机IP/index.php进行测试
  1. [root@localhost ~]# netstat -antp
  2. Active Internet connections (servers and established)
  3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  4. tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2201/php-fpm
  5. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2715/nginx
  6. tcp 0 0 127.0.0.1:34197 0.0.0.0:* LISTEN 2903/sshd
  7. tcp 0 0 127.0.0.1:34198 0.0.0.0:* LISTEN 2903/sshd
  8. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2225/sshd
  9. tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2020/cupsd
  10. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2585/master
  11. tcp 0 0 172.28.1.8:10051 172.28.1.5:51231 TIME_WAIT -
  12. tcp 0 52 172.28.1.8:22 172.28.1.5:51242 ESTABLISHED 2903/sshd
  13. tcp 0 0 :::3306 :::* LISTEN 2444/mysqld
  14. tcp 0 0 ::1:34197 :::* LISTEN 2903/sshd
  15. tcp 0 0 ::1:34198 :::* LISTEN 2903/sshd
  16. tcp 0 0 :::22 :::* LISTEN 2225/sshd
  17. tcp 0 0 ::1:631 :::* LISTEN 2020/cupsd
  18. tcp 0 0 ::1:25 :::* LISTEN 2585/master
  19. [root@localhost ~]#

源码安装LNMP环境的更多相关文章

  1. ubuntu 源码安装 lnmp 环境

    准备篇 下载软件包 1.下载nginx http://nginx.org/download/nginx-1.2.0.tar.gz 2.下载pcre  (支持nginx伪静态) ftp://ftp.cs ...

  2. linux 手动源码安装lnmp(亲测)

    linux 手动源码安装lnmp笔记(亲测)<pre>先安装这2个yum install gccyum install g++</pre><pre>先在linux ...

  3. CENTOS6.5源码安装LNMP

    CENTOS6.5源码安装LNMP 一.安装前准备 ########################################################################## ...

  4. 在CENTOS上源码搭建LNMP环境

    前言 1.操作前提: CentOS Linux release 7.5.1804: sudo用户(需要root权限): 2.需要安装的组件: nginx稳定版:nginx-1.14.0: MariaD ...

  5. 终于完成了 源码 编译lnmp环境

    经过了大概一个星期的努力,终于按照海生的编译流程将lnmp环境源码安装出来了 nginx 和php 主要参考 http://hessian.cn/p/1273.html mysql 主要参考 http ...

  6. 源码安装LNMP与搭建Zabbix

    系统环境:CentOS release 6.5 (Final) 搭建Zabbix 3.0对PHP环境要求>= 5.4 一.下载NMP的软件包: N:wget http://nginx.org/d ...

  7. 用源码搭建LNMP环境+部署WordPress

    首先要做的是就是关闭Centos7.4的防火墙及selinux #systemctl stop firewalld #systemctl disable firewalld #sed -ri 's/^ ...

  8. CentOS 7 源码搭建LNMP环境

    搭建 LNMP 环境 源码包版本 :  CentOS Linux  7 nginx-1.15.1.tar.gz  mysql-boost-5.7.21.tar.gz  php-7.2.7.tar.gz ...

  9. CentOS 下源码安装LAMP环境

    一.简介 什么是LAMP    LAMP是一种Web网络应用和开发环境,是Linux, Apache, MySQL, Php/Perl的缩写,每一个字母代表了一个组件,每个组件就其本身而言都是在它所代 ...

随机推荐

  1. OC中的私有变量和私有方法

    在类的实现即.m文件中也可以声明成员变量,但是因为在其他文件中通常都只是包含头文件而不会包含实现文件,所以在.m文件中声明的成员变量是@private得.在 .m中定义的成员变量不能和它的头文件.h中 ...

  2. 重庆/北京/江苏KS/快乐时时/七星/福运来菠菜电商开奖修复APP网站SSC网站程序开发php

    网站制作是指使用标识语言(markup language),通过一系列设计.建模.和执行的过程将电子格式的信息通过互联网传输,最终以图形用户界面(GUI)的形式被用户所浏览.简单来说,网页设计的目的就 ...

  3. [刷题]Codeforces 746G - New Roads

    Description There are n cities in Berland, each of them has a unique id - an integer from 1 to n, th ...

  4. jQuery库冲突解决办法

    一次面试中面试官问到jQuery解决怎么冲突?虽然以前看过,但是我已经不记得了. 我的思路就是如果让我来设计,那我就用一个默认值$,不传参数,那就用$,最后就挂载在window.$上,传参数就用传入名 ...

  5. 测试class

    各种断言方法: assertEqual(a,b) a == b assertNotEqual(a,b) a != b assertTrue(x) x == True assertFalse(x) x ...

  6. UNIX文件I/O

    第一次用markdown语法写博客,写出来的还比较整齐,感觉博客园对序号的支持不是很好,调了一会才有了比较满意的效果,还有有哪位知道使用markdown如何插入frame? 这边博客主要说了APUE中 ...

  7. VR大时代-全景智慧城市搭建是一个任重而道远的任务

    全景智慧城市搭建是一个任重而道远的任务,但是也促进了实体市场的蓬勃发展与进步.VR技术改变了人们以往的娱乐方式,而全景智慧城市将会彻底改变人们的生活习惯.VR是未来的计算平台,更是人力发展历史中,技术 ...

  8. UX2内核浏览加速技术纲要

    UX2内核是本人负责主要开发的浏览服务项目,其主要目的是为开发者提供一个简单好用.轻便的网络浏览服务.UX2内核的安卓端是基于WebView进行深度优化的,同时欢迎大家使用这个内核用于app页面或浏览 ...

  9. python 收录集中实现线程池的方法

    概念: 什么是线程池? 诸如web服务器.数据库服务器.文件服务器和邮件服务器等许多服务器应用都面向处理来自某些远程来源的大量短小的任务.构建服务器应用程序的一个过于简单的模型是:每当一个请求到达就创 ...

  10. 红包项目总结---MVC版

    起因: 针对传统版的明显缺陷做优化.主要是提升可维护性. 效果  线上:  未发布 线下:http://10.27.5.1/svn/FED/code/hongbao/year-end   hb-fac ...