centos下利用yum安裝LAMP(Linux+Apache+MySQL+PHP)及配置

來源:互聯網
上載者:User

標籤:

先說下我的實踐配置,centos6.5(64位),連網

安裝前準備:關閉防火牆 service iptables stop

  • 安裝MySQL

開啟終端,root使用者

yum install mysql mysql-server

 安裝完畢,設定MySQL自啟動

chkconfig --levels 235 mysqld on/etc/init.d/mysqld start   //或者service mysqld start

 設定MySQL root賬戶的密碼(我沒有建立MySQL使用者,就用root賬戶了),輸入以下

mysql_secure_installation

 出現以下提示時

Enter current paaword for root

因為我們root密碼為空白,所以直接斷行符號

之後按照提示,輸入新密碼,確認,最後會有四個確認,直接斷行符號就行

  • 安裝Apache
yum install httpd

 配置自啟動

chkconfig --levels 235 httpd on
service httpd start

 此時啟動可能會出現以下錯誤

正在啟動httpd:httpd:could not reliably determine the server‘s fully qualif domain name,

using::1 for servername

解決方案:

我們要修改/etc/httpd/conf/httpd.conf檔案

進入vi修改狀態,找到#ServerName www.example.com:80

取消#,並修改為ServerName 網域名稱:80(如果沒有網域名稱的話,就設為localhost)

wq!儲存退出

service httpd start或restart

 重啟httpd,此時你就可以訪問你的伺服器了,輸入localhost,出現一個Apache test page powered by centos的測試頁面

  • 安裝PHP

同樣輸入命令

yum install php

 直接一路安裝,安裝完成之後我們需要再次重啟httpd服務

重啟之後我們進行測試PHP相關資訊,我們建立一個PHP介面進行測試

vi  /var/www/html/info.php
按 i 進行編輯,輸入:
<?php
phpinfo();
?>

 編輯完畢,儲存退出

此時我們訪問這個頁面,輸入localhost/info.php,就會出現一個現實PHP資訊的網頁,說明你的PHP安裝成功了

  • 將PHP模組和MySQL模組關聯起來

在這個步驟中,我們要安裝相關模組

首先搜尋模組

yum search php(在網上看到的步驟,並不知道有什麼卵用)

 之後安裝相關模組

yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml  php-xmlrpc

 網上也有以下安裝包的,我當時選擇的是上面的,應該是都可以的

yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt 本篇文章來源於 Linux公社網站(www.linuxidc.com)  原文連結:http://www.linuxidc.com/Linux/2014-12/111030.htm

 

安裝完成,重啟mysqld,重啟httpd

再次訪問剛才的info.php,我們發現已經多了MySQL的相關資訊(不貼圖了)

  • LAMP配置

   Apache配置

vi /etc/httpd/conf/httpd.conf #編輯檔案
ServerTokens OS 修改為:ServerTokens Prod (在出現錯誤頁的時候不顯示伺服器作業系統的名稱)
ServerSignature On  修改為:ServerSignature Off (在錯誤頁中不顯示Apache的版本)
Options Indexes FollowSymLinks  修改為:Options Includes ExecCGI FollowSymLinks(允許伺服器執行CGI及SSI,禁止列出目錄)
#AddHandler cgi-script .cgi 修改為:AddHandler cgi-script .cgi .pl (允許副檔名為.pl的CGI指令碼運行)
AllowOverride None  修改為:AllowOverride All (允許.htaccess)
AddDefaultCharset UTF-8 修改為:AddDefaultCharset GB2312 (添加GB2312為預設編碼)
Options Indexes MultiViews FollowSymLinks     修改為 Options MultiViews FollowSymLinks(不在瀏覽器上顯示樹狀目錄結構)
DirectoryIndex index.html index.html.var     修改為:DirectoryIndex index.html index.htm Default.html Default.htm index.php Default.php index.html.var (設定預設首頁檔案,增加index.php)
KeepAlive Off      修改為:KeepAlive On (允許程式性聯機)
MaxKeepAliveRequests 100     修改為:MaxKeepAliveRequests 1000 (增加同時串連數)
:wq! #儲存退出
/etc/init.d/httpd restart#重啟
  PHP配置

vi /etc/php.ini #編輯
date.timezone = PRC #在946行 把前面的分號去掉,改為date.timezone = PRC
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,

popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,

posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#在386行 列出PHP可以禁用的函數,如果某些程式需要用到這個函數,可以刪除,取消禁用。
expose_php = Off #在432行 禁止顯示php版本的資訊
magic_quotes_gpc = On #在745行 開啟magic_quotes_gpc來防止SQL注入
short_open_tag = ON #在229行支援php短標籤
open_basedir = .:/tmp/ #在380行 設定表示允許訪問目前的目錄(即PHP指令檔所在之目錄)和/tmp/目錄,可以防止php木馬跨站

,如果改了之後安裝程式有問題,可以登出此行,或者直接寫上程式的目錄/data/網域名稱/:/tmp/
:wq! #儲存退出
/etc/init.d/mysqld restart #重啟MySql
/etc/init.d/httpd restart #重啟Apche

  • 配置讓Apache可以解析php
vi /etc/httpd/conf/httpd.conf
添加
Addtype application/x-httpd-php .php .phtml
Addtype application/x-httpd-php-source .phps
  •  

 

centos下利用yum安裝LAMP(Linux+Apache+MySQL+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.