CentOS 7配置LNMP开发环境及配置文件管理详解
安装并配置MySQL5.6
从CentOS从7.x开始默认使用MariaDB。MariaDB完全兼容MySQL,包括API和命令行。但是很多时候我们还是会想要安装MySQL,所以不能直接通过yum命令安装。
下载源安装文件
wgethttp://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm
本地安装rpm包(配置MySQL安装源)
yum-ylocalinstallmysql57-community-release-el7-8.noarch.rpm
查看所有MySQL安装源(默认MySQL安装版本5.7)
yumrepolistall|grepmysql
关闭MySQL5.7安装源
sudoyum-config-manager--disablemysql57-community
开启MySQL5.6安装源
sudoyum-config-manager--enablemysql56-community
没有yum-config-manager命令可以安装yuminstallyum-utils.noarch工具 或者编辑/etc/yum.repos.d/mysql-community.repo文件enable项为1表示开启,为0表示关闭
安装MySQL
yum-yinstallmysql-develmysql-community-server
启动MySQL
systemctlstartmysqld.service
安全配置MySQL
mysql_secure_installation
安装并配置PHP5.6
CentOS7.1版本中,默认安装PHP为PHP5.4版本,其中php-mysqlnd是PHP源码提供的MYSQL驱动数据库。
很多时候会对PHP环境要求校新的版本,例如PHP5.6环境,记录一种通过yum工具安装最新PHP版本的方法。首先,需要在系统上安装一个扩展yum源,即epel源。可从http://fedoraproject.org/wiki/EPEL网站下载并安装。(注意:如果文章时间久,就可能需要去重新找新的下载链接。)
下载源安装文件
wgethttps://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
本地安装(和上面MySQL安装源命令类似)
rpm-ivhepel-release-7-8.noarch.rpm
接着,还需要一个REMI源,这个yum源提供了最新的PHP版本的下载和安装,它的官网http://rpms.famillecollet.com/。安装REMI源的过程如下。
导入gpg校验文件
rpm--importhttp://rpms.remirepo.net/RPM-GPG-KEY-remi
下载源安装文件
wgethttps://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
本地安装
rpm-Uvhremi-release-7.rpm
默认情况下,REMI是禁用的,防止多个yum源发生冲突。可以通过命令查看REMI源是否成功安装
yumrepolistdisabled|grepremi
通过REMI源安装需要的PHP版本,安装PHP5.6版本。
yum--enablerepo=remi-php56installphp
安装php-fpm
yum--enablerepo=remi-php56installphp-fpm
开启php-fpm
systemctlstartphp-fpm
安装并配置Nginx
导入gpg校验文件
rpm--importhttp://rpms.remirepo.net/RPM-GPG-KEY-remi
下载源安装文件(配置Nginx安装源)。可从http://nginx.org/packages/centos/网站下载安装源。(注意:如果文章时间久,就可能需要去重新找新的下载链接。)
wgethttp://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.10.0-1.el7.ngx.x86_64.rpm
本地安装
rpm-Uvhnginx-1.10.0-1.el7.ngx.x86_64.rpm
安装Nginx
yuminstallnginx
开启Nginx
systemctlstartnginx
Nginx主机配置(设置php-fpm)
编辑/etc/nginx/conf.d/default.conf配置文件,并重启。
server{
listen80;
server_namelocalhost;
#charsetkoi8-r;
#access_log/var/log/nginx/log/host.access.logmain;
root/usr/share/nginx/html;
indexindex.htmlindex.htmindex.php;
#error_page404/404.html;
#redirectservererrorpagestothestaticpage/50x.html
#
error_page500502503504/50x.html;
location=/50x.html{
root/usr/share/nginx/html;
}
#proxythePHPscriptstoApachelisteningon127.0.0.1:80
#
#location~\.php${
#proxy_passhttp://127.0.0.1;
#}
#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
#
location~\.php${
roothtml;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME/usr/share/nginx/html$fastcgi_script_name;
includefastcgi_params;
}
#denyaccessto.htaccessfiles,ifApache'sdocumentroot
#concurswithnginx'sone
#
#location~/\.ht{
#denyall;
#}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。