码迷,mamicode.com
首页 > 其他好文 > 详细

centos 7--LNMP环境部署

时间:2017-07-31 14:41:00      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:lnmp nginx php mysql phalcon nginx_http_concat

系统环境: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的相关信息。


centos 7--LNMP环境部署

标签:lnmp nginx php mysql phalcon nginx_http_concat

原文地址:http://jinlong.blog.51cto.com/3276088/1952256

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!