CENTOS7 安裝LNMP環境
阿新 • • 發佈:2021-04-30
------僅作為自己學習留存------
CENTOS 7.6/NGINX1.14.0/MYSQL8/PHP7.2
安裝編譯器
[[email protected] home]# yum install gcc gcc-c++
軟體下載路徑---自己伺服器
/home/lnmp
zlib原始碼安裝
[[email protected] lnmp]# wget http://prdownloads.sourceforge.net/libpng/zlib-1.2.11.tar.gz
[[email protected] lnmp]# tar zxvf zlib-1.2.11.tar.gz
[ [email protected] lnmp]# cd zlib-1.2.11
[[email protected] zlib-1.2.11]# ./configure
[[email protected] zlib-1.2.11]# make && make install
pcre安裝
[[email protected] lnmp]# wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz
[[email protected] lnmp]# tar zxvf pcre-8.42.tar.gz
[ [email protected] lnmp]# cd pcre-8.42/
[[email protected] pcre-8.42]# ./configure
[[email protected] pcre-8.42]# make && make install
[[email protected] pcre-8.42]#
[[email protected] lnmp]# pcre-config --version
8.42
OpenSSL安裝
[[email protected] lnmp]#yum groupinstall "Development Tools"
[ [email protected] lnmp]# wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
[[email protected] lnmp]# tar zxvf openssl-1.1.1k.tar.gz
[[email protected] lnmp]# cd openssl-1.1.1k/
[[email protected] openssl-1.1.1k]# ./config --prefix=/usr/local/openssl --openssldir=/usr/local/ssl
[[email protected] openssl-1.1.1k]# make -j 2
[[email protected] openssl-1.1.1k]# make install
匯出庫檔案
[[email protected] openssl-1.1.1k]# echo /usr/local/openssl/lib >> /etc/ld.so.conf.d/openssl.conf
[[email protected] openssl-1.1.1k]# ldconfig
# "檢測版本資訊"
[[email protected] openssl-1.1.1k]# /usr/local/openssl/bin/openssl version -a
#匯出openssl/bin 到PATH 變數
[[email protected] openssl-1.1.1k]# echo 'PATH=/usr/local/openssl/bin:$PATH' >> /etc/profile.d/env.sh
[[email protected] openssl-1.1.1k]# source /etc/profile.d/env.sh
[[email protected] openssl-1.1.1k]# openssl version
OpenSSL 1.1.1k 25 Mar 2021
Nginx安裝
[[email protected] lnmp]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
[[email protected] lnmp]# tar zxvf nginx-1.14.0.tar.gz
[[email protected] lnmp]# cd nginx-1.14.0/
[[email protected] 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
[[email protected] nginx-1.14.0]# make && make install
檢查Nginx:
[[email protected] 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:
[[email protected] nginx-1.14.0]#/usr/local/nginx/sbin/nginx
[[email protected] nginx-1.14.0]# /usr/local/nginx/sbin/nginx -s stop
雲伺服器ip地址頁面
開機自啟動
[[email protected] nginx-1.14.0]# chmod 755 /etc/rc.d/rc.local
[[email protected] nginx-1.14.0]# vim /etc/rc.d/rc.local
新增
MySQL安裝
解除安裝mariadb
[[email protected] lnmp]# yum list installed | grep mariadb
mariadb-libs.x86_64 1:5.5.68-1.el7 @os
[[email protected] lnmp]# yum -y remove mariadb*
安裝Mysql/源
[[email protected] lnmp]# wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
[[email protected] lnmp]# rpm -ivh mysql80-community-release-el7-1.noarch.rpm
[[email protected] 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
[[email protected] lnmp]# yum -y install mysql-server
[[email protected] 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!
[[email protected] lnmp]#
啟動mysql
[[email protected] lnmp]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[[email protected] lnmp]#
檢視初始密碼然後登入
[email protected]: %sdu8swV:OLG[密碼]
[[email protected] 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 [email protected]: %sdu8swV:OLG
[[email protected] 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
[[email protected] lnmp]# systemctl restart mysqld.service
mysql服務命令
systemctl start mysqld.service #啟動
systemctl stop mysqld.service #停止
systemctl restart mysqld.service #重啟
systemctl enable mysqld.service #設定開機啟動
systemctl status mysqld.service #檢視狀態
PHP安裝
手動更新rpm 7yum源
[[email protected] 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%]
[[email protected] 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%]
[[email protected] lnmp]#
檢視版本號是否更新成功
[[email protected] lnmp]# yum list php*
安裝php
[[email protected] lnmp]# yum install epel-release //擴充套件包更新包
[[email protected] lnmp]# yum update //更新yum源
[[email protected] 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
[[email protected] lnmp]# yum -y install libmcrypt libmcrypt-devel mcrypt mhash
安裝PHP-FPM
[[email protected] lnmp]# yum -y install php72w-fpm.x86_64
#檢視php-fpm版本
[[email protected] 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
[[email protected] lnmp]# systemctl start php-fpm
配置Nginx支援PHP
註釋*,然後修改/scripts為$document_root
[[email protected] lnmp]# vi/usr/local/nginx/conf/nginx.conf
配置支援後重啟nginx:
[[email protected] 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 --reload #重啟防火牆
開啟phpinfo測試