Centos6.5下安裝php

安裝phpphp

yum -y install phphtml

重啓httpd服務激活php:
/etc/init.d/httpd restartmysql

測試php是否安裝完成
vim /var/www/html/info.phpc++

<?php
phpinfo();
?>
安裝php的組件:web

搜索php組件:
yum search phpsql

安裝經常使用組件:
yum -y install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc  php-bcmath php-mbstringshell

記得安裝完要重啓httpd服務激活組件:
/etc/init.d/httpd restart數據庫

php配置文件:apache

vi /etc/php.inivim

memory_limit=128M

post_max_size=8M

upload_max_filesize=2M

一條命令安裝

yum -y install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel gettext-devel pcre-devel mysql-devel net-snmp-devel curl-devel perl-DBI mysql mysql-server httpd php php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc  php-bcmath php-mbstring

 

第一步:配置Apache

修改Apache配置文件:vi /etc/httpd/conf/httpd.conf,並在文件中查找下面所在行,進行修改(查找能夠在vi的通常模式下輸入「/要查找的字符」進行查找):

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   (增長同時鏈接數)

 

修改好以後保存配置,從新啓動Apache:/etc/init.d/httpd restart

建議刪除默認的測試頁面:rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html 

第二步:配置PHP

修改PHP配置文件:vi /etc/php.ini,如下須要修改的行的位置能夠經過vi的查找命令來查找:

date.timezone = PRC                    #把前面的分號去掉,改成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

#列出PHP能夠禁用的函數,若是某些程序須要用到這個函數,能夠刪除,取消禁用。

expose_php = Off                                     #禁止顯示php版本的信息

display_errors = OFF                               #關閉錯誤提示
register_globals = OFF                           #關閉註冊全局變量
magic_quotes_gpc = On                        #打開magic_quotes_gpc來防止SQL注入
log_errors = On                                         #記錄錯誤日誌
error_log = /var/log/php/error_log.log   #設置錯誤日誌存放目錄,文件必須容許apache用戶的和組具備寫的權限(注意,在修改以前,要先建立文件/var/log/php/error_log.log,而後在修改其屬性,使其屬於apache用戶和用戶組。chown apache /var/log/php/error_log.log和chgrp apache /var/log/php/error_log.log)

open_basedir = .:/tmp/                             #設置表示容許訪問當前目錄(即PHP腳本文件所在之目錄)和/tmp/目錄,能夠防止php木馬跨站

 

通過安裝和配置以後,web服務器基本上已經搭建起來了,能夠對其進行訪問。

 

測試篇

在目錄/var/www/html下:cd /var/www/html

建立php文件:vi index.php

<?php
phpinfo();
?>

那麼,在瀏覽器中輸入本機地址的時候,就能夠訪問到剛纔建立的index.php網頁文件了。

注意:apache的默認程序目錄是:/var/www/html,網頁文件放在這裏就能夠被訪問到。須要保證這個目錄是屬於用戶apache和用戶組apache的。

         MySQL的數據庫目錄是:/var/lib/mysql

 GPG key retrieval failed: [Errno 14] Could not open/read file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-

今天更新爲163的源後,yum的時候報錯:GPG key retrieval failed: [Errno 14] Could not open/read file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5.

解決方案:vi /etc/yum.repos.d/CentOS-Base.repo 

把文件裏全部的RPM-GPG-KEY-CentOS-5更改成RPM-GPG-KEY-CentOS-6就能夠了

vim 替換 :%s/RPM-GPG-KEY-CentOS-5/RPM-GPG-KEY-CentOS-6

相關文章
相關標籤/搜索