Centos 7配置LAMP

由於安裝zabbix須要LAMP環境,特記錄以下。php

LAMP指的Linux(操做系統)、Apache HTTP 服務器,MySQL(有時也指MariaDB,數據庫軟件)和PHP(有時也是指Perl或Python)的第一個字母,通常用來創建web應用平臺。全部組成產品均是開源軟件,是國際上成熟的架構框架,不少流行的商業應用都是採起這個架構,和Java/J2EE架構相比,LAMP具備Web資源豐富、輕量、快速開發等特色,微軟的.NET架構相比,LAMP具備通用、跨平臺、高性能、低價格的 優點,所以LAMP不管是性能、質量仍是價格都是企業搭建網站的首選平臺。html

下面討論如何在RHEL/CentOS/Scientific Linux 7上搭建LAMP環境.mysql

1、Install Apache

Apache HTTP Server(簡稱Apache)是Apache軟件基金會的一個開放源碼的網頁服務器,能夠在大多數計算機操做系統中運行,因爲其多平臺和安全性被普遍使用,是最流行的Web服務器端軟件之一。它快速、可靠而且可經過簡單的API擴展,將Perl/Python等解釋器編譯到服務器中。linux

在終端以root權限運行如下命令:web

yum install httpd -y

啓動Apachesql

systemctl start httpd

設置開機啓動數據庫

systemctl enable httpd

firewall設置容許遠程登陸:apache

firewall-cmd --permanent --add-service=http

systemctl restart firewalld

測試Apachecentos

瀏覽器訪問 http://localhost/ or http://server-ip-address/瀏覽器

clip_image001[8]

2、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

3、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的版本信息.

clip_image002[4]

也可使用以下命令安裝全部php modules,重啓httpd服務,查看http://server-ip-address/testphp.php能夠看到全部安裝的modules

yum install php* -y

4、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’.

clip_image003[4]

重啓the Apache service:

systemctl restart httpd

訪問 phpmyadmin 的控制檯 http://server-ip-address/phpmyadmin/

clip_image004[4]

輸入MySQL username and password,將重定向到PhpMyAdmin main web interface.

clip_image005

如今你能夠經過phpMyAdmin web interface 管理你的MariaDB數據庫了。

至此LAMP環境搭建完畢

參考:

http://www.unixmen.com/install-lamp-server-apache-mariadb-php-centosrhelscientific-linux-7/

相關文章
相關標籤/搜索