selinux可能会致使编译安装失败,我们先禁用它。永久禁用,需要重启生效

sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

临时禁用,不需要重启

setenforce
iptables -I INPUT -p tcp –dport -j ACCEPT

安装必备工具

yum -y install gcc automake autoconf libtool make gcc-c++ glibc libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel pcre pcre-devel libmcrypt libmcrypt-devel cmake

几点说明:

pcre、openssl、zlib是安装nginx时需要的
cmake是安装MySQL时需要的

配置下载地址

cat > /usr/local/src/url << “EOF”
http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
http://nginx.org/download/nginx-1.8.1.tar.gz
http://jp2.php.net/distributions/php-5.6.30.tar.gz
http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.30.tar.gz
EOF

下载

wget -P /usr/local/src -i /usr/local/src/url

解压

cd /usr/local/src
for i in *.tar.gz ; do tar zxvf $i; done

安装cmake

cd cmake-2.8.10.2
./bootstrap
gmake && gmake install

安装mysql

创建mysql安装目录、组、账号

groupadd mysql ; useradd -g mysql -s /sbin/nologin mysql
mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql
mkdir -p /usr/local/mysql ; chown -R mysql:mysql /usr/local/mysql

开始安装

cd ../mysql-5.6.
cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE= \
-DWITH_ARCHIVE_STORAGE_ENGINE= \
-DWITH_BLACKHOLE_STORAGE_ENGINE= \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_TCP_PORT= \
-DENABLE_DOWNLOADS= .
make && make install

初始化数据库 拷贝配置文件

cd /usr/local/mysql/
scripts/mysql_install_db –user=mysql –datadir=/data/mysql
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld

添加启动目录

vim /etc/profile

按G移动光标到最后一行o插入以下两行

PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH

更新配置文件

source /etc/profile

设置开机启动并启动

chkconfig mysqld on
service mysqld start

登陆测试,默认是没有密码,直接回车就可进入

mysql -uroot -p

设置mysql密码

SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘password’);

查看用户

select user,host from mysql.user;

删除不必要的用户

drop user “”@localhost;
drop user “”@c65mini.localdomain;
drop user root@c65mini.localdomain;
drop user root@’::′;

赋予账号远程访问的权限

GRANT ALL PRIVILEGES ON *.* TO ‘root’@’127.0.0.1’ IDENTIFIED BY ‘你的密码’ WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’localhost’ IDENTIFIED BY ‘你的密码’ WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’c65mini.localdomain’ IDENTIFIED BY ‘你的密码’ WITH GRANT OPTION;

针对数据库创建一个全部权限的用户

grant all on wordpress.* to ‘admin’@’localhost’ identified by ‘’;
UPDATE user SET password=PASSWORD(‘′) WHERE user=’root’;

其它一些信息查询: 检查mysql版本

mysql -uroot -p”密码” -e “select version();”

安装php

cd /usr/local/src/php-5.6.
./configure \
–prefix=/usr/local/php \
–with-config-file-path=/usr/local/php/etc \
–enable-fpm \
–with-fpm-user=php-fpm \
–with-fpm-group=php-fpm \
–with-mysql=/usr/local/mysql \
–with-mysql-sock=/usr/local/mysql/mysql.sock \
–with-libxml-dir \
–with-gd \
–with-jpeg-dir \
–with-png-dir \
–with-freetype-dir \
–with-iconv-dir \
–with-zlib-dir \
–with-mcrypt \
–enable-soap \
–enable-gd-native-ttf \
–enable-ftp \
–enable-mbstring \
–enable-exif \
–enable-zend-multibyte \
–disable-ipv6 \
–with-pear \
–with-curl \
–with-openssl \
–disable-fileinfo
make && make install

创建用户

groupadd www ; useradd -g www /sbin/nologin www

修改配置文件

cp php.ini-production /usr/local/php/etc/php.ini
cat > /usr/local/php/etc/php-fpm.conf << “EOF”
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = www
group = www
listen.owner = www
listen.group = www
pm = dynamic
pm.max_children =
pm.start_servers =
pm.min_spare_servers =
pm.max_spare_servers =
pm.max_requests =
rlimit_files =
EOF

保存配置文件后,检验配置是否正确的方法, 如果出现诸如 “test is successful” 字样,说明配置没有问题。

/usr/local/php/sbin/php-fpm -t

启动php-fpm

cp /usr/local/src/php-5.6./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod /etc/init.d/php-fpm
service php-fpm start
chkconfig php-fpm on

检测是否启动:

ps aux |grep php-fpm

看看是不是有很多个进程(大概20多个)。

安装nginx

cd ../nginx-1.8.
./configure \
–prefix=/usr/local/nginx \
–user=www \
–group=www \
–with-http_realip_module \
–with-http_sub_module \
–with-http_gzip_static_module \
–with-pcre

编译nginx

make && make install

因为nginx比较小,所以很快就会安装完,而且也不会出什么错误

编写nginx启动脚本,并加入系统服务

cat > /etc/init.d/nginx <<“EOF”
#!/bin/bash
# chkconfig: –
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN=”/usr/local/nginx/sbin/nginx”
NGINX_CONF=”/usr/local/nginx/conf/nginx.conf”
NGINX_PID=”/usr/local/nginx/logs/nginx.pid”
RETVAL=
prog=”Nginx”
start() {
echo -n $”Starting $prog: “
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $”Stopping $prog: “
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload(){
echo -n $”Reloading $prog: “
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){
stop
start
}
configtest(){
$NGINX_SBIN -c $NGINX_CONF -t
return
}
case “$” in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $”Usage: $ {start|stop|reload|restart|configtest}”
RETVAL=
esac
exit $RETVAL
EOF

保存后,更改权限:

chmod  /etc/init.d/nginx
chkconfig –add nginx
chkconfig nginx on

更改nginx配置

首先把原来的配置文件清空: 写入如下内容:

cat > /usr/local/nginx/conf/nginx.conf << “EOF”
user www www;
worker_processes ;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile ;
events
{
use epoll;
worker_connections ;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size ;
server_names_hash_max_size ;
log_format combined_realip ‘$remote_addr $http_x_forwarded_for [$time_local]’
‘$host “$request_uri” $status’
‘”$http_referer” “$http_user_agent”‘;
sendfile on;
tcp_nopush on;
keepalive_timeout ;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size ;
client_header_buffer_size 1k;
large_client_header_buffers 4k;
request_pool_size 4k;
output_buffers 32k;
postpone_output ;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 8k;
gzip_comp_level ;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm application/xml;
include vhosts/*.conf;
}
EOF
mkdir -p /usr/local/nginx/conf/vhosts
cat > /usr/local/nginx/conf/vhosts/default.conf << “EOF”

server
{
listen default_server;
server_name localhost;
index index.html index.htm index.php;
root /tmp/;
deny all;
}
EOF
mkdir -p /data/www/test
cat > /usr/local/nginx/conf/vhosts/test.conf << “EOF”

server
{
listen ;
server_name test.com;
index index.html index.htm index.php;
root /data/www/test;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www/test$fastcgi_script_name;
}
}
EOF

保存配置后,先检验一下配置文件是否有错误存在:

/usr/local/nginx/sbin/nginx -t

启动看是否有进程。

service nginx start
ps aux |grep nginx

测试是否解析php文件

cat > /data/www/test/.php << “EOF”
<?php
echo “测试php是否解析”;
?>
EOF

测试php是否解析

curl -x127.0.0.: test.com/.php

CentOS6.8搭建LNMP环境的更多相关文章

  1. CentOS6.6搭建LNMP环境

    CentOS6.6搭建LNMP环境 1.设置yum源,本地安装依赖包 1 yum -y install gcc gcc-c++ automake autoconf libtool make 2.下载依 ...

  2. CentOS6.7搭建LNMP环境

    1:查看环境: [root@localhost ~]# cat /etc/redhat-release 2:关掉防火墙 #重启后生效开启 [root@localhost ~]# chkconfig i ...

  3. centos6.5搭建lnmp环境

    注:本文原文链接:http://www.cnblogs.com/xiaoit/p/3991037.html 本文只是做保存使用 1:查看环境: [root@10-4-14-168 html]# cat ...

  4. Centos6.x搭建lnmp环境

    查看系统版本 #cat /etc/redhat-release CentOS release 6.7 (Final) 配置静态ip #vi /etc/sysconfig/network-scripts ...

  5. Docker之使用Docker-compose搭建LNMP环境

    之前有随笔介绍使用Docker-compose搭建LNMP环境(centos6 php5.6) https://www.cnblogs.com/minseo/p/10146982.html 本文介绍D ...

  6. Yum搭建LNMP环境(动、静、库分离)(week4_day5)--技术流ken

    前言 本篇博客使用yum来搭建lnmp环境,将采用动态,静态以及数据库分开安装的方式即nginx,php,mysql.会被分开安装在不同的服务器之上,搭建出来一套lnmp环境,并部署wordpress ...

  7. [Linux] deepin15.8搭建LNMP环境

    LAMP和LNMP LAMP==Linux+Apache+Mysql+PHP LNMP==Linux+Nginx+Mysql+PHP 安装nginx sudo apt install nginx 安装 ...

  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. Vmware搭建LNMP环境(Centos7+Nginx+Mysql+PHP7.1.8)

    参考:1.Linux学习之CentOS(一)----在VMware虚拟机中安装CentOS 7(图文教程) 2.Centos7搭建LNMP环境 3.MySQL5.7修改默认root密码 4.CentO ...

随机推荐

  1. 【已转移】【缓存与性能优化】一篇文章搞掂:Redis

    本文篇幅较长,建议合理利用右上角目录进行查看(如果没有目录请刷新). 一.什么是Redis 全称: Remote Dictionary Server 远程字典服务器 实质: 一个缓存结构服务器或数据结 ...

  2. thinkphp5一键清除缓存

    入口文件定义缓存文件路径常量 define('DS', DIRECTORY_SEPARATOR); defined('APP_PATH') or define('APP_PATH', dirname( ...

  3. margin 负值问题

    * margin-top 和 margin-left 负值,自身元素向上.向左移动: * margin-right 负值,右侧元素左移,自身元素不受影响: * margin-bottom 负值,下方元 ...

  4. CSS样式初始化代码

    CSS样式初始化代码 为什么要初始化CSS? 建站老手都知道,这是为了考虑到浏览器的兼容问题,其实不同浏览器对有些标签的默认值是不同的,如果没对CSS初始化往往会出现浏览器之间的页面差异.当然,初始化 ...

  5. JS-拷贝对象

    As it is well known to us all, 拷贝对象分为浅拷贝和深拷贝,深拷贝只会复制地址,深拷贝才会复制内容,那么 JS 如何进行这两种拷贝呢? # 浅拷贝 ## Object.a ...

  6. 自己写一个 wsgi 服务器运行 Django 、Tornado 等框架应用

    https://blog.csdn.net/heybob/article/details/52288006

  7. Leetcode 最长连续序列

    题目链接:https://leetcode-cn.com/problems/longest-consecutive-sequence/ 题目大意: 略. 分析: 注意有重复值,序列为空等情况. 代码如 ...

  8. cmd 运行 java 文件

    在安装好jdk 并配置好环境变量的情况下 原因一:没有指定class文件的路径 例如HI是变异好的class文件,并且在d:/RJAZB里面 如果写成 Java HI  则会报错 正确做法 java ...

  9. io.lettuce.core.RedisCommandExecutionException: ERR unknown command 'GEOADD'

    io.lettuce.core.RedisCommandExecutionException: ERR unknown command 'GEOADD' at io.lettuce.core.Exce ...

  10. linux下如何挂载磁盘

    1.显示磁盘使用情况:#df 2.显示磁盘:#fdisk -l 3.格式化分区:#mkfs.ext4 /dev/vdb1           //注:将/dev/vdb1格式化为ext4类型(文件类型 ...