本期教程目錄
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



















