Fedora 12伺服器上安裝Apache2+PHP+MySQL

來源:互聯網
上載者:User

LAMP是 Linux, Apache, MySQL, PHP的縮寫.這篇教程將教你如何在一台Fedora 12伺服器上安裝Apache2web伺服器+PHP(mod_php) +MySQL .

我已經測試無誤,你可以放心使用。

1. 前言


在這篇教程中,我使用的主機名稱為server1.example.com,ip地址是192.168.0.100。這些設定可能與你想要的有所不同,所以你必須在適當的地方修改一下。

2 安裝MySQL5


用下列命令安裝MySQL:
yum install mysql mysql-server

然後我們為MySQL建立系統啟動連結(這樣的話,MySQL就會隨著系統啟動而啟動),並啟動MySQL伺服器:
chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start

運行
mysqladmin -u root password yourrootsqlpassword
mysqladmin -h server1.example.com -u root password yourrootsqlpassword

來為root使用者佈建一個密碼(否則任何人都可以訪問你的MySQL資料庫!)

3 安裝Apache2


Fedora預設有Apache2這個包,我們可以用下列命令安裝它:
yum install httpd

現在配置下系統使得Apache能夠隨著系統啟動而啟動…
chkconfig --levels 235 httpd on

... 啟動Apache:
/etc/init.d/httpd start

現在開啟瀏覽器,訪問http://192.168.0.100,你就應該能看到Apache2的預留頁了:



在Fedora中Apache的預設文件路徑在/var/www/html,設定檔是/etc/httpd/conf/httpd.conf。其餘的設定檔儲存在/etc/httpd/conf.d/。

4 安裝PHP5

我們用下列命令安裝PHP5和Apache PHP5模組:
yum install php

然後我們啟動下Apache:
/etc/init.d/httpd restart

5 測試PHP5/擷取PHP5安裝後的詳細資料

網站的預設文件路徑是/var/www/html。我們現在在這個檔案夾中建立一個小型PHP(info.php)檔案,並在;瀏覽器中訪問它。這個檔案會顯示關於PHP安裝的大量的細節,例如PHP的版本。
vi /var/www/html/info.php

<?php

phpinfo();

?>

現在我們在瀏覽器中訪問這個檔案(例如http://192.168.0.100/info.php):



正如你所看到的一樣,PHP5已經正常工作了,並且在Server API這一行中顯示的Apache是以Apache2.0 Handler模式工作的。如果你向下翻頁,你將會看到已經安裝了PHP5的所有的模組。MySQL沒有在這裡列出來,也就意味著目前PHP5並不支援 MySQL。

6 讓PHP5支援MySQL


我們安裝php-mysql這個包既可以使MySQL支援php了。在這裡最好也安裝其他的PHP5模組,這些模組也許你會在其他的應用中用到。你可以使用下列明星先搜尋一下PHP5的模組:
yum search php

選取你需要的模組,並使用下列命令安裝它們:
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mapserver php-mbstring php-mcrypt php-mhash php-mssql php-shout php-snmp php-soap php-tidy

現在重啟Apache2:
/etc/init.d/httpd restart

現在在瀏覽器中重新整理http://192.168.0.100/info.php,並再次翻到模組部分。你就應該能在這裡找到很多新模組,其中就包括了MySQL模組:


7 phpMyAdmin


phpMyAdmin是一款可以web化管理MySQL資料庫的工具:

可以使用下列命令安裝phpmyadmin:
yum install phpmyadmin

現在我們配置phpMyAdmin。我們改變Apache的設定檔讓其只能通過本地訪問(通過登出<Directory /usr/share/phpMyAdmin/參數):
vi /etc/httpd/conf.d/phpMyAdmin.conf

# phpMyAdmin - Web based MySQL browser written in php
#
# Allows only localhost by default
#
# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin
#
#   order deny,allow
#   deny from all
#   allow from 127.0.0.1
#   allow from ::1
#

# This directory does not require access over HTTP - taken from the original
# phpMyAdmin upstream tarball
#

    Order Deny,Allow
    Deny from All
    Allow from None


# This configuration prevents mod_security at phpMyAdmin directories from
# filtering SQL etc.  This may break your mod_security implementation.
#
#
#   
#        SecRuleInheritance Off
#   
#

重啟Apache:
/etc/init.d/httpd restart

然後,你就可以通過http://192.168.0.100/phpmyadmin/:訪問phpMyAdmin了 :


8 相關連結



       
  • Apache: http://httpd.apache.org/
       
  • PHP: http://www.php.net/
       
  • MySQL: http://www.mysql.com/
       
  • Fedora: http://fedoraproject.org/
       
  • phpMyAdmin: http://www.phpmyadmin.net/

9 相關聲明

源地址:http://www.howtoforge.com/installing-apache2-with-php5-and-mysql-support-on-fedora-12-lamp


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.