溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

CentOS使用本地yum源搭建LAMP環(huán)境的方法

發(fā)布時間:2022-05-07 16:22:20 來源:億速云 閱讀:113 作者:iii 欄目:大數(shù)據(jù)

今天小編給大家分享一下CentOS使用本地yum源搭建LAMP環(huán)境的方法的相關(guān)知識點,內(nèi)容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。

【準(zhǔn)備工作】

配置防火墻,開啟80端口、3306端口

vi /etc/sysconfig/iptables

如圖,添加下面兩條:

-a input -m state --state new -m tcp -p tcp --dport 80 -j accept #允許80端口通過防火墻

-a input -m state --state new -m tcp -p tcp --dport 3306 -j accept #允許3306端口通過防火墻

CentOS使用本地yum源搭建LAMP環(huán)境的方法

重啟防火墻使配置生效

/etc/init.d/iptables restart

關(guān)閉selinux

vi /etc/selinux/config
#selinux=enforcing #注釋掉
#selinuxtype=targeted #注釋掉
selinux=disabled #增加
:wq! #保存退出

重啟系統(tǒng)

shutdown -r now

【安裝apache】

執(zhí)行安裝

yum -y install httpd

啟動apache

service httpd restart

或:

/etc/init.d/httpd start

apache啟動之后會提示錯誤could not reliably determine the server's fully qualifdomain name, using ::1 for servername,解決方法:

vi /etc/httpd/conf/httpd.conf

找到 #servername www.example.com:80
修改為 servername www.lws.com:80  (設(shè)置為自己的域名 或 servername localhost:80
:wq!#保存退出

設(shè)為開機啟動

chkconfig httpd on

檢查安裝 訪問主機地址 如圖所示安裝成功

CentOS使用本地yum源搭建LAMP環(huán)境的方法

修改apache配置

vi /etc/httpd/conf/httpd.conf #建議使用ftp工具 修改之前做好備份

修改如下:

servertokens os  #在44行 修改為:servertokens prod (在出現(xiàn)錯誤頁的時候不顯示服務(wù)器操作系統(tǒng)的名稱)
serversignature on  #在536行修改為:serversignature off (在錯誤頁中不顯示apache的版本)
options indexes followsymlinks  #在331行修改為:options includes execcgi followsymlinks(允許服務(wù)器執(zhí)行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?。ㄌ砑觛b2312為默認(rèn)編碼)
options indexes multiviews followsymlinks #在554行 修改為options multiviews followsymlinks(不在瀏覽器上顯示樹狀目錄結(jié)構(gòu))
directoryindex index.html index.html.var #在402行 修改為:directoryindexindex.html index.htm default.html default.htm index.php default.phpindex.html.var (設(shè)置默認(rèn)首頁文件,增加index.php)
keepalive off #在76行 修改為:keepalive on (允許程序性聯(lián)機)
maxkeepaliverequests 100 #在83行 修改為:maxkeepaliverequests1000 (增加同時連接數(shù))

刪除兩個默認(rèn)測試頁

rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html

重啟apache

service httpd restart

/etc/init.d/httpd restart

【安裝mysql

執(zhí)行安裝

yum -y install mysql mysql-server

啟動mysql

/etc/init.d/mysqld start

設(shè)為開機啟動

chkconfig mysqld on

拷貝配置文件(注意:如果/etc目錄下面默認(rèn)有一個my.cnf,直接覆蓋即可)

cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

為root賬戶設(shè)置密碼

mysql_secure_installation
#回車,根據(jù)提示輸入y,輸入2次密碼,回車,根據(jù)提示一路輸入y最后出現(xiàn):thanks for using mysql設(shè)置完成

或者

mysqladmin -u root password '密碼'

允許遠程登錄

mysql -u root -p

輸入密碼
輸入mysql命令:

grant all privileges on *.* to 'root'@'%' identified by '密碼' with grant option;

退出mysql:exit

重啟mysql

service mysqld restart

【安裝php5】

執(zhí)行安裝

yum -y install php

安裝php組件(這里選擇以下安裝包,根據(jù)提示輸入y回車安裝)

復(fù)制代碼 代碼如下:

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

修改php配置

vi /etc/php.ini #建議使用ftp工具 修改之前做好備份

修改如下:

date.timezone= prc #在946行 把前面的分號去掉,改為date.timezone = prc

復(fù)制代碼 代碼如下:

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可以禁用的函數(shù),如果某些程序需要用到這個函數(shù),可以刪除,取消禁用。

expose_php = off #在432行 禁止顯示php版本的信息
magic_quotes_gpc = on #在745行 打開magic_quotes_gpc來防止sql注入
short_open_tag = on #在229行支持php短標(biāo)簽
open_basedir = .:/tmp/
#在380行 設(shè)置表示允許訪問當(dāng)前目錄(即php腳本文件所在之目錄)和/tmp/目錄,可以防止php木馬跨站,如果改了之后安裝程序有問題,可以注銷此行,或者直接寫上程序的目錄/data/www.osyunwei.com/:/tmp/

重啟mysql、apahe

service mysqld restart
service httpd restart

(到此完成yum源搭建lamp環(huán)境,我們可以查看一下各部分的安裝版本)

查看apache版本

httpd -v

CentOS使用本地yum源搭建LAMP環(huán)境的方法

查看php版本

php –v

CentOS使用本地yum源搭建LAMP環(huán)境的方法

查看mysql版本

mysql -v

(注意大寫)

CentOS使用本地yum源搭建LAMP環(huán)境的方法

以上就是“CentOS使用本地yum源搭建LAMP環(huán)境的方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學(xué)習(xí)更多的知識,請關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI