前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CentOS7安装部署LNMP环境

CentOS7安装部署LNMP环境

作者头像
DevOps云学堂
发布2019-10-18 18:49:14
7020
发布2019-10-18 18:49:14
举报
文章被收录于专栏:DevOps持续集成DevOps持续集成

1.安装部署Nginx

安装前准备

yum -y install pcre-devel  zlib-devel  openssl openssl-devel

添加nginx用户

useradd -s /sbin/nologin  nginx -M

编译安装nginx

tar zxf nginx-$NVERSION.tar.gz -C /usr/src/
./configure
--user=nginx --group=nginx --prefix=/usr/local/nginx  
--with-http_stub_status_module --with-http_ssl_module  
make -j 4
make install

配置nginx

cp/usr/local/nginx/conf/nginx.conf/usr/local/nginx/conf/nginx.conf.default
ln -s /usr/local/nginx/sbin/nginx /usr/sbin

配置nginx支持php

user  nginx;
worker_processes  8;

events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
sendfile        on;
keepalive_timeout  65;
server {
        listen       80;
        server_name  localhost;

     location / {
            root   html;
            index  index.html index.htm;
        }

     location ~ \.(php|php5)?$ {
            root           /usr/local/nginx/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
    #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
     fastcgi_paramSCRIPT_FILENAME/usr/local/nginx/html$fastcgi_script_name;                        
            include    fastcgi_params;
           }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

2.安装部署MySQL

卸载旧版本mysql

rpm -e mysql --nodeps
rpm -e mysql-server --nodeps

安装cmake和ncurses-devel工具

yum -y install cmake ncurses-devel

添加系统用户

useradd -s /sbin/nologin  -M mysql

编译安装MySQL

tar zxf mysql-$MVERSION.tar.gz -C /usr/src/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all
make -j 4
make install

配置

chown -R mysql:mysql /usr/local/mysql/  #设置属主属组
mv /etc/my.cnf /etc/my.cnf.old  #更改原始配置文件
cp  support-files/my-medium.cnf /etc/my.cnf  #生成新的配置文件
/usr/local/mysql/scripts/mysql_install_db  --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
#初始化数据库
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile #设置环境变量
. /etc/profile   #生效配置变量
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld    #生成服务脚本
chmod +x /etc/init.d/mysqld   #添加执行权限
chkconfig --add mysqld

3.安装PHP

准备安装环境

yum -y install zlib-devel libxml2-devel libjpeg-turbo-devel freetype-devel libpng-devel gd-devel libcurl-devel

编译安装php

tar zxf php-$PVERSION.tar.gz -C /usr/src/
./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd  --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --with-gettext --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-static --with-fpm-user=nginx --with-fpm-group=nginx --enable-fpm --enable-ftp --enable-opcache=yes
make -j 4
make install

配置php

cp/usr/src/php-$PVERSION/php.ini-production  /usr/local/php/php.ini
cd /usr/local/php/etc/
cp php-fpm.conf.default  php-fpm.conf

4.启动服务

启动nginx

nginx
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
netstat -anlpt | grep nginx

启动mysql

service mysqld start
chkconfig mysqld on
netstat -anlpt | grep mysqld

启动php-fpm

/usr/local/php/sbin/php-fpm
 netstat -anlpt | grep php-fpm

5.测试LNMP

编辑测试页面

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

访问测试

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 DevOps持续集成 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档