1. 程式人生 > >linux下LAMP安裝與配置

linux下LAMP安裝與配置

函數 rri osi ase live ins php expose share

安裝

一. Apache

安裝

yum install -y httpd
啟動

/etc/init.d/httpd start
備註:Apache啟動之後會提示錯誤: 正在啟動httpd:httpd: Could not reliably determine the server’s fully qualif domain name, using ::1 for ServerName
解決辦法:
vi /etc/httpd/conf/httpd.conf #編輯

找到 #ServerName www.example.com:80

修改為ServerName www.1000seo.com:80 #這裏設置為你自己的域名,

如果沒有域名,可以設置為localhost

:wq! #保存退出

設置開機啟動

chkconfig httpd on
重啟

/etc/init.d/httpd restart
停止

/etc/init.d/httpd stop
小技巧

針對上邊的命令可能不太好記憶,可以將這些命令導入到環境變量裏
vim ~/.bash_profile

alias httpd_start=‘/etc/init.d/httpd start‘
alias httpd_stop=‘/etc/init.d/httpd stop‘
alias httpd_restart=‘/etc/init.d/httpd restart‘

source ~/.bash_profile

二 .MySql

安裝

yum install -y MySQL mysql-server
啟動

/etc/init.d/mysqld start
開機啟動

chkconfig mysqld on
復制配置文件

cp /usr/share/mysql/my-medium.cnf /etc/my.cnf #拷貝配置文件(註意:如果/etc目錄下面默認有一個my.cnf,根據提示覆蓋即可)
設置root賬戶密碼

mysql_secure_installation
回車,根據提示輸入Y 輸入2次密碼,回車 根據提示一路輸入Y 最後出現:Thanks for using MySQL! MySql密碼設置完成
mysql啟動命令

/etc/init.d/mysqld restart #重啟

/etc/init.d/mysqld stop #停止

/etc/init.d/mysqld start #啟動

如果命令不好記憶,可以借鑒上文中的apache的環境變量配置

三. php

安裝

yum install -y PHP
組件安裝

yum install -y 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
重啟mysql和apache

mysql_restart restart #重啟MySql

httpd_restart restart #重啟Apche
配置

apache配置

vi /etc/httpd/conf/httpd.conf #編輯文件 ServerTokens OS  #在44行

修改為:ServerTokens Prod (在出現錯誤頁的時候不顯示服務器操作系統的名稱)

ServerSignature On #在536行

修改為:ServerSignature Off (在錯誤頁中不顯示Apache的版本)

Options Indexes FollowSymLinks #在331行

修改為:Options Includes ExecCGI FollowSymLinks(允許服務器執行CGI及SSI,禁止列出目錄)

#AddHandler cgi-script .cgi #在796行

修改為:AddHandler cgi-script .cgi .pl (允許擴展名為.pl的CGI腳本運行)

AllowOverride None #在338行

修改為:AllowOverride All (允許.htaccess)

AddDefaultCharset UTF-8 #在759行

修改為:AddDefaultCharset GB2312 (添加GB2312為默認編碼)

Options Indexes MultiViews FollowSymLinks #在554行

修改為Options MultiViews FollowSymLinks(不在瀏覽器上顯示樹狀目錄結構)

DirectoryIndex index.html index.html.var #在402行 修改為:

DirectoryIndex index.html index.htm Default.html Default.htm index.php Default.php index.html.var (設置默認首頁文件,增加index.php)

KeepAlive Off #在76行

修改為:KeepAlive On (允許程序性聯機)

MaxKeepAliveRequests 100 #在83行

修改為:MaxKeepAliveRequests 1000 (增加同時連接數)

:wq! #保存退出

/etc/init.d/httpd restart #重啟

rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html #刪除默認測試頁

php配置

vi /etc/php.ini

#編輯 date.timezone = PRC #在946行

把前面的分號去掉,改為date.timezone = Asia/Shanghai

#在386行 列出PHP可以禁用的函數,如果某些程序需要用到這個函數,可以刪除,取消禁用。
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

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/www.bamaol.com/:/tmp/

:wq! #保存退出

/etc/init.d/mysqld restart #重啟MySql

/etc/init.d/httpd restart #重啟Apche

三. 測試

cd /var/www/html

vi index.php #編輯輸入下面內容

<?php phpinfo(); ?>

:wq! #保存退出
上文中的配置可以簡化一些,這個需要根據個人的喜好進行配置,比如我喜歡將目錄樹進行展示出來,這裏沒有給出DocumentRoot目錄,可以在php.ini文件中查看,如果想要配置,修改即可

linux下LAMP安裝與配置