2014年7月15日 星期二

Centos6.5中安裝LAMP與phpMyAdmin軟體

下午4:00:00 Posted by Amos , No comments

簡介

本文概述簡單的步驟,教導如何建置LAMP環境(Apache、Php、MySQL),並安裝phpmyadmin管理MySQL資料庫。

環境介紹及前置作業

作業系統版本 : Centos 6.5 (64位元)

安裝編輯及wget套件

若於Centos中已有安裝vim (編輯工具)和wget(抓檔案工具)時,可以忽略該步驟
yum -y install wget vim

關閉SELinux

編輯 /etc/sysconfig/selinux檔案,將SELINUX=enforcing 改成 SELINUX=disabled,重新開機。
# This file controls the state of SELinux on the system. 
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

設定Open File個數

編輯 /etc/security/limits.conf檔案,設定Open File個數
* hard nofile 65535
* soft nofile 65535

開啟防火牆

編輯 /etc/sysconfig/iptables檔案,開啟8080防火牆(用於node.js的服務),設定完成後請重新啟動防火牆。
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
/etc/init.d/iptables restart

安裝及設定Apache

輸入 yum install httpd* ,安裝Apacher Server相關套件,並設定於開機時自動啟用,請參考以下步驟進行設定。
yum -y install httpd* 
chkconfig --level 345 httpd on
chkconfig --list httpd

為了安全性考量,設定用戶無法瀏覽Apache預設的首頁,請參考以下步驟進行設定(每行前面都加入#符號,共計4行)。
vi /etc/httpd/conf.d/welcome.conf 

#<LocationMatch "^/+$">
    #Options -Indexes
    #ErrorDocument 403 /error/noindex.html
#</LocationMatch>

啟用Apache時若有出現Could not reliably determine the server's fully qualified domain name訊息,請修改如下之檔案內容
vi /etc/httpd/conf/httpd.conf 
ServerName localhost:80 #新增加這一項參數

安裝及設定php

安裝php套件

安裝Apacher Server相關套件,並設定於開機時自動啟用,請參考以下步驟進行設定。
yum -y install php* 

安裝 mcrypt 以支援phpMyAdmin高級功能
rpm -ivh http://mirror01.idc.hinet.net/EPEL/6/x86_64/epel-release-6-8.noarch.rpm 
yum install php-mcrypt

重新啟動Apache Server。
/etc/init.d/httpd restart

設定php.ini檔案

編輯 /etc/php.ini檔案,設定以下參數
vi /etc/php.ini 
修改為: post_max_size = 800M
修改為: upload_max_filesize = 800M
修改為: default_charset="utf8"
修改為: default_socket_timeout = 300

安裝及設定MySQL資料庫

安裝MySQL

安裝MySQL相關套件,並設定於開機時自動啟用,請參考以下步驟進行設定。
yum install mysql-server 

設定MySQL自動啟動

chkconfig --level 345 mysqld on 
chkconfig --list mysqld

設定MySQL root帳號之密碼

/usr/bin/mysqladmin -u root password '新密碼'

重新啟動 MySQL Server
/etc/init.d/mysqld restart

安裝及設定phpMyAdmin

下載phpMyAdmin-4.0.10.1-all-languages.tar.gz並安裝

解壓縮phpMyAdmin-4.0.10.1-all-languages
tar -zxvf phpMyAdmin-4.0.10.1-all-languages.tar.gz

搬移 phpMyAdmin-4.0.10.1-all-languages目錄到/usr/share,並修改名稱為phpMyAdmin-4.0.10.1
mv phpMyAdmin-4.0.10.1-all-languages /usr/share/phpMyAdmin-4.0.10.1

複製範本設定檔 config.sample.inc.php 並重新命名為 config.inc.php
cd /usr/share/phpMyAdmin-4.0.10.1
cp config.sample.inc.php config.inc.php

修改 phpMyAdmin 的認證方式,請編輯config.inc.php檔案,重新啟動 Apache
/* Authentication type */ 
$cfg['Servers'][$i]['auth_type'] = 'cookies';
/etc/init.d/httpd restart

修改config.inc.php檔案的權限
chmod 644 config.inc.php

移除setup安裝資料夾
mv setup setup.org

設定phpMyAdmin網站別名(可視情況設定)

編輯 /etc/httpd/conf/httpd.conf 檔案

#Set Virtual Host
Alias /mysqladm "/usr/share/phpMyAdmin-4.0.10.1"
<Directory "/usr/share/phpMyAdmin-4.0.10.1">
  Options -Indexes FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all
</Directory>

開啟瀏覽器輸入http://您的IP/mysqladm將會看到phpMyAdmin登入網頁,輸入使用者名稱及密碼後即可開始管理MySQL資料庫

0 意見:

張貼留言