跳到主要內容

Linux-CentOS7-如何建置LAMP?(CentOS7+Apache2.4+MariaDB10.3+PHP7.3)

LAMP
由Linux搭建,Apache提供WEB服務,MariaDB 或 MySQL提供資料庫存取,PHP 或 Python作為網頁的程式語言。

首先安裝第三方套件庫:
1.查看CentOS官方獲社群認可的軟件庫:可供CentOS 使用的軟件庫 - CentOS Wiki
2.安裝 EPELRemi RepositoryMariaDB Repositories
  • EPEL:
  • # sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  • Remi Repository:
  • # sudo rpm -Uvh http://mirror.innosol.asia/remi/enterprise/remi-release-7.rpm
  • MariaDB Repositories:這邊使用 MariaDB 10.3
  • # sudo vim  /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.3 CentOS repository list - created 2019-09-03 01:44 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
3.清除套件庫緩存及讓repo設定生效
  • # sudo yum clean all 


安裝 Apache HTTP Server
  • # sudo yum install httpd


使用 chown 更改目錄(/var/www/html)擁有者、群組為 apache

  • sudo chown apache:apache -R /var/www/html


使用 chcon 修改 SELinux security context
  • sudo chcon -R -t httpd_sys_rw_content_t /var/www/html

開通防火牆 HTTP 端口 | 查看防火牆規則清單
  • # sudo firewall-cmd --add-service=http --permanent
  • # sudo firewall-cmd --reload
  • # sudo firewall-cmd --list-all

 查看 Apache 啟動狀態 | 重啟 Apache | 開機後啟動 httpd
  • # sudo systemctl status httpd
  • # sudo systemctl restart httpd
  • # sudo systemctl enable httpd

查看 Apache 測試頁
  • 使用 先前架設 DNS Server 做解析到 Apache Server ,URL:www.brookdns.local
Apache 完成安裝!!


Mariadb
安裝 MariaDB 10.3

  • sudo yum install mariadb-server

啟動 MariaDB | 查看 MariaDB 狀態 | 開機後啟動MariaDB
  • sudo systemctl restart mariadb
  • sudo systemctl status mariadb
  • sudo systemctl enable mariadb

執行 mysql_secure_installation 設定相關安全性
  • mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
"
登入 MariaDB 測試
  • mysql -u root -p

MariaDB 測試完成!!

PHP
安裝PHP前有必要先確認一下版本,例如:worepress.org上就有要求PHP的版本需要7.3,後面需要安裝 wordpress 所以這邊安裝 php7.3版,但是 CentOS7預設提供的PHP只有提供5.4版,所以開始時有安裝套件庫(Remi Repository),先安裝 yum-utils 使用yum-config-manager指令啟用 Remi Repository PHP7.3。

  • sudo yum install yum-utils
  • sudo yum-config-manager --enable remi-php73
安裝PHP7.3及常用擴建
  • sudo yum install php php-xml php-gd php-mbstring php-intl php-mysqlnd php-pecl-zip php-pecl-mysql
安裝完後在 Apache 存放網頁的路徑下創建一個 PHP 信息測試頁,寫入<?php phpinfo(); ?>
  • # sudo vim /var/www/html/info.php

重新啟動 Apache 服務
  • sudo systemctl restart httpd
查看 PHP 信息頁面
  • http://your doman name/info.php 
PHP完成安裝!!

留言

這個網誌中的熱門文章

Linux-CentOS7 使用 Bind 架設 DNS Server & DNS正解

DNS (Domain Name System)服務 提供域名解析,相較於IP位址(IP Address),域名(Domain name)讓使用者容易記憶,使用域名對應IP位址。 1.安裝 BIND 套件 # sudo yum install bind

Linux-CentOS7 Bind 設置 DNS反解(rDNS) & 增加次要(Slave)伺服器

DNS 反解 : 將IP轉換成域名,通常需要 Class C 或是跟上層網路業者申請 ➽此使用內部網路做DNS反解測試。 1.在主設定檔(/etc/named.conf)添加反解區域(240.168.192.in-addr.arpr) # sudo vim /etc/named.conf zone "240.168.192.in-addr.arpa" IN { type master; file "240.168.192.txt"; }; 2.編輯 反解區域檔案(240.168.192.txt),完成後儲存檔案 # sudo vim/var/named/240.168.192.txt 3.重新啟動 Bind 服務&查看 Bind 服務狀態 # sudo systemctl restart named # sudo systemctl status named 4.使用 nslookup 工具測試 server xxx.xxx.xxx.xxx  --> 指定 DNS 服務器 反解測試完成!! DNS次要(Slave)服務器: 主要減少主伺服器的負擔,還有DNS服務器備機的用途。 1.在主要(Master)DNS服務器,正解及反解區域添加: allow-transfer { }; notify yes; 2.重啟主要(Master)DNS服務器的 Bind 服務 # sudo system restart named 3.次要(Slave)服務器安裝 Bind # sudo yum install -y bind 4.編輯 Slave 的 Bind 主設定檔 # sudo vim /etc/named.conf listen-on port 53 {}; //加入次要服務器 IP allow-query {}; //開放允許查詢的網段 // 加入正解區域 zone "brookdns.local" IN { type slave; masters {192.168.240.14...

Windows-使用 PowerShell 更改 RDP Port Number & 調整防火牆規則

目的: 服務器在啟用遠端桌面預設值為"3389",因為對管理上有風險,所以需要更改遠端桌面的端口號、調整防火牆規則增加安全性。 PowerShell內容  GitHub:https://github.com/minyufu/powershell.git function Pause(){ [System.Console]::Write('按任意鍵繼續...') [void][System.Console]::ReadKey(1) } #用途:更改預設RDP端口號並添加防火牆規則 Write-Output "-----目前RDP使用端口號-----" $Now_RDP_PortNumber = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal*Server\WinStations\RDP-TCP\" -Name PortNumber | Select-Object PortNumber Write-Output "PortNumber: $Now_RDP_PortNumber" #使用者輸入需要修改的端口號: $New_Rdp_PortNumber = Read-Host -Prompt '輸入新的RDP端口號' #設定新的端口號 Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal*Server\WinStations\RDP-TCP\" -Name PortNumber -Value $New_Rdp_PortNumber #加入TCP防火牆規則 New-NetFirewallRule -DisplayName "遠程桌面(TCP-In) $New_Rdp_PortNumber" -Direction Inbound -Protocol TCP -Profile Any -LocalPort $New_Rdp_PortNumber -Action allow Write-Output "遠程桌面(TCP...