CentOS 6下手動安裝LAMP環境(通用版)

本期教程目錄
1.安裝/配置Apache
2.安裝/配置MySQL
3.安裝/配置PHP

一、安裝/配置Apache

1.更新系統&安裝Apache
yum update
yum install httpd

推薦:使用如下命令備份Apache配置文件
cp /etc/httpd/conf/httpd.conf ~/httpd.conf.backup

為了給大家拓展思路,本次在CentOS上的教程,和大家分享Apache的另外一種綁定域名和創建虛擬機的方式~

2.編輯/etc/httpd/conf.d/vhost.conf,假設我們要綁定example.com和example.org兩個域名,則參照下面內容加入文件,
NameVirtualHost *:80

ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined

ServerAdmin webmaster@example.org
ServerName example.org
ServerAlias www.example.org
DocumentRoot /srv/www/example.org/public_html/
ErrorLog /srv/www/example.org/logs/error.log
CustomLog /srv/www/example.org/logs/access.log combined

3.因為我們上文指定了幾個目錄而這幾個目錄還不存在,所以,使用如下命令創建相應目錄,
mkdir -p /srv/www/example.com/public_html
mkdir /srv/www/example.com/logs

mkdir -p /srv/www/example.org/public_html
mkdir /srv/www/example.org/logs

4.啟動Apache
/etc/init.d/httpd start

日后每次修改vhost.conf文件,都需要使用如下命令使Apache重新載入配置文件
/etc/init.d/httpd reload

5.設置Apache開機啟動
/sbin/chkconfig –levels 235 httpd on

二、安裝/配置MySQL

1.安裝MySQL
yum install mysql-server

2.設置MySQL開機自動啟動
/sbin/chkconfig –levels 235 mysqld on

3.啟動MySQL
/etc/init.d/mysqld start

MySQL的配置文件位于/etc/my.cnf

4.安裝mysql_secure_installation(MySQL安全設置)
mysql_secure_installation

5.附上常用的MySQL命令

登錄MySQL
mysql -u root -p

創建數據庫iaodun(注意MySQL命令行下都需要以;結尾),并將該數據庫所有權限賦予iaodun_user(密碼為123)
create database iaodun;
grant all on iaodun.* to ‘iaodun_user’ identified by ‘123’;

退出MySQL
quit

三、安裝/配置PHP

1.安裝PHP
yum install php php-pear php-mysql

2.編輯配置文件/etc/php.ini,修改如下內容
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off
log_errors = On
error_log = /var/log/php.log
max_execution_time = 300
memory_limit = 64M
register_globals = Off

最后,重啟Apache,大功告成~
/etc/init.d/httpd restart

贊(0)
版權聲明:本文采用知識共享 署名4.0國際許可協議 [BY-NC-SA] 進行授權, 轉載請注明出處。
文章名稱:《CentOS 6下手動安裝LAMP環境(通用版)》
文章鏈接:http://www.lrracing.com/394.html
【聲明】:國外主機測評僅分享信息,不參與任何交易,也非中介,所有內容僅代表個人觀點,均不作直接、間接、法定、約定的保證,讀者購買風險自擔。一旦您訪問國外主機測評,即表示您已經知曉并接受了此聲明通告。
【關于安全】:任何 IDC商家都有倒閉和跑路的可能,備份永遠是最佳選擇,服務器也是機器,不勤備份是對自己極不負責的表現,請保持良好的備份習慣。