CentOS 5.6 快速搭建LAMP

來源:互聯網
上載者:User

在虛擬機器下安裝了個CentOS,5.6版本的。利用NAT模式與宿主pc共用上網!   
當然可以採用編譯源碼的方式搭建lamp。這裡只是介紹快速搭建php開發架構的方法。其實也沒什麼,主要是是是使用linux的yum來線上安裝。如果上不了網請尋找編譯源碼搭建lamp的文章。網上N多的哈^_^
   1.安裝mysql資料庫
     命令列下:yum -y install mysql mysql-server  
     Setting up Install Process
     Setting up repositories... ....
     ....................................................
     Installed: mysql-server.i386 0:4.1.20-1.RHEL4.1
     Dependency Installed: mysql.i386 0:4.1.20-1.RHEL4.1 perl-DBD-MySQL.i386 0:2.9004-3.1 perl-DBI.i386 0:1.40-8
     Complete!
    安裝完畢,配置mysql:
   命令列下:vi /etc/my.cnf        提示:紅色字為添加的行,主要是設定資料庫預設的字元集為utf8
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
default-character-set = utf8
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
[mysql]
default-character-set = utf8
 儲存退出後,設定mysql服務隨系統自啟動,
命令列下:chkconfig mysqld on
       可以通過chkconfig --list mysqld 查看設定狀態,顯示 mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off,2~5顯示On就可以了。
 
  啟動mysql服務, /etc/rc.d.init.d/mysqld start
      Initializing MySQL database:         [ OK ]
      Starting MySQL:              [ OK ]
可以登入mysql進行測試:mysql -u -root                     *(預設root的密碼是空的)
出現提示符“mysql〉”後,設定root的密碼。
以下動作出於安全考慮:
命令列下:mysql> use  mysql;
                    mysql> set password for root@localhost = password('你的密碼');
                    mysql> set password for root@localhost.localdomain=password('你的密碼');
刪除匿名使用者: mysql> delete from user where user='';   
刪除測試資料庫: mysql> drop database test;
至此,mysql資料安裝完成,可以用sql操作mysql測試。
2.安裝apache
命令列下:yum -y install apache
Setting up Install Process
Setting up repositories
....................................
Complete!
接下來配置apache,編輯Apache的設定檔,命令列下:vi /etc/httpd/conf/httpd.conf
#
# Don't give away too much information about all the subcomponents
# we are running. Comment out this line if you don't mind remote sites
# finding out what major optional modules you are running
ServerTokens OS  ← 找到這一行,將“OS”改為“Prod”(在出現錯誤頁的時候不顯示伺服器作業系統的名稱)

ServerTokens Prod   ← 變為此狀態
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#
ServerSignature On  ← 找到這一行,將“On”改為“Off”

ServerSignature Off  ← 在錯誤頁中不顯示Apache的版本
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work. See also the UseCanonicalName directive.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make
# redirections work in a sensible way.
#
#ServerName new.host.name:80  ← 修改主機名稱

ServerName www.linuxidc.com:80  ← 根據實際情況修改,連接埠號碼保持預設的80
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs-2.0/mod/core.html#options
# for more information.
#
DirectoryIndex index.html index.html.var       ←找到這一行,
DirectoryIndex index.html index.php               ← 添加預設index.php檔案

Options Indexes FollowSymLinks  ← 找到這一行,刪除“Indexes”,並添加“Includes”、“ExecCGI”

Options Includes ExecCGI FollowSymLinks  ← 允許伺服器執行CGI及SSI
#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
#AddHandler cgi-script .cgi  ← 找到這一行,去掉行首的“#”,並在行尾添加“.pl”

AddHandler cgi-script .cgi .pl  ← 允許副檔名為.pl的CGI指令碼運行
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None  ← 找到這一行,將“None”改為“All”

AllowOverride All  ← 變為此狀態,允許.htaccess
#
# Specify a default charset for all pages sent out. This is
# always a good idea and opens the door for future internationalisation
# of your web site, should you ever want it. Specifying it as
# a default does little harm; as the standard dictates that a page
# is in iso-8859-1 (latin1) unless specified otherwise i.e. you
# are merely stating the obvious. There are also some security
# reasons in browsers, related to javascript and URL parsing
# which encourage you to always set a default char set.
#
AddDefaultCharset UTF-8  ← 找到這一行,在行首添加“#”

#AddDefaultCharset UTF-8  ← 不使用UTF-8作為網頁的預設編碼
AddDefaultCharset GB2312  ← 並接著添加這一行(添加GB2312為預設編碼)
<Directory "/var/www/icons">  ← 找到這一個標籤,並在標籤中更改相應選項
Options Indexes MultiViews  ← 找到這一行,將“Indexes”刪除

Options MultiViews   ← 變為此狀態(不在瀏覽器上顯示樹狀目錄結構)
AllowOverride None
Order allow,deny
Allow from all
</Directory>
命令列下:  chkconfig httpd on  ← 設定HTTP服務自啟動
                     chkconfig --list httpd
                     httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off   ← 確認2--5為on的狀態就OK
                      /etc/rc.d/init.d/httpd start  ← 啟動HTTP服務
                     Starting httpd:              [ OK ] ← 啟動成功會出現OK
在瀏覽器瀏覽http://127.0.0.1  就可以看到測試頁面出現,表示安裝成功。3.安裝php
命令列下:yum -y install php
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
...............................
..................
Installing: php-pear ######################### [2/2]
Installed: php.i386 0:4.3.9-3.15
Dependency Installed: php-pear.i386 0:4.3.9-3.15
Complete!
安裝完畢,設定檔位於/etc/php.ini。可以修改配置。
4.測試環境
建立一個php檔案,
命令列下:vi  /var/www/html/test.php
輸入代碼:
<?php 
        $host = 'localhost'; 
        $user = 'root'; 
        $pwd = 'password'; 
        $link = mysql_connect( $host, $user, $pwd ); 
        if( !$link ){
               die( '串連失敗' ); 
        }else{ 
               echo '串連成功!'; 
        } 
        mysql_close( $link ); 
?> 
儲存退出,在瀏覽器下瀏覽 http://127.0.0.1/test.php ,可以看到php的相關資訊頁面。
至此,centos上利用yum線上快速搭建php環境就完成了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.