CENTOS7 安装LNMP环境

------仅作为自己学习留存------

CENTOS 7.6/NGINX1.14.0/MYSQL8/PHP7.2

安装编译器

[root@VM-0-16-centos home]# yum install gcc gcc-c++

软件下载路径---自己服务器

/home/lnmp

zlib源码安装

[root@VM-0-16-centos lnmp]# wget http://prdownloads.sourceforge.net/libpng/zlib-1.2.11.tar.gz
[root@VM-0-16-centos lnmp]# tar zxvf zlib-1.2.11.tar.gz
[root@VM-0-16-centos lnmp]# cd zlib-1.2.11
[root@VM-0-16-centos zlib-1.2.11]# ./configure
[root@VM-0-16-centos zlib-1.2.11]# make && make install

pcre安装

[root@VM-0-16-centos lnmp]# wget  https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz
[root@VM-0-16-centos lnmp]# tar zxvf pcre-8.42.tar.gz 
[root@VM-0-16-centos lnmp]# cd pcre-8.42/
[root@VM-0-16-centos pcre-8.42]# ./configure 
[root@VM-0-16-centos pcre-8.42]# make && make install
[root@VM-0-16-centos pcre-8.42]# 

[root@VM-0-16-centos lnmp]# pcre-config --version
8.42

OpenSSL安装

[root@VM-0-16-centos lnmp]#yum groupinstall "Development Tools" 

[root@VM-0-16-centos lnmp]# wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
[root@VM-0-16-centos lnmp]# tar zxvf openssl-1.1.1k.tar.gz 
[root@VM-0-16-centos lnmp]# cd openssl-1.1.1k/
[root@VM-0-16-centos openssl-1.1.1k]# ./config --prefix=/usr/local/openssl --openssldir=/usr/local/ssl
[root@VM-0-16-centos openssl-1.1.1k]# make -j 2
[root@VM-0-16-centos openssl-1.1.1k]# make install

导出库文件

[oot@VM-0-16-centos openssl-1.1.1k]# echo  /usr/local/openssl/lib >> /etc/ld.so.conf.d/openssl.conf
[oot@VM-0-16-centos openssl-1.1.1k]# ldconfig 
# "检测版本信息"
[oot@VM-0-16-centos openssl-1.1.1k]# /usr/local/openssl/bin/openssl  version -a
#导出openssl/bin 到PATH 变量
[root@VM-0-16-centos openssl-1.1.1k]# echo 'PATH=/usr/local/openssl/bin:$PATH' >> /etc/profile.d/env.sh
[root@VM-0-16-centos openssl-1.1.1k]#  source /etc/profile.d/env.sh
[root@VM-0-16-centos openssl-1.1.1k]# openssl version
OpenSSL 1.1.1k  25 Mar 2021

Nginx安装

[root@VM-0-16-centos lnmp]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
[root@VM-0-16-centos lnmp]# tar zxvf nginx-1.14.0.tar.gz 
[root@VM-0-16-centos lnmp]# cd nginx-1.14.0/
[root@VM-0-16-centos nginx-1.14.0]# ./configure --with-http_ssl_module --with-pcre=../pcre-8.42 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.1.1k
[root@VM-0-16-centos nginx-1.14.0]# make && make install

检查Nginx:

[root@VM-0-16-centos 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

启动/停止Nginx:

[root@VM-0-16-centos nginx-1.14.0]# /usr/local/nginx/sbin/nginx

[root@VM-0-16-centos nginx-1.14.0]# /usr/local/nginx/sbin/nginx -s stop

云服务器ip地址页面

开机自启动

[root@VM-0-16-centos nginx-1.14.0]# chmod 755 /etc/rc.d/rc.local
[root@VM-0-16-centos nginx-1.14.0]# vim /etc/rc.d/rc.local

添加

MySQL安装
卸载mariadb

[root@VM-0-16-centos lnmp]# yum list installed | grep mariadb 
mariadb-libs.x86_64              1:5.5.68-1.el7                        @os
[root@VM-0-16-centos lnmp]# yum -y remove mariadb*

安装Mysql/源

[root@VM-0-16-centos lnmp]# wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
[root@VM-0-16-centos lnmp]# rpm -ivh mysql80-community-release-el7-1.noarch.rpm
[root@VM-0-16-centos lnmp]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2023 解决公钥过期
[root@VM-0-16-centos lnmp]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64   MySQL Connectors Community               194
mysql-tools-community/x86_64        MySQL Tools Community                    126
mysql80-community/x86_64            MySQL 8.0 Community Server               247
[root@VM-0-16-centos lnmp]# yum -y  install mysql-server
[root@VM-0-16-centos lnmp]# 
Installed:
  mysql-community-server.x86_64 0:8.0.24-1.el7 
Dependency Installed:
  mysql-community-client.x86_64 0:8.0.24-1.el7            mysql-community-client-plugins.x86_64 0:8.0.24-1.el7           
  mysql-community-common.x86_64 0:8.0.24-1.el7            mysql-community-libs.x86_64 0:8.0.24-1.el7                     

Complete!
[root@VM-0-16-centos lnmp]#

启动mysql

[root@VM-0-16-centos lnmp]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@VM-0-16-centos lnmp]# 

查看初始密码然后登录
root@localhost: %sdu8swV:OLG[密码]

[root@instance-9a809cx7 src]# cat /var/log/mysqld.log|grep 'A temporary password'
2021-04-29T04:32:24.561119Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: %sdu8swV:OLG
[root@instance-9a809cx7 src]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.24

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

初始密码修改,by后面为密码

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)

#重启mysql
[root@VM-0-16-centos lnmp]# systemctl restart mysqld.service

mysql修改远程访问

mysql> use mysql;
mysql> update user set host = ‘%’ where user = ‘root’;
mysql> FLUSH PRIVILEGES;

mysql选择数据库引入脚本

mysql> use mysql;
mysql> source /home/soft/***.sql;

mysql服务命令

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

PHP安装

手动更新rpm 7yum源

[root@VM-0-16-centos lnmp]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Retrieving https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:epel-release-7-13                ################################# [100%]

[root@VM-0-16-centos lnmp]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
warning: /var/tmp/rpm-tmp.DAiXqr: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:webtatic-release-7-3             ################################# [100%]

[root@VM-0-16-centos lnmp]#

查看版本号是否更新成功

[root@VM-0-16-centos lnmp]# yum list php*

安装php

[root@VM-0-16-centos lnmp]# yum  install epel-release  //扩展包更新包
[root@VM-0-16-centos lnmp]# yum  update //更新yum源
[root@VM-0-16-centos lnmp]# yum -y install php72w-gd php72w-imap php72w-ldap php72w-odbc php72w-pear php72w-xml php72w-xmlrpc php72w-mysqlnd php72w-pdo php72w-curl php72w-mbstring
[root@VM-0-16-centos lnmp]# yum -y install libmcrypt libmcrypt-devel mcrypt mhash  

安装PHP-FPM

[root@VM-0-16-centos lnmp]# yum -y install php72w-fpm.x86_64

#查看php-fpm版本
[root@VM-0-16-centos lnmp]# php-fpm -v
PHP 7.2.34 (fpm-fcgi) (built: Oct  1 2020 13:40:44)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

#启动php-fpm
[root@VM-0-16-centos lnmp]# systemctl start php-fpm

配置Nginx支持PHP

注释*,然后修改/scripts为$document_root

[root@VM-0-16-centos lnmp]# vi /usr/local/nginx/conf/nginx.conf

配置支持后重启nginx:

[root@VM-0-16-centos lnmp]# /usr/local/nginx/sbin/nginx -s reload

防火墙开放80端口

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

打开phpinfo测试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值