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

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

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

iptables -F
chkconfig iptables off
vi /etc/selinux/config

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

1、安装Nginx:

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

mkdir packet
cd packet/
创建nginx用户及组
groupadd -r nginx
useradd -r -g nginx nginx
解压,编译安装
tar xf nginx-1.11.5.tar.gz
cd nginx-1.11.5
./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
make && make install
为nginx编写启用脚本,需要注意两个位置的填写:
nginx="/usr/local/nginx/sbin/nginx" (configure参数中--sbin-path参数)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"(nginx配置文件,configure参数中 --conf-path参数)
vi /etc/rc.d/init.d/nginx
#!/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/local/nginx/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/rc.d/init.d/nginx
设置开机启动nginx
chkconfig --add nginx
chkconfig nginx on
service nginx start
2、安装mariadb:
rz上传mariadb安装包
创建mariadb数据存放文件夹,并进行挂载至单独的分区(建议使用LVM)
mkdir -p /mydata/data
fdisk /dev/sdb
‘n’一个新分区,‘w’保存退出
mkfs.ext4 /dev/sdb1
编辑/etc/fstab末行新增
vi /etc/fstab
/dev/sdb1 /mydata/data ext4 defaults 0 0 挂载
mount -a 
创建mysql用户及组
groupadd -r mysql
useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
解压并为解压目录创建链接文件
tar xf mariadb-10.1.18-linux-x86_64.tar.gz
ln -sv /root/packet/mariadb-10.1.18-linux-x86_64 /usr/local/mysql
cd /usr/local/mysql
更改所有文件属主属组为mysql
chown -R mysql:mysql .
使用mysql用户将数据库初始化至上面创建并挂载的目录/mydata/data目录下
scripts/mysql_install_db --user=mysql --datadir=/mydata/data
更改文件属主root属组mysql
chown -R root .
为mysql提供配置文件
cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
更改参数,并新增datadir参数
vi /etc/my.cnf
# Try number of CPU's*2 for thread_concurrency (CPU数量*2)
thread_concurrency = 2
datadir = /mydata/data
为mysql提供启动文件,并设置开机自启
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
配置mysql的man手册,编辑/etc/my.config
vi /etc/man.config
新增行
MANPATH /usr/local/mysql/man

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

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

  

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

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

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

    什么是索引: SQL索引有两种,聚集索引和非聚集索引,索引主要目的是提高了SQL Server系统的性能,加快数据的查询速度与减少系统的响应时间. 聚集索引:该索引中键值的逻辑顺序决定了表中相应行的物 ...

  2. phpcms页面替换

    首页的替换流程首先要先把静态网页做出来,拿到这里来: 会发现这个网页里面少了图片,样式表也没有了 因为我们只把网页扔过来,所对应的图片和样式表没有扔过来 图片什么的应该扔到: 接着打开index.ht ...

  3. java中的GC(gabage collection)如何工作

    1. “引用记数(reference counting)”是一种简单但速度很慢的垃圾回收技术.每个对象都含有一个引用记数器,当有引用连接至对象时,引用计数加1.当引用离开作用域或被置 为null时,引 ...

  4. JQuery控制下拉列表

    //遍历option和添加.移除option function changeShipMethod(shipping){ var len = $("select[@name=ISHIPTYPE ...

  5. Scala基础 - 下划线使用指南

    下划线这个符号几乎贯穿了任何一本Scala编程书籍,并且在不同的场景下具有不同的含义,绕晕了不少初学者.正因如此,下划线这个特殊符号无形中增加Scala的入门难度.本文希望帮助初学者踏平这个小山坡. ...

  6. gitignore.io-程序猿值得拥有的智能生成gitignore文件的秘密武器

    gitignore.io Create useful .gitignore files for your project by selecting from 360 Operating System, ...

  7. JS 中new一个对象发生了什么事

    今天看到一个360的前端面试题: function A(){}function B(a){  this.a=a;}function C(a){  if(a){    this.a=a;   }}A.p ...

  8. 【方法】Html5实现文件异步上传

    1 简介 开发文件上传功能从来不是一件愉快的事,异步上传更是如此,使用过iframe和Flash的上传方案,也都感觉十分的别扭.本文简要简绍利用Html5的FormData实现文件的异步上传,还可以实 ...

  9. How to parse project properties or how to parse files with key-value pair

    If a file has content like raven.enabled = false raven.host = "localhost" raven.port = 808 ...

  10. 浅谈MVC异常处理

    在日常开发中,我们会去捕捉很多的异常,来进行处理,通常我们的方法就是,在需要进行异常处理的地方加上 try catch 块,但是,如果需要异常处理的地方很多,那么,就会频繁的去写try catch 块 ...