当前位置:首页 > 系统 > CentOS7 搭建LNMP

CentOS7 搭建LNMP

系统6年前 (2018-01-07)

CentOS7 搭建LNMP

使用CentOS 1708,其实就是RHEL 7.4,使用YUM搭建LNMP环境(Linux、Nginx、MariaDB、PHP),全部使用新版组件,比如Nginx 1.12.2、MariaDB 10.2,PHP 7.1,并运行wordpress


环境配置

关闭selinux
vi /etc/sysconfig/selinux
SELINUX=disabled
SELINUXTYPE=disabled
执行setenforce 0

关闭防火墙
systemctl stop firewalld
systemctl disable firewalld

添加epel附加源
yum install epel-release
yum update

安装常用组件
yum install zip unzip wget net-tools gcc automake autoconf libtool make gcc-c++ libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel libidn libidn-devel openssl openssl-devel


安装Nginx

vi /etc/yum.repos.d/nginx.repo    
添加
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

yum install nginx   #安装nginx

systemctl start nginx   开启nginx服务
systemctl enable nginx   设置HTTP自启

测试

CentOS7 搭建LNMP



安装MariaDB 

vi /etc/yum.repos.d/mariadb.repo
添加
[mariadb]
name=MariaDB
baseurl=http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

yum install MariaDB-server MariaDB-client   #安装mariadb

systemctl start mariadb.service   开启mariadb服务
systemctl enable mariadb.service   设置DB自启

配置数据库

mysql_secure_installation
Enter current password for root (enter for none):  回车
Set root password? [Y/n] y
New password:123456
Re-enter new password:123456
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

mysql -u root -p
create database wp;     创建数据库
grant all on wp.* to 'wp' identified by 'vmos';    用户名为wp,密码为vmos
flush privileges;    刷新权限
quit


安装PHP

安装webtatic源 
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装PHP7.x
yum install php71w-common php71w-fpm php71w-gd php71w-opcache php71w-pecl-imagick php71w-gd php71w-process php71w-mysqlnd php71w-mcrypt php71w-intl php71w-imap php71w-odbc php71w-mbstring php71w-recode php71w-soap php71w-pdo php71w-pecl-redis php71w-pear php71w-pecl-memcached php71w-devel php71w-xml php71w-xmlrpc

systemctl start php-fpm   开启fpm服务
systemctl enable php-fpm   设置fpm自启

测试

CentOS7 搭建LNMP

配置php

vi /etc/php.ini 
date.timezone = PRC

配置fpm (Nginx服务器只会响应静态请求,所以需要配合php-fpm来解析php网页的动态请求)

vi /etc/php-fpm.d/www.conf
 修改
 user = nginx
 group = nginx

配置nginx

vi /etc/nginx/nginx.conf在最后一行看到include /etc/nginx/conf.d/*.conf;
然后
vi /etc/nginx/conf.d/default.conf
在location的index中添加
index.php
再下面添加
location ~ \.php$ {
           root /usr/share/nginx/html; 
           fastcgi_pass 127.0.0.1:9000;
           fastcgi_index index.php;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           include fastcgi_params;
    }

CentOS7 搭建LNMP

测试

CentOS7 搭建LNMP


CentOS7 搭建LNMP

增加测试页

vi /usr/share/nginx/html/info.php
添加
<?php    
phpinfo();    
?>

 重启服务

systemctl restart php-fpm
systemctl restart nginx

测试

CentOS7 搭建LNMP


安装WordPress

rm -rf /usr/share/nginx/html/index.html   #移除默认nginx首页
cd /root/ && wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
mv wordpress/* /usr/share/nginx/html/   #复制到webroot路径
chown -R nginx:nginx /usr/share/nginx/html/  #设置帐户在webroot路径权限
chmod -R 755 /usr/share/nginx/html/   #设置webroot路径权限

CentOS7 搭建LNMP


安装phpMyAdmin

wget  https://files.phpmyadmin.net/phpMyAdmin/4.7.7/phpMyAdmin-4.7.7-all-languages.zip
unzip phpMyAdmin-4.7.7-all-languages.zip   
mkdir /usr/share/nginx/html/phpmyadmin   #webroot创建phpmyadmin路径
mv phpMyAdmin-4.7.7-all-languages/* /usr/share/nginx/html/phpmyadmin/   #将解压好的文件拷贝到webroot路径

配置phpmyadmin

cd /usr/share/nginx/html/phpmyadmin/
cp config.sample.inc.php config.inc.php
vi config.inc.php
 修改
$cfg['blowfish_secret'] = ‘vm0SteCH,c0M@VMoSTECh.cN@vM0sTecH’;
vi /etc/php.ini 
 修改
session.save_path = "/var/lib/php/session/"
mkdir /var/lib/php/session
chmod -R 777 /var/lib/php/session

CentOS7 搭建LNMP

测试 

CentOS7 搭建LNMP

输入MariaDB 用户名root 密码123456登录即可



本站所有文章均可随意转载,转载时请保留原文链接及作者。

本文链接:https://www.vos.cn/os/183.html

相关文章

修复升级EVE-NG后无法正常打开问题

修复升级EVE-NG后无法正常打开问题

升级流程Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.9.40-eve-ng-ukms+ x86_64) * Documentation:  ...

Redhat 6.5网卡聚合绑定

Redhat 6.5网卡聚合绑定

linux下网卡bonding配置是通过多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡,在生产场景中是一种常用的技术,常用聚合模式为0,1,60(balance-rr)轮循(RR)...

解决/bin/bash^M: bad interpreter: No such file or directory

解决/bin/bash^M: bad interpreter: No such file or directory

运行windows下自编的脚本,提示因为windows下编写的脚本每行结尾以\r\n来标识,而unix格式的文件行尾则以\n来标识。dos格式的文件行尾为^M$,unix格式的文件行尾为$,可从显示结...

centos7.5 [root@bogon ~]

centos7.5 [root@bogon ~]

虚拟机中的centos7.5,开机后发现主机名由[root@localhost ~]#变成了[root@bogon ~]# hostname lemp su暂时是修改为正确的主机...

firewalld开启常用端口

firewalld开启常用端口

新版都默认为firewalld代替了iptables,命令也不一样安装yum install firewalld -y yum install fi...

CentOS7 fail2ban+firewalld

CentOS7 fail2ban+firewalld

在CentOS7.5中使用fail2ban+firewalld方式,防御nginx、wordpress和ssh防止爆破攻击安装fail2banyum install epel-re...