资讯专栏INFORMATION COLUMN

Centos7.5编译安装搭建LNMP环境

yeooo / 2476人阅读

摘要:查看版本启动配置支持把行注释去掉,可能会存在偏差自己看下然后修改,然后修改为重启生效然后测试是否成功如果有开启防火墙记得开放端口查看状态或者重启防火墙开启端口

环境介绍

[root@instance-9a809cx7 ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core) 
[root@instance-9a809cx7 ~]# 

一、Nginx安装
1、检查是否安装wget,如果没有安装就使用yum安装

[root@instance-9a809cx7 ~]# rpm -qa wget
wget-1.14-15.el7_4.1.x86_64
[root@instance-9a809cx7 ~]# 

2、安装编译器

yum install gcc gcc-c++

3、安装nginx依赖的软件
nginx中的rewrite module、gzip module、Http SSL module需要安装PCRE、zlib、OpenSSL,这里编译安装也可以使用yum安装,命令如下,这里用的是编译安装

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

3.1、zlib源码安装
解压、编译安装

[root@instance-9a809cx7 src]# wget http://prdownloads.sourceforge.net/libpng/zlib-1.2.11.tar.gz
[root@instance-9a809cx7 src]# tar zxvf zlib-1.2.11.tar.gz
[root@instance-9a809cx7 src]# cd zlib-1.2.11
[root@instance-9a809cx7 zlib-1.2.11]# ./configure
[root@instance-9a809cx7 zlib-1.2.11]# make && make install

3.2、pcre安装
Pcre官网
下载最新版本8.42
解压、编译安装

[root@instance-9a809cx7 src]# wget  https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz
[root@instance-9a809cx7 src]# tar zxvf pcre-8.42.tar.gz 
[root@instance-9a809cx7 src]# cd pcre-8.42/
[root@instance-9a809cx7 pcre-8.42]# ./configure 
[root@instance-9a809cx7 pcre-8.42]# make && make install
[root@instance-9a809cx7 pcre-8.42]# 

查看版本

[root@instance-9a809cx7 pcre-8.42]# pcre-config --version
8.42
[root@instance-9a809cx7 pcre-8.42]# 

3.3、OpenSSL安装
OpenSSL官网
下载并解压、安装

[root@instance-9a809cx7 src]# wget https://www.openssl.org/source/openssl-1.0.2o.tar.gz^C
[root@instance-9a809cx7 src]# tar zxvf openssl-1.0.2o.tar.gz 
[root@instance-9a809cx7 src]# cd openssl-1.0.2o/
[root@instance-9a809cx7 src]# cd openssl-1.0.2o/
[root@instance-9a809cx7 openssl-1.0.2o]# ./config 
[root@instance-9a809cx7 openssl-1.0.2o]# make && make install

4、Nginx安装(最新稳定版为1.14.0)
官网

[root@instance-9a809cx7 src]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
[root@instance-9a809cx7 src]# tar zxvf nginx-1.14.0.tar.gz 
[root@instance-9a809cx7 src]# cd nginx-1.14.0/
[root@instance-9a809cx7 nginx-1.14.0]# ./configure --with-http_ssl_module --with-pcre=../pcre-8.42 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.2o
[root@instance-9a809cx7 nginx-1.14.0]# make && make install

检查Nginx的正确性:

[root@instance-9a809cx7 nginx-1.14.0]# /usr/local/nginx/sbin/nginx -t 
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@instance-9a809cx7 nginx-1.14.0]# 

启动Nginx:

[root@instance-9a809cx7nginx-1.14.0]# /usr/local/nginx/sbin/nginx

停止Nginx

/usr/local/nginx/sbin/nginx -s stop 

开机自启动

[root@instance-9a809cx7 nginx-1.14.0]# chmod 755 /etc/rc.d/rc.local
[root@instance-9a809cx7 nginx-1.14.0]# vim /etc/rc.d/rc.local
[root@instance-9a809cx7 nginx-1.14.0]# 

二、MySQL安装
1、检查是否安装mariadb如安装则卸载

[root@instance-9a809cx7 src]# yum list installed | grep mariadb 
mariadb-libs.x86_64                  1:5.5.56-2.el7                    @anaconda
[root@instance-9a809cx7 src]# yum -y remove mariadb*

2、安装Mysql
下载

[root@instance-9a809cx7 src]# wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm

检查MySQL yum源是否安装成功

[root@instance-9a809cx7 src]# yum repolist enabled | grep "mysql.*-community.*" 
!mysql-connectors-community/x86_64 MySQL Connectors Community                 74
!mysql-tools-community/x86_64      MySQL Tools Community                      74
!mysql80-community/x86_64          MySQL 8.0 Community Server                 49

安装

[root@instance-9a809cx7 src]# yum -y  install mysql-server
[root@instance-9a809cx7 src]# 

启动MySQL

[root@instance-9a809cx7 src]# service mysqld start 
Redirecting to /bin/systemctl start mysqld.service

查看初始密码然后登录
root@localhost: uXg%-ip2**[密码]

[root@instance-9a809cx7 src]# cat /var/log/mysqld.log|grep "A temporary password"
2018-11-12T10:17:55.906846Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: uXg%-ip2***
[root@instance-9a809cx7 src]# mysql -uroot -p

密码可以自行修改
命令如下

mysql> alter user "root"@"localhost" identified by "youpassword"; 
mysql> flush privileges;
mysql> alter user "root"@"localhost" identified by "qA123,./";
Query OK, 0 rows affected (0.10 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

重启

systemctl restart mysqld.service

其它命令

systemctl start mysqld      #启动
systemctl stop mysqld       #停止
systemctl restart mysqld    #重启
systemctl enable mysqld     #设置开机启动
systemctl status mysqld     #查看状态

三、PHP安装
由于yum 直接安装版本是5.4,所以我们要动更新rpm

[root@instance-9a809cx7 src]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm   
[root@instance-9a809cx7 src]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

查看版本5.5~7.2都有

[root@instance-9a809cx7 src]# yum list php*

安装

[root@instance-9a809cx7 src]# yum -y install php72w-gd php72w-imap php72w-ldap php72w-odbc php72w-pear php72w-xml php72w-xmlrpc php72w-mysqlnd php72w-pdo

安装PHP-FPM
要让PHP以FastCGI的方式与nginx进行交互,需要有PHP-FPM模块的支持。

[root@instance-9a809cx7 src]# php72w-fpm.x86_64

查看版本

[root@instance-9a809cx7 src]# php-fpm -v
PHP 7.2.11 (fpm-fcgi) (built: Oct 11 2018 19:18:07)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
[root@instance-9a809cx7 src]# 

启动PHP-FPM

[root@instance-9a809cx7 src]# systemctl start php-fpm

配置Nginx支持PHP
把65~72行注释去掉,可能会存在偏差自己看下然后修改,然后修改/scripts为$document_root

[root@instance-9a809cx7 src]# vi /usr/local/nginx/conf/nginx.conf

重启生效:

[root@instance-9a809cx7 src]# /usr/local/nginx/sbin/nginx -s reload

然后测试是否成功 :

如果有开启防火墙记得开放80端口

systemctl status firewalld   #查看状态或者netstat -nltp
firewall-cmd --reload    #重启防火墙
firewall-cmd --zone=public --add-port=80/tcp --permanent #开启80端口

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/40189.html

相关文章

  • Centos7.5编译安装搭建LNMP环境

    摘要:查看版本启动配置支持把行注释去掉,可能会存在偏差自己看下然后修改,然后修改为重启生效然后测试是否成功如果有开启防火墙记得开放端口查看状态或者重启防火墙开启端口 环境介绍 [root@instance-9a809cx7 ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@instance-9a80...

    baishancloud 评论0 收藏0
  • Centos7.5编译安装搭建LNMP环境

    摘要:查看版本启动配置支持把行注释去掉,可能会存在偏差自己看下然后修改,然后修改为重启生效然后测试是否成功如果有开启防火墙记得开放端口查看状态或者重启防火墙开启端口 环境介绍 [root@instance-9a809cx7 ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@instance-9a80...

    wapeyang 评论0 收藏0
  • 不止LNMP的后端开发环境搭建

    摘要:前言本次目标是在新安装在虚拟机中的系统中安装一系列后端开发通常用到的程序服务这里不介绍的安装并以为例子部署一个网站开机启动重要提示如果觉得一个个安装和配置太麻烦那推荐使用宝塔可视化管理工具进行操作基本实现一键操作极大提高效率简言之一个字爽当 前言 本次目标是在新安装在虚拟机中的CentOS7.5系统中安装一系列后端开发通常用到的程序服务(这里不介绍CentOS的安装),并以phpMyA...

    StonePanda 评论0 收藏0
  • 不止LNMP的后端开发环境搭建

    摘要:前言本次目标是在新安装在虚拟机中的系统中安装一系列后端开发通常用到的程序服务这里不介绍的安装并以为例子部署一个网站开机启动重要提示如果觉得一个个安装和配置太麻烦那推荐使用宝塔可视化管理工具进行操作基本实现一键操作极大提高效率简言之一个字爽当 前言 本次目标是在新安装在虚拟机中的CentOS7.5系统中安装一系列后端开发通常用到的程序服务(这里不介绍CentOS的安装),并以phpMyA...

    ddongjian0000 评论0 收藏0
  • 不止LNMP的后端开发环境搭建

    摘要:前言本次目标是在新安装在虚拟机中的系统中安装一系列后端开发通常用到的程序服务这里不介绍的安装并以为例子部署一个网站开机启动重要提示如果觉得一个个安装和配置太麻烦那推荐使用宝塔可视化管理工具进行操作基本实现一键操作极大提高效率简言之一个字爽当 前言 本次目标是在新安装在虚拟机中的CentOS7.5系统中安装一系列后端开发通常用到的程序服务(这里不介绍CentOS的安装),并以phpMyA...

    stefan 评论0 收藏0

发表评论

0条评论

yeooo

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<