Centos7.2下LAMP環境快速搭建

目錄

1. 概述

2. 環境準備

2.1 機器準備

#一臺虛擬機
hostname:myhost
ip:ip_address

2.2 系統環境

[root@myhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 
[root@myhost ~]#  firewall-cmd --state							 #查看防火牆的狀態
running
[root@myhost ~]#  firewall-cmd --list-ports                       #查看防火牆已經開放的端口
[root@myhost ~]#  firewall-cmd --list-services                    #查看防火牆開放的服務
dhcpv6-client ssh
#httpd服務默認的端口是80,防火牆允許80/tcp端口訪問 
[root@myhost ~]#  firewall-cmd --zone=public --permanent --add-port=80/tcp
success
#mysqld服務默認的端口是3306,防火牆允許3306/tcp端口訪問 
[root@myhost ~]#  firewall-cmd --zone=public --permanent --add-port=3306/tcp
success
[root@myhost ~]#  firewall-cmd --reload                                       	#重新加載防火牆配置
success 
[root@myhost ~]#  setenforce 0  &&    getenforce
Permissive
[root@myhost ~]#  sed -i  "s/SELINUX=enforcing/SELINUX=disabled/g"  /etc/sysconfig/selinux 

3. Apache安裝部署

3.1 下載httpd源碼安裝包

[root@myhost ~]# cd /home/tools/
[root@myhost tools]# ll
總用量 22256
-rw-r--r--. 1 root root 639864682 1月   8 09:46 mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz

[root@myhost tools]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.43.tar.gz
--2020-04-14 15:17:44--  https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.43.tar.gz
正在解析主機 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
正在連接 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... 已連接。
已發出 HTTP 請求,正在等待迴應... 200 OK
長度:9348230 (8.9M) [application/octet-stream]
正在保存至: “httpd-2.4.43.tar.gz”

100%[==================================================================================================>] 9,348,230   1.23MB/s 用時 7.3s   

2020-04-14 15:17:51 (1.23 MB/s) - 已保存 “httpd-2.4.43.tar.gz” [9348230/9348230])

3.2 解壓進行編譯安裝

[root@myhost tools]# ll
總用量 41388
-rw-r--r--. 1 root root   9348230 3月  30 22:21 httpd-2.4.43.tar.gz
-rw-r--r--. 1 root root 639864682 1月   8 09:46 mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
[root@myhost tools]# tar xf  httpd-2.4.43.tar.gz 
[root@myhost tools]# cd httpd-2.4.43
[root@myhost httpd-2.4.43]# ll
總用量 2200
-rw-r--r--.  1 root dip   13497 2月  21 08:33 ABOUT_APACHE
-rw-r--r--.  1 root dip   25703 2月  21 08:06 acinclude.m4
-rw-r--r--.  1 root dip   66792 3月  26 2019 Apache-apr2.dsw
-rw-r--r--.  1 root dip   81919 3月  26 2019 Apache.dsw
-rw-r--r--.  1 root dip    9907 12月 18 2009 apache_probes.d
-rw-r--r--.  1 root dip    2512 12月 22 2008 ap.d
drwxr-sr-x.  6 root dip    4096 3月  26 22:46 build
-rw-r--r--.  1 root dip    2644 8月  24 2007 BuildAll.dsp
-rw-r--r--.  1 root dip    2784 1月  14 2018 BuildBin.dsp
-rwxr-xr-x.  1 root dip   10679 9月   8 2017 buildconf
-rw-r--r--.  1 root dip  287086 3月  24 01:54 CHANGES
-rw-r--r--.  1 root dip   47641 10月 25 21:27 CMakeLists.txt
-rw-r--r--.  1 root dip   14180 2月  21 08:39 config.layout
-rwxr-xr-x.  1 root dip 1209103 3月  26 22:46 configure    ###編譯安裝腳本###
-rw-r--r--.  1 root dip   30571 2月   3 15:56 configure.in
drwxr-sr-x. 10 root dip    4096 3月  26 22:46 docs
-rw-r--r--.  1 root dip     403 11月 22 2004 emacs-style
-rw-r--r--.  1 root dip    2218 3月  23 2016 httpd.dep
-rw-r--r--.  1 root dip    4124 6月  12 2008 httpd.dsp
-rw-r--r--.  1 root dip    8994 3月  23 2016 httpd.mak
-rw-r--r--.  1 root dip   17313 3月  26 22:46 httpd.spec
drwxr-sr-x.  2 root dip    4096 3月  26 22:46 include
-rw-r--r--.  1 root dip    3782 5月  18 2016 INSTALL
-rw-r--r--.  1 root dip    2909 11月 15 2011 InstallBin.dsp
-rw-r--r--.  1 root dip    4097 11月 16 2013 LAYOUT
-rw-r--r--.  1 root dip   79070 3月  23 2016 libhttpd.dep
-rw-r--r--.  1 root dip   21528 1月  16 2018 libhttpd.dsp
-rw-r--r--.  1 root dip   38913 1月  16 2018 libhttpd.mak
-rw-r--r--.  1 root dip   25479 1月  15 01:39 LICENSE
-rw-r--r--.  1 root dip   11166 8月   8 2018 Makefile.in
-rw-r--r--.  1 root dip   53749 3月  26 2019 Makefile.win
drwxr-sr-x. 28 root dip    4096 3月  26 22:43 modules
-rw-r--r--.  1 root dip     720 1月   2 03:42 NOTICE
-rw-r--r--.  1 root dip   13884 3月  20 2016 NWGNUmakefile
drwxr-sr-x.  7 root dip    4096 3月  26 22:46 os
-rw-r--r--.  1 root dip    4642 1月  24 2014 README
-rw-r--r--.  1 root dip   13317 3月  23 2016 README.cmake
-rw-r--r--.  1 root dip    4418 8月  28 2014 README.platforms
-rw-r--r--.  1 root dip   10184 2月  21 08:33 ROADMAP
drwxr-sr-x.  3 root dip    4096 3月  26 22:46 server
drwxr-sr-x.  2 root dip      24 3月  26 22:46 srclib
drwxr-sr-x.  4 root dip    4096 3月  26 22:46 support
drwxr-sr-x.  2 root dip    4096 3月  26 22:46 test
-rw-r--r--.  1 root dip    8186 2月  21 08:33 VERSIONING

[root@myhost httpd-2.4.43]# ./configure --prefix=/usr/local/apache-2.4.43/ --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... no
configure: error: APR not found.  Please read the documentation.

#編譯過程中報錯,根據報錯信息進行處理,這裏缺少APR依賴包
[root@myhost httpd-2.4.43]# yum install -y apr*

#再次進行編譯
[root@myhost httpd-2.4.43]# ./configure --prefix=/usr/local/apache-2.4.43/ --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite

[root@myhost httpd-2.4.43]# echo $?
0
[root@myhost httpd-2.4.43]# make && make install  && echo $?
[root@myhost httpd-2.4.43]# cd /usr/local/apache-2.4.43/
[root@myhost apache-2.4.43]# ll
總用量 44
drwxr-xr-x.  2 root root 4096 4月  14 15:22 bin
drwxr-xr-x.  2 root root 4096 4月  14 15:22 build
drwxr-xr-x.  2 root root   74 4月  14 15:22 cgi-bin
drwxr-xr-x.  4 root root   79 4月  14 15:22 conf
drwxr-xr-x.  3 root root 4096 4月  14 15:22 error
drwxr-sr-x.  2 root root   23 3月  26 22:46 htdocs
drwxr-xr-x.  3 root root 8192 4月  14 15:22 icons
drwxr-xr-x.  2 root root 4096 4月  14 15:22 include
drwxr-xr-x.  2 root root    6 4月  14 15:22 logs
drwxr-xr-x.  4 root root   28 4月  14 15:22 man
drwxr-sr-x. 14 root root 8192 3月  26 22:46 manual
drwxr-xr-x.  2 root root 4096 4月  14 15:22 modules

3.3 檢查+啓動httpd服務

[root@myhost apache-2.4.43]# /usr/local/apache-2.4.43/bin/apachectl -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using xx.xx.xx.xx. Set the 'ServerName' directive globally to suppress this message
Syntax OK

[root@myhost apache-2.4.43]# grep ServerName /usr/local/apache-2.4.43/conf/httpd.conf 
# ServerName gives the name and port that the server uses to identify itself.
#ServerName www.example.com:80

[root@myhost apache-2.4.43]# vi  /usr/local/apache-2.4.43/conf/httpd.conf  +198
# ServerName gives the name and port that the server uses to identify itself.
#ServerName www.example.com:80
ServerName 127.0.0.1:80
[root@myhost apache-2.4.43]# grep ServerName /usr/local/apache-2.4.43/conf/httpd.conf 
# ServerName gives the name and port that the server uses to identify itself.
#ServerName www.example.com:80
ServerName 127.0.0.1:80
[root@myhost apache-2.4.43]# /usr/local/apache-2.4.43/bin/apachectl -t                
Syntax OK

在這裏插入圖片描述

[root@myhost apache-2.4.43]# /usr/local/apache-2.4.43/bin/apachectl  start
[root@myhost apache-2.4.43]# /usr/local/apache-2.4.43/bin/apachectl stop
[root@myhost apache-2.4.43]# /usr/local/apache-2.4.43/bin/apachectl  start
[root@myhost apache-2.4.43]# /usr/local/apache-2.4.43/bin/apachectl status
/usr/local/apache-2.4.43/bin/apachectl:行95: lynx: 未找到命令
[root@myhost apache-2.4.43]# ps -ef |grep httpd
root     16708     1  0 15:31 ?        00:00:00 /usr/local/apache-2.4.43//bin/httpd
daemon   16709 16708  0 15:31 ?        00:00:00 /usr/local/apache-2.4.43//bin/httpd
daemon   16710 16708  0 15:31 ?        00:00:00 /usr/local/apache-2.4.43//bin/httpd
daemon   16714 16708  0 15:31 ?        00:00:00 /usr/local/apache-2.4.43//bin/httpd
root     16805 63217  0 15:32 pts/0    00:00:00 grep --color=auto httpd
[root@myhost apache-2.4.43]# netstat -lntup |grep httpd
tcp6       0      0 :::80                   :::*                    LISTEN      16708/httpd   

4 MySQL安裝部署

4.1 軟件安裝約定

安裝包存放目錄:/home/tools
Mysql安裝目錄:/usr/local/mysql
數據庫保存位置:/usr/local/mysql/data  	#需要自行建立,並修改屬主和屬組爲mysql:mysql
日誌保存位置:/usr/local/mysql/log			#需要自行建立,並修改屬主和屬組爲mysql:mysql

4.2 下載安裝包

  1. MySQL的官網下載地址:http://www.mysql.com/downloads
  2. MySQL的官網下載地址:https://dev.mysql.com/downloads/mysql
[root@myhost ~]#cd /home/tools
[root@myhost tools]# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
[root@myhost tools]# ll
total 835560
-rw-r--r--. 1 root root 639864682 May 25  2016 mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz

4. 3 解壓安裝部署

解壓安裝部署過程省略,參考之前寫兩篇,注意安裝路徑防火牆開放端口等靈活處理。

https://blog.csdn.net/yuki5233/article/details/89466254

https://blog.csdn.net/yuki5233/article/details/81736439
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章