altis 2014-11-1 23:00
在 CentOS 7 下快速安裝 Apache+PHP+MariaDB(MySQL)
<div><div>Redhat 在 7 月份釋出了最新版本的作業系統 – Redhat Enterprise Linux 7,CentOS 也在當月不久釋出 CentOS 7,</div><div>這邊介紹如何快速的在 CentOS 中建置 LAMP(Linux + Apache + MariaDB + PHP)服務。</div><div><br></div><div>RHEL7/CentOS7 已不包含 MySQL 資料庫,取而代之的是由原先 MySQL 開發團隊所維護的 MariaDB,其功能與函式使用均與 MySQL 相同,基本上若無使用特別的套件,大部份的應用程式應該都相容可以,無需修改程式。</div></div><div><br></div>安裝 Apache <br># <font color="#ff0000">yum install httpd</font><br><br>啟動 Web Server<br># <font color="#ff0000">service httpd start</font><br><font color="#0000ff">Redirecting to /bin/systemctl start httpd.service</font><br>或<br># <font color="#ff0000">systemctl start httpd</font><br><br>在防火牆開啟 http 服務<br># <font color="#ff0000">firewall-cmd --permanent --add-service=http</font><br># <font color="#ff0000">systemctl restart firewalld</font><br><br>設定開機時啟動 Web Server<br># <font color="#ff0000">systemctl enable httpd</font><br><br>安裝 PHP<br># <font color="#ff0000">yum install php php-mysql php-pdo php-gd php-mbstring</font><br><br>修改時區設定<br># <font color="#ff0000">sed -i 's/;date.timezone =/date.timezone = Asia\/Taipei/' /etc/php.ini</font><br><br>重新啟動 Web Server<br># <font color="#ff0000">service httpd restart</font><br><font color="#0000ff">Redirecting to /bin/systemctl restart httpd.service</font><br>或<br># <font color="#ff0000">systemctl restart httpd</font><br><br>安裝 MariaDB<br># <font color="#ff0000">yum install mariadb-server mariadb</font><br><br>啟動 MariaDB<br># <font color="#ff0000">systemctl start mariadb</font><br><br>初始化資料庫設定<br># <font color="#ff0000">/usr/bin/mysql_secure_installation</font><br><br>設定開機時啟動 MariaDB<br># <font color="#ff0000">systemctl enable mariadb</font><div><font color="#ff0000"><br><font color="Black">再來安裝 phpMyAdmin<br>因為目前yum的套件資料庫中沒有phpMyAdmin的安裝資訊存在,我們要更新yum套件資料庫。請執行以下指令來更新yum套件資料庫:<br><br># </font></font><font color="#ff0000"><font color="Black">rpm -ivh <a href="http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm">http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm</a><br># </font></font><font color="#ff0000"><font color="Black">yum install phpMyAdmin<br><br>我們開始執行phpMyAdmin網頁時, http://localhost/phpmyadmin會出現 Forbidden 的錯誤,這是因為Apache的保護,我們要修改phpMyAdmin網頁的設定,請執行下列vi指令:<br><br>vi /etc/httpd/conf.d/phpMyAdmin.conf<br><br>然後,把phpMyAdmin.conf的配置修改如下:<br>[quote]<br><font color="Red">#<Directory /usr/share/phpMyAdmin/> <br># AddDefaultCharset UTF-8 <br># <br># <IfModule mod_authz_core.c> <br># # Apache 2.4 <br># <RequireAny> <br># Require ip 127.0.0.1 <br># Require ip ::1 <br># </RequireAny> <br># </IfModule> <br># <IfModule !mod_authz_core.c> <br># # Apache 2.2 <br># Order Deny,Allow <br># Deny from All <br># Allow from 127.0.0.1 <br># Allow from ::1 <br># </IfModule> <br>#</Directory> </font><br> <br><font color="DarkGreen"><Directory /usr/share/phpMyAdmin/> <br> Options none <br> AllowOverride Limit <br> Require all granted <br></Directory> </font><br> <br>[......] <br>[/quote]<br><br>將紅色內容 加‘#’號予以註解,不執行,再增加綠色的部份,<br>然後 Apache 重啟後,就大功告成啦!<br></font></font></div>