PHP APACHE MYSQL 企业应用
PHP 配置文件:/etc/php.in
APACHE 配置文件 :/etc/httpd/conf/httpd.conf
APACHE 日志:/etc/httpd/logs
MYSQL配置文件 :/etc/my.cnf
MYSQL 日志 :/var/log/mysqld.log
服务启动
#service mysqld restart#service php restart
================================================================
- 验证APAHCE 与PHP是否整合
进入httpd.conf 指定的DocumentRoot文件夹,新建php测试文件如下,然后保存退出
#cd /usr/local/htdocs/cici #vi test.php <?php phpinfo(); ?> :wq
浏览器访问 出现如下测试页面,则说明APAHCE与PHP绑定成功
- MYSQL 与 PHP 整合
1 验证php服务与mysql服务交互情况
#cd /usr/local/htdocs/cici #vi mysqltest.php <?php $link=mysql_connect('localhost','root',''); if ($link) echo "yes"; else echo "no"; mysql_close(); ?>
浏览器访问如下网址
http://localhost/mysqltest.php
出现 -- php 没有与MYSQL 成功交互
NO
查看APACHE错误日志
#cd /etc/httpd/logs #less -MN error_log 5 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/msql.so' - /usr/lib/php/ 5 modules/msql.so: cannot open shared object file: No such file or directory in Unknown on line 0 6 PHP Warning: Module 'mysqli' already loaded in Unknown on line 0
2 整合开始
2.1 下载MYSQL PHP支持安装包
URL:http://rpm.pbone.net/index.php3/stat/4/idpl/18074333/dir/redhat_el_6/com/MySQL-shared-compat-5.5.24-1.el6.i686.rpm.html
URL:http://rpm.pbone.net/index.php3?stat=26&dist=74&size=1686808&name=MySQL-shared-5.5.27-1.el6.i686.rpm
2.2 进入相关目录 执行安装命令
#rpm -ivh MySQL-shared-compat-5.5.24-1.el6.i686.rpm #rpm -ivh MySQL-shared-5.5.27-1.el6.i686.rpm
2.3 PHP配置文件修改
#vi /etc/php.ini
注释如下代码
;extension=msql.so
添加如下代码
extension=msql.so extension=mysqli.so
2.4 重新启动服务
#service mysql restart #service httpd restart
2.5
浏览器访问如下网址
http://localhost/mysqltest.php
出现yes -- PHP MYSQL 整合成功
- PHP 项目搭建
1 建立数据库
1.1 将数据库文件放置到宿主与虚拟机共享文件夹内
G:\Program Files\Red Hat Enterprise Linux 4\Exchange Data\programe\incom_db_orignal
data.sql
table.sql
1.2 将文件复制到虚拟机指定目录
cp -r /mnt/hgfs/CentOS\&RHEL4/Exchange\ Data/programe/incom_db_orignal/* /usr/dev/programe/DB/
1.3 进入MYSQL数据库 创建table 和 insert data
#mysql -uroot -p #create database cici Mysql>use cici Mysql>source /usr/dev/programe/DB/table.sql Mysql>source /usr/dev/programe/DB/data.sql
2 导入PHP程序
#cp -r /mnt/hgfs/CentOS\&RHEL4/Exchange\ Data/programe/cici/ /usr/local/htdocs/cici
3 修改PHP连接数据库配置文件
#vi \usr\local\htdocs\incom\include\conn.php
$dbhost = "localhost"; $dbuser = "root"; $dbpass = ""; $dbdatabase = "cici"; $conn=mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error()); mysql_select_db($dbdatabase); mysql_query('set names "GBK"');
4 设计编码方式
4.1 设置数据库编码方式为utf8
#vi /etc/my.cnf
添加如下内容
#修改字符集 character_set_server = utf8
4.2 APACHE服务配置 修改全局编码方式
#vi /etc/httpd/conf/httpd.conf
添加如下内容
AddDefaultCharset GBK
4.3 程序配置文件编码设置
4.3.1
#vi /usr/local/htdocs/cici/include/conn.php
文件内容 Line 11
mysql_query('set names "GBK"');
<!-- [if gte mso 9]><xml><w:WordDocument><w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel><w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery><w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery><w:DocumentKind>DocumentNotSpecified</w:DocumentKind><w:DrawingGridVerticalSpacing>7.8</w:DrawingGridVerticalSpacing><w:View>Normal</w:View><w:Compatibility></w:Compatibility><w:Zoom>0</w:Zoom></w:WordDocument></xml><![endif]-->
4.3.2 检查企业门户程序.php文件编码方式是否为gb2312
文件头一般包含如下信息
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">