阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 7配置LNMP开发环境及配置文件管理

125次阅读
没有评论

共计 3194 个字符,预计需要花费 8 分钟才能阅读完成。

安装并配置 MySQL 5.6

从 CentOS 从 7.x 开始默认使用 MariaDB。MariaDB 完全兼容 MySQL,包括 API 和命令行。但是很多时候我们还是会想要安装 MySQL,所以不能直接通过 yum 命令安装。

下载源安装文件

wget http://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm

本地安装 rpm 包(配置 MySQL 安装源)

yum -y localinstall mysql57-community-release-el7-8.noarch.rpm

查看所有 MySQL 安装源(默认 MySQL 安装版本 5.7)

yum repolist all | grep mysql

关闭 MySQL 5.7 安装源

sudo yum-config-manager --disable mysql57-community

开启 MySQL 5.6 安装源

sudo yum-config-manager --enable mysql56-community

没有 yum-config-manager 命令可以安装 yum install yum-utils.noarch 工具
或者编辑 /etc/yum.repos.d/mysql-community.repo 文件 enable 项为 1 表示开启,为 0 表示关闭

安装 MySQL

yum -y install mysql-devel mysql-community-server

启动 MySQL

systemctl start mysqld.service

安全配置 MySQL

mysql_secure_installation

安装并配置 PHP 5.6

CentOS 7.1 版本中,默认安装 PHP 为 PHP5.4 版本,其中 php-mysqlnd 是 PHP 源码提供的 MYSQL 驱动数据库。

很多时候会对 PHP 环境要求校新的版本,例如 PHP5.6 环境,记录一种通过 yum 工具安装最新 PHP 版本的方法。首先,需要在系统上安装一个扩展 yum 源,即 epel 源。可从 http://Fedoraproject.org/wiki/EPEL 网站下载并安装。(注意:如果文章时间久,就可能需要去重新找新的下载链接。)

下载源安装文件

wget https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm

本地安装(和上面 MySQL 安装源命令类似)

rpm -ivh epel-release-7-8.noarch.rpm

接着,还需要一个 REMI 源,这个 yum 源提供了最新的 PHP 版本的下载和安装,它的官网http://rpms.famillecollet.com/。安装 REMI 源的过程如下。

导入 gpg 校验文件

rpm --import http://rpms.remirepo.net/RPM-GPG-KEY-remi

下载源安装文件

wget https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm

本地安装

rpm -Uvh remi-release-7.rpm

默认情况下,REMI 是禁用的,防止多个 yum 源发生冲突。可以通过命令查看 REMI 源是否成功安装

yum repolist disabled | grep remi

通过 REMI 源安装需要的 PHP 版本,安装 PHP5.6 版本。

yum --enablerepo=remi-php56 install php

安装 php-fpm

yum --enablerepo=remi-php56 install php-fpm

开启 php-fpm

systemctl start php-fpm

安装并配置 Nginx

导入 gpg 校验文件

rpm --import http://rpms.remirepo.net/RPM-GPG-KEY-remi

下载源安装文件(配置 Nginx 安装源)。可从 http://nginx.org/packages/centos/ 网站下载安装源。(注意:如果文章时间久,就可能需要去重新找新的下载链接。)

wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.10.0-1.el7.ngx.x86_64.rpm

本地安装

rpm -Uvh nginx-1.10.0-1.el7.ngx.x86_64.rpm

安装 Nginx

yum install nginx

开启 Nginx

systemctl start nginx

Nginx 主机配置(设置 php-fpm)

编辑 /etc/nginx/conf.d/default.conf 配置文件,并重启。

server {listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    root   /usr/share/nginx/html;
    index  index.html index.htm index.php;

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

 

LNMP 环境搭建(Discuz 论坛)  http://www.linuxidc.com/Linux/2016-03/129334.htm

 

Ubuntu 14.04 下 apt-get 方法安装 LNMP 环境  http://www.linuxidc.com/Linux/2016-07/133683.htm

 

CentOS 7 源码编译安装 PHP5.6 和 Nginx1.7.9 及 MySQL(搭建 LNMP 环境) http://www.linuxidc.com/Linux/2015-12/126200.htm

 

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL  http://www.linuxidc.com/Linux/2014-05/102351.htm

 

CentOS 7 源码安装最新版 LNMP 环境 http://www.linuxidc.com/Linux/2015-04/116058.htm

 

Ubuntu 16.04 下源码配置 LNMP 开发环境 http://www.linuxidc.com/Linux/2016-09/135381.htm

 

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-01/139356.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计3194字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中