apache php mysql
1 php部分
//修改PHP的默认时区
php.ini
[Date]
date.timezone = "Asia/Shanghai"
//若php不支持mysql的函数,在确认PHP已配置好环境变量的情况下,先重启一下电脑,再试试。
//php.ini配置中默认是关闭scandir函数的,使用时需要修改php.ini文件。
2 mysql部分
windows新版本问题
mysqld.exe --initialize-insecure --user=mysql
mysqld --install
如果用service mysqld start无法启动mysql,试试用/etc/init.d/mysqld start来启动mysql
如果apache已经支持php,但无法连接mysql,执行以下操作
1 yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
2 /etc/init.d/httpd restart
创建数据库及导入数据
CREATE DATABASE IF NOT EXISTS yourdbname DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
use testdb;
source /var/test.sql;
//mysql修改root密码
UPDATE user SET password=PASSWORD('123456') WHERE user='root';//新版本是 authentication_string
FLUSH PRIVILEGES;
//为远程连接赋权限
//grant 权限(select,insert,update,delete) on (数据库).(表) to 用户@'主机' identified by '密码'
grant all privileges on *.* to root@'%' identified by "root";
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
//创建用户test,只能从本机联入,只能访问book库,密码是abc
grant select,insert,update,delete on book.* to test@localhost Identified by "abc";
//mysql数据库连接的demo
<?php $con=mysql_connect("127.0.0.1","root","123456"); mysql_select_db("mysql",$con); $res=mysql_query("select host from user"); while($row=mysql_fetch_array($res)){ echo $row['host']."<br>"; } mysql_close($con); ?>
3
//apache 多站点配置
修改httpd.conf
打开LoadModule vhost_alias_module modules/mod_vhost_alias.so
打开Include conf/extra/httpd-vhosts.conf
修改Listen 80为Listen 8081 Listen 8082 ...
修改DocumentRoot "你想指定的本地目录"
修改<Directory "你想指定的本地目录">
修改extra\httpd-vhosts.conf 添加如下的段
<VirtualHost *:8081>
DocumentRoot "C:/www/blog"
ServerName localhost
</VirtualHost>
//apache配置以支持yii路径路由
打开LoadModule rewrite_module modules/mod_rewrite.so
//apache加入对PHP的支持
修改httpd.conf,加入以下代码
PHPIniDir "C:\Program Files\PHP\"
LoadModule php5_module "C:\Program Files\PHP\php5apache2_2.dll"