1. Centos 默認是打開IP安全策略的,也就是80端口也禁止外部訪問,所以先停用iptables.
service iptables stop
或者對80端口開放
iptables -I RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
2. 安裝apache
yum install httpd (只安裝apache),如果要安裝其它插件可以
yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql
安裝後的網頁位置是 /var/www/html
3. 安裝mysql
yum install mysql mysql-server mysql-devel
安裝完成以後,運行mysql 可能出現以下錯誤:Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock 這個錯誤的原因有很多種,一種這個時候/var/lib/mysql/目錄下找不到mysql.sock這個文件,可以運行 service mysqld start 或 (/etc/init.d/mysqld start) 如果成功啟動mysql,那麼會在/var/lib/mysql/目錄下生成mysql.sock文件的,這個時候就將mysql 設置系統啟動時,自動啟動,否則又會重復Can't connect to local MySQL server through socket 錯誤。自動啟動命令如下: chkconfig mysqld on
系統默認不會設置密碼的,就是空密碼,如果要設置mysql 密碼,假設密碼設置為123456
mysqladmin -u root password 123456
如果要開通外部訪問mysql,就要設置用戶可供外部訪問
mysql> GRANT ALL PRIVILEGES ON *.* TO '用戶名'@'地址' IDENTIFIED BY '密碼' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
例子,允許root 用戶用123456密碼192.168.6.6 連接
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root'@'192.168.6.6' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
例子,允許所有外部,用戶root 密碼123456 連接數據庫
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
例子,允許IP為192.168.6.6 ,用戶root 密碼123456 連接USER數據庫
mysql> GRANT ALL PRIVILEGES ON USER.* TO ‘root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
4. 安裝php
yum install php php-mysql php-common php-gd php-mbstring php-mcrtpt php-devel php-xml