centos 7--LNMP环境部署

系统环境:centos 7.3

软件环境:mysql 5.6.12 采用二进制免编译安装包

php 7.17 增加扩展模块phalcon

nginx 1.12.1 增加扩展模块 nginx_http_concat_module

# 安装依赖包

yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel libmcrypt libmcrypt-devel libaio

#============== ========安装MYSQL 5.6.12==========================

#下载MYSQL 5.6.12

cd /usr/local/src

wget https://cdn.mysql.com//archives/mysql-5.6/mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz

#解压MYSQL

tar -zxvf /usr/local/src/mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz -C /usr/local

#添加mysql用户,不允许登陆系统

useradd -s /sbin/nologin mysql

#更改mysql文件名

cd /usr/local

mv mysql-5.6.12-linux-glibc2.5-x86_64 mysql

#创建mysql数据库目录

mkdir -pv /data/mysql

chown -R mysql.mysql /data/mysql

#初始化MYSQL

cd /usr/local/mysql

./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

#创建MYSQL 主配置文件

mv /etc/my.cnf /etc/my.cnf.bak

cat > /etc/my.cnf <<EOF

[mysql]

default-character-set=utf8

socket=/tmp/mysql.sock

[mysqld]

skip-name-resolve

port = 3306

socket=/tmp/mysql.sock

basedir=/usr/local/mysql

datadir=/data/mysql

max_connections=200

character-set-server=utf8

default-storage-engine=INNODB

lower_case_table_names=1

max_allowed_packet=16M

EOF

#更改启动脚本,并添加到开机启动

cp support-files/mysql.server /etc/init.d/mysqld

chmod 755 /etc/init.d/mysqld

/etc/init.d/mysqld start

chkconfig --add mysqld

chkconfig mysqld on

netstat -tulnp |grep mysql   //查看是否监听3306端口

#====================安装php 7.17==============================

#下载PHP 7.1.7

cd /usr/local/src

wget http://cn2.php.net/distributions/php-7.1.7.tar.gz

#解压PHP:

tar -zxvf php-7.1.7.tar.gz

#添加php-fpm 用户,不允许登陆系统

useradd -s /sbin/nologin php-fpm

#进入PHP解压目录,配置编译参数:

cd /usr/local/src/php-7.1.7

./configure ‘--prefix=/usr/local/php‘ ‘--with-config-file-path=/usr/local/php/etc‘ ‘--with-config-file-scan-dir=/usr/local/php/etc/conf.d‘ ‘--enable-fpm‘ ‘--with-fpm-user=php-fpm‘ ‘--with-fpm-group=php-fpm‘ ‘--enable-soap‘ ‘--with-openssl‘ ‘--with-openssl-dir‘ ‘--with-mcrypt‘ ‘--with-pcre-regex‘ ‘--with-zlib‘ ‘--with-iconv‘ ‘--with-bz2‘ ‘--enable-calendar‘ ‘--with-curl‘ ‘--with-cdb‘ ‘--enable-dom‘ ‘--enable-exif‘ ‘--with-pcre-dir‘ ‘--enable-ftp‘ ‘--with-gd‘ ‘--with-jpeg-dir‘ ‘--with-png-dir‘ ‘--with-freetype-dir‘ ‘--with-gettext‘ ‘--with-gmp‘ ‘--with-mhash‘ ‘--enable-mbstring‘ ‘--with-libmbfl‘ ‘--with-onig‘ ‘--enable-pdo‘ ‘--with-pdo-mysql=mysqlnd‘ ‘--with-zlib-dir‘ ‘--with-readline‘ ‘--enable-session‘ ‘--enable-shmop‘ ‘--enable-simplexml‘ ‘--enable-sockets‘ ‘--enable-sysvmsg‘ ‘--enable-sysvsem‘ ‘--enable-sysvshm‘ ‘--enable-wddx‘ ‘--with-libxml-dir‘ ‘--with-xsl‘ ‘--enable-zip‘ ‘--enable-mysqlnd‘ ‘--with-mysql-sock=/tmp/mysql.sock‘ ‘--with-mysqli=/usr/local/mysql/bin/mysql_config‘ ‘--without-pear‘

#编译及安装

make && make install

#复制Php 主配置:

cp 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

#创建php-fpm 主配置文件:

sed -i ‘1,$s#;pid = run/php-fpm.pid#pid = /usr/local/php/var/run/php-fpm.pid#g‘ /usr/local/php/etc/php-fpm.conf

sed -i ‘1,$s#;error_log = log/php-fpm.log#error_log = /usr/local/php/var/log/php-fpm.log#g‘ /usr/local/php/etc/php-fpm.conf

echo "include=/usr/local/php/etc/php-fpm.d/*.conf" >> /usr/local/php/etc/php-fpm.conf

cat <<EOF > /usr/local/php/etc/php-fpm.d/www.conf

[global]

pid = /usr/local/php/var/run/php-fpm.pid

error_log = /usr/local/php/var/log/php-fpm.log

[www]

listen = 127.0.0.1:9000

user = php-fpm

group = php-fpm

listen.owner = nginx

listen.group = nginx

pm = dynamic

pm.max_children = 50

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

pm.max_requests = 500

rlimit_files = 1024

EOF

#测试php-fpm 配置:

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

#centos 7 systemctl启动php-fpm

cp /usr/local/src/php-7.1.7/sapi/fpm/php-fpm.service /usr/lib/systemd/system/

systemctl enable php-fpm.service

systemctl start php-fpm.service

#关闭php 版本信息:

sed -i ‘s/expose_php = On/expose_php = Off/g‘ /usr/local/php/etc/php.ini

#下载phalcon模块

cd /usr/local/src

git clone https://github.com/dreamsxin/cphalcon7.git

cd cphalcon7/ext

#准备环境,配置编译参数

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config >> $LOG_INS 2>&1

#编译及安装

make && make install

#修改php.ini,增加扩展模块

mkdir /usr/local/php/etc/conf.d

echo "extension = phalcon.so" >> /usr/local/php/etc/conf.d/phalcon.ini

#重新加载配置

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

systemctl restart php-fpm.service

#===================安装nginx 1.12.1 ==============================

#下载

cd /usr/local/src && wget http://nginx.org/download/nginx-1.12.1.tar.gz && git clone git://github.com/alibaba/nginx-http-concat.git

#解压:

tar zxf nginx-1.12.1.tar.gz

#创建nginx运行用户

useradd -s /sbin/nologin nginx

#进入解压目录,配置编译参数:

cd ./nginx-1.12.1 && ./configure --prefix=/usr/local/nginx --with-http_realip_module  --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre --add-module=/usr/local/src/nginx-http-concat

#编译及安装

make && make install

#设置软链接

ln -s /usr/local/lib/libmaxminddb.so.0 /usr/lib64

ln -s /usr/local/lib/libprofiler.so.0 /usr/lib64

ln -s /usr/local/lib/libunwind.so.8 /usr/lib64

#检测初始化完成的nginx 配置是否有问题

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

#centos 7创建nginx启动脚本

cat <<EOF > /usr/lib/systemd/system/nginx.service

[Unit]

Description=nginx

Documentation=http://nginx.org/en/docs/

After=network-online.target remote-fs.target nss-lookup.target

Wants=network-online.target

[Service]

Type=forking

PIDFile=/usr/local/nginx/logs/nginx.pid

ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s TERM $MAINPID

[Install]

WantedBy=multi-user.target

EOF

#将nginx加入到开机启动

systemctl enable nginx.service

#备份nginx主配置文件

cp /usr/local/nginx/conf/nginx.conf{,.bak}

#重新nginx 配置:

cat << EOF > /usr/local/nginx/conf/nginx.conf

user nginx nginx;

error_log /var/log/nginx_error.log crit;

pid /usr/local/nginx/logs/nginx.pid;

worker_processes  auto;

worker_rlimit_nofile 65535;

events {

use epoll;

worker_connections  65535;

}

http {

include      mime.types;

default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;

server_tokens off;

charset utf-8;

tcp_nopush on;

tcp_nodelay on;

gzip on;

gzip_min_length 100;

gzip_buffers 4 16k;

gzip_http_version 1.0;

gzip_comp_level 6;

gzip_types text/plain application/x-javascript text/css application/xml;

gzip_vary on;

server {

listen      80;

server_name  localhost;

location / {

root  html;

index  index.html index.htm index.php;

}

error_page  500 502 503 504  /50x.html;

location = /50x.html {

root  html;

}

location ~ \.php\$ {

root          html;

fastcgi_pass  127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

include        fastcgi_params;

}

}

}

EOF

#创建PHP测试文件:

echo "<?php  echo phpinfo();  ?>" >/usr/local/nginx/html/index.php

#备份index.html:

mv /usr/local/nginx/html/index.html{,.bak}

#启动nginx:

#service nginx start

systemctl start nginx.service

#清空防火墙配置

iptables -F

#设置nginx、mysql 及php 的环境变量:

echo "PATH=$PATH:/usr/local/php/bin:/usr/local/nginx/sbin:/usr/local/mysql/bin:/usr/local/php/sbin" >> /etc/profile

#刷新环境变量配置,使其立即生效:

source /etc/profile

浏览器访问ip,会出现php的相关信息。

时间: 2024-11-02 14:34:35

centos 7--LNMP环境部署的相关文章

LNMP环境部署及zabbix服务器端安装

一.LNMP环境部署 1.配置epel源 建议在系统安装完成之后就配置epel源,方便一些软件包的安装: wget http://mirrors.ustc.edu.cn/centos/6/extras/x86_64/Packages/epel-release-6-8.noarch.rpmrpm -ivhepel-release-6-8.noarch.rpm 2.nginx安装 (1)安装支持软件 Nginx.mysql.php的配置及运行需要pcre.zlib.openssl等软件包的支持,因此

Centos7.X LNMP环境部署(非源码)

1.下载新的CentOS-Base.repo #wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 2.安装Nginx YUM源中没有Nginx,我们需要增加一个nginx的源nginx.repo vi /etc/yum.repos.d/nginx.repo [nginx]name=nginx repobaseurl=http://nginx.org/packages/cen

CentOS安装LNMP环境的基础组件

注:以下所有操作均在CentOS 6.5 x86_64位系统下完成. 在安装LNMP环境之前,请确保已经使用yum安装了以下各类基础组件(如果系统已自带,还可以考虑yum update下基础组件): gcc cmake openssl+openssl-devel pcre+pcre-devel bzip2+bzip2-devel libcurl+curl+curl-devel libjpeg+libjpeg-devel libpng+libpng-devel freetype+freetype-

centos配置lnmp环境详解及相关问题

安装系统,配置环境 第一步:进入系统 用工具putty进入centos系统,输入账号密码. 第二步:远程终端端口 screen -S lnmp 如果提示screen: command not found,需要安装screen yum install screen 第三步:安装LNMP环境 安装过程中可以选择相应的设置,默认也可以! 1.2版本 wget -c http://soft.vpser.net/lnmp/lnmp1.2-full.tar.gz && tar zxf lnmp1.2-

阿里云(ECS)Centos服务器LNMP环境搭建

阿里云( ECS ) Centos7 服务器 LNMP 环境搭建 前言 第一次接触阿里云是大四的时候,当时在校外公司做兼职,关于智能家居项目的,话说当时俺就只有一个月左右的 php 后台开发经验(还是因为无意中选修了一门电子商务的课程,要做课程设计逼迫出来的),因为公司没人接触过后台开发,所以我这个菜鸟就硬着头皮上了.刚开始入门我把精力放在公司业务功能实现上,所用的服务器环境是别人已经配置好的,就是把代码在本地写好,通过 ftp 上传到服务器目录,是用 postman 插件测试一下接口就行了,开

Centos安装lnmp环境

1:查看环境: [[email protected] html]# cat /etc/redhat-release CentOS release 6.5 (Final) 2:关掉防火墙 [[email protected] html]# chkconfig iptables off 3:配置CentOS 6.0 第三方yum源(CentOS默认的标准源里没有nginx软件包) #wget http://www.atomicorp.com/installers/atomic #sh ./atomi

centos 7 JDK 环境部署

1.1  系统环境: [[email protected] tools]# cat/etc/redhat-release CentOS Linux release 7.0.1406 (Core) [[email protected] tools]# uname -r 3.10.0-123.el7.x86_64 [[email protected] tools]# uname -n nginx-daili [[email protected] tools]# uname -m x86_64 1.2

阿里云Centos配置LNMP环境

CentOS基本配置 1.连接服务器 拿到服务器的ip.初始密码以后.我们先要用远程连接工具putty连接服务器主机. 启动putty.exe程序,进入putty主界面,在Host Name 栏中输入你的服务器ip地址,Saved Sessions 填入你的主机名称(可自定义,用于区别你的服务器).点击Save保存配置.选中你的服务器名点击open开始连接服务器. 第一次连接,会出现对话框,点击是 出现登录界面,输入用户名,默认为超级用户root,接着输入密码,要注意的是密码不会显示在屏幕上.输

LNMP环境部署

1 安装nginx 1.1 安装nginx相关包 yum install -y http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm yum install -y nginx 1.2 创建项目目录 mkdir -p /var/www/www.cmdschool.org 1.3 配置http和https服务 http config: cp /etc/nginx/conf.

centos 7 lnmp环境编译安装zabbix-3.4.14

一.安装环境(zabbix3.0需要php在5.5版本以上) [[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) [[email protected] ~]# netstat -lntup|egrep 'nginx|mysql' tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1268/nginx: master tcp 0 0 0.0.0.0:443 0.