因為安裝zabbix需要LAMP環境,特記錄如下。
LAMP指的Linux(操作系統)、Apache HTTP 服務器,MySQL(有時也指MariaDB,數據庫軟件)和PHP(有時也是指Perl或Python)的第一個字母,一般用來建立web應用平台。所有組成產品均是開源軟件,是國際上成熟的架構框架,很多流行的商業應用都是采取這個架構,和Java/J2EE架構相比,LAMP具有Web資源豐富、輕量、快速開發等特點,微軟的.NET架構相比,LAMP具有通用、跨平台、高性能、低價格的 優勢,因此LAMP無論是性能、質量還是價格都是企業搭建網站的首選平台。
下面討論如何在RHEL/CentOS/Scientific Linux 7上搭建LAMP環境.
一、Install Apache
Apache HTTP Server(簡稱Apache)是Apache軟件基金會的一個開放源碼的網頁服務器,可以在大多數計算機操作系統中運行,由於其多平台和安全性被廣泛使用,是最流行的Web服務器端軟件之一。它快速、可靠並且可通過簡單的API擴展,將Perl/Python等解釋器編譯到服務器中。
在終端以root權限運行以下命令:
yum install httpd -y
啟動Apache
systemctl start httpd
設置開機啟動
systemctl enable httpd
firewall設置允許遠程登錄:
firewall-cmd --permanent --add-service=http
systemctl restart firewalld
測試Apache
瀏覽器訪問 http://localhost/ or http://server-ip-address/
二、Install MariaDB
MariaDB數據庫管理系統是MySQL的一個分支,主要由開源社區在維護,采用GPL授權許可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能輕松成為MySQL的代替品。 MariaDB由MySQL的創始人Michael Widenius(英語:Michael Widenius)主導開發,他早前曾以10億美元的價格,將自己創建的公司MySQL AB賣給了SUN,此后,隨着SUN被甲骨文收購,MySQL的所有權也落入Oracle的手中。MariaDB名稱來自Michael Widenius的女兒Maria的名字。
安裝MariaDB
yum install mariadb-server mariadb -y
啟動MariaDB
systemctl start mariadb
設置開機啟動
systemctl enable mariadb
設置root密碼
默認情況下,root密碼為空。為防止未授權的訪問,我們設置root密碼
mysql_secure_installation
三、Install PHP
PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本預處理器”)是一種通用開源腳本語言,主要適用於Web開發領域。
使用以下的命令安裝php
yum install php php-mysql php-gd php-pear -y
測試PHP:
在Apache文檔根目錄創建“testphp.php”
vi /var/www/html/testphp.php
編輯內容如下
<?php
phpinfo();
?>
重啟 httpd 服務:
systemctl restart httpd
瀏覽器訪問 http://server-ip-address/testphp.php. 將會顯示php的版本信息.
也可以使用如下命令安裝所有php modules,重啟httpd服務,查看http://server-ip-address/testphp.php,可以看到所有安裝的modules
yum install php* -y
四、Install phpMyAdmin (可選)
phpMyAdmin 是一個以PHP為基礎,以Web-Base方式架構在網站主機上的MySQL的數據庫管理工具,讓管理者可用Web接口管理MySQL數據庫。由於phpMyAdmin跟其他PHP程式一樣在網頁服務器上執行,您可以在任何地方使用這些程式產生的HTML頁面,也就是於遠端管理MySQL數據庫,方便的建立、修改、刪除數據庫及資料表。也可借由phpMyAdmin建立常用的php語法,方便編寫網頁時所需要的sql語法正確性。
添加 EPEL repository 參照(Install EPEL Repository on RHEL/CentOS/Scientific Linux 7)
yum install epel-release
安裝 phpMyAdmin:
yum install phpmyadmin -y
配置phpMyAdmin
默認,phpMyAdmin只能由本機訪問。為了能夠遠程訪問,編輯phpmyadmin.conf file:
vi /etc/httpd/conf.d/phpMyAdmin.conf
查找/<Directory> ,注釋掉或刪除如下內容
<Directory /usr/share/phpMyAdmin/> AddDefaultCharset UTF-8
<IfModule mod_authz_core.c> # Apache 2.4 <RequireAny> Require ip 127.0.0.1 Require ip ::1 </RequireAny> </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from ::1 </IfModule> </Directory>
<Directory /usr/share/phpMyAdmin/setup/> <IfModule mod_authz_core.c> # Apache 2.4 <RequireAny> Require ip 127.0.0.1 Require ip ::1 </RequireAny> </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from ::1 </IfModule> </Directory> |
添加
<Directory /usr/share/phpMyAdmin/> Options none AllowOverride Limit Require all granted </Directory> |
編輯“config.inc.php” 改變phpMyAdmin的authentication,修改“cookie” 為 “http”
vi /etc/phpMyAdmin/config.inc.php
Change ‘cookie’ to ‘http’.
重啟the Apache service:
systemctl restart httpd
訪問 phpmyadmin 的控制台 http://server-ip-address/phpmyadmin/
輸入MySQL username and password,將重定向到PhpMyAdmin main web interface.
現在你可以通過phpMyAdmin web interface 管理你的MariaDB數據庫了。
至此LAMP環境搭建完畢
參考:
http://www.unixmen.com/install-lamp-server-apache-mariadb-php-centosrhelscientific-linux-7/