Centos7.5編譯安裝搭建LNMP環境

環境介紹php

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

1、Nginx安裝
一、檢查是否安裝wget,若是沒有安裝就使用yum安裝html

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

二、安裝編譯器mysql

yum install gcc gcc-c++

三、安裝nginx依賴的軟件
nginx中的rewrite module、gzip module、Http SSL module須要安裝PCRE、zlib、OpenSSL,這裏編譯安裝也可使用yum安裝,命令以下,這裏用的是編譯安裝nginx

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

3.一、zlib源碼安裝
解壓、編譯安裝c++

[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.二、pcre安裝
Pcre官網
下載最新版本8.42
解壓、編譯安裝web

[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]#

查看版本sql

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

3.三、OpenSSL安裝
OpenSSL官網
下載並解壓、安裝vim

[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

四、Nginx安裝(最新穩定版爲1.14.0)
官網php7

[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的正確性:tcp

[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]#

圖片描述

2、MySQL安裝
一、檢查是否安裝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*

二、安裝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     #查看狀態

3、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端口
相關文章
相關標籤/搜索