win7系統(tǒng)配置php.html" target="_blank">php+Apache+mysql環(huán)境的方法,大家都了解嗎?php負(fù)責(zé)解析php代碼,apache負(fù)責(zé)服務(wù)器端,mysql是數(shù)據(jù)交互的中轉(zhuǎn)站,接下來錯(cuò)新技術(shù)頻道帶大家一起學(xué)習(xí),希望大家在實(shí)戰(zhàn)中能隨機(jī)應(yīng)變。
第一步:
php-5.5.10-Win32-VC11-x64.zip?
httpd-2.4.7-win64-VC11.zip?
mysql-5.6.16-winx64.zip?
第二步:
安裝配置Apache2.4.7(httpd-2.4.7-win64-VC11.zip )
1、解壓下載的安裝包:httpd-2.4.7-win64-VC11.zip將其放到自己的安裝目錄(我的目錄D:/phpEnv/Apache24)

2.然后對http.conf(D:/phpEnv/Apache24/conf/http.conf)配置文件進(jìn)行修改-使用記事本打開就行
?????(1)修改ServerRoot Apache的根路徑:
??????? (37行)ServerRoot"c:/Apache24"改成=>ServerRoot "D:/phpEnv/Apache24"
?????(2)修改ServerName你的主機(jī)名稱:
??????? 如果此行不修改則啟動(dòng)apache 提示Starting httpd: AH00558
??????? (217行)ServerName www.example.com:80將前面的#去掉,該屬性在從命令行啟動(dòng)Apache時(shí)需要用到。
???? (3)修改DocumentRoot Apache訪問的主文件夾目錄,就是php、html代碼文件的位置。Apache默認(rèn)的路徑是在htdocs(D:/phpEnv/Apache24/htdocs)下面,里面會(huì)有個(gè)簡單的入口文件index.html。這個(gè)路徑可以自己進(jìn)行修改,我這里將其配置在我自己新建的文件夾www(D:/phpEnv/www)下。
????????? (247行) DocumentRoot "c:/Apache24/htdocs"
??????? <Directory "c:/Apache24/htdocs">
改為=>
??????? DocumentRoot "D:/phpEnv/www"
??????? <Directory "D:/phpEnv/www">
??? (4)修改入口文件配置:DirectoryIndex一般情況下我們都是以index.php、index.html、index.htm作為web項(xiàng)目的入口。Apache默認(rèn)的入口只有index.html需要添加其他兩個(gè)的支持,當(dāng)然這個(gè)入口文件的設(shè)置可以根據(jù)自己的需要增減,如果要求比較嚴(yán)格的話可以只寫一個(gè)index.php,這樣在項(xiàng)目里面的入口就只能是index.php
??????? (274行)<IfModule dir_module>?
??????? DirectoryIndex index.html
?????? </IfModule>
改為=>
?????? <IfModuledir_module>
??????? DirectoryIndex? index.php index.htm index.html
??????? </IfModule>
?? (5)設(shè)定serverscript的目錄:
??????? (358行)ScriptAlias/cgi-bin/ "c:/Apache24/cgi-bin/"改為=> ScriptAlias/cgi-bin/ "D:/phpEnv/Apache24/cgi-bin"
? (6)(380行)
??????? <Directory "c:/Apache24/cgi-bin">
????????? AllowOverride None
????????? Options None
????????? Require all granted
??????? </Directory>
改為=>
??????? <Directory "D:/phpEnv/Apache24/cgi-bin">
????????? AllowOverride None
????????? Options None
????????? Require all granted
??????? </Directory>
3、接下來就可以啟動(dòng)Apache了
開始---運(yùn)行,輸入cmd,打開命令提示符。接著進(jìn)入D:/phpEnv/Apache24/bin目錄下回車httpd回車,如圖所示.
沒有報(bào)錯(cuò)的話就可以測試了(保持該命令窗口為打開的狀態(tài))。
??? 把Apache24/htdocs目錄下的index.html放到D:/phpEnv/www目錄下,用瀏覽器訪問會(huì)出現(xiàn)“It works”那么就說明apache已經(jīng)正確安裝并啟動(dòng)了。也可以自己寫一個(gè)簡單的index.html文件也可以打開。

4、將Apache加入到window服務(wù)啟動(dòng)項(xiàng)里面并設(shè)置成開機(jī)啟動(dòng)
先關(guān)閉httpd的服務(wù)(將命令窗口關(guān)閉即可)
重新打開一個(gè)新的命令窗口進(jìn)入到D:/phpEnv/Apache24/bin目錄下:
添加HTTP服務(wù)的命令是:httpd.exe -kinstall -n "servicename"? servicename是服務(wù)的名稱,我添加的是:httpd.exe -k install -n "Apache24"命令成功后會(huì)有成功的提示,此時(shí)你可以在window服務(wù)啟動(dòng)項(xiàng)中看到Apache24這個(gè)服務(wù)
然后點(diǎn)擊啟動(dòng)就可以了,如果不想設(shè)置成開機(jī)啟動(dòng)的話也可以將啟動(dòng)類型修改為手動(dòng)。
如果要卸載這個(gè)服務(wù)的話,先要停止這個(gè)服務(wù),然后輸入httpd.exe -k uninstall -n "Apache24"卸載這個(gè)服務(wù)。
當(dāng)然也可以通過D:/phpEnv/Apache24/bin下面的ApacheMonitor.exe來啟動(dòng)Apache這里就不多說了
如此Apache的配置就基本完成了。
?
二、安裝配置php5.5.10(php-5.5.10-Win32-VC11-x64.zip)
1、將下載的php-5.5.10-Win32-VC11-x64.zip? 解壓到安裝目錄下我的是(D:/phpEnv/php)
2、將目錄下的php.ini-development文件復(fù)制一份并改名為php.ini他是php的配置文件
3、為Apache服務(wù)添加php支持
打開Apache的配置文件http.conf在最后加上
# php5 supportLoadModule php5_module “D:/phpEnv/php/php5apache2_4.dll”AddHandler application/x-httpd-php .phpAddType application/x-httpd-php .html .htm# configure thepath to php.iniPHPIniDir "D:/phpEnv/php"
這里我添加在LoadModule下面
添加的時(shí)候要保證你的php5apache2_4.dll文件確實(shí)存在php5.5的早期版本里面是沒有這個(gè)文件的,不過高點(diǎn)版本里面已經(jīng)有了,可以打開php安裝目錄找下這個(gè)文件
PHPIniDir"D:/phpEnv/php"這個(gè)就是你的php根目錄

4.重啟Apache服務(wù)器。
5.測試。
刪除www中其他文件,新建一個(gè)index.php,內(nèi)容為<?php phpinfo(); ?>保存,訪問出現(xiàn)php的信息就說明php已經(jīng)成功安裝。
備注:
Php的一些常用配置修改:(D:/phpEnv/php/php.ini)
時(shí)區(qū)的設(shè)置:date.timezone = Asia/Shanghai
錯(cuò)誤報(bào)告等級:error_reporting = E_ALL這個(gè)在開發(fā)模式下可以全部打開。
三、安裝配置mysql5.6.16(mysql-5.6.16-winx64.zip)
1、安裝mysql
64位的mysql暫時(shí)沒找到msi的安裝包,因此直接解壓到安裝目錄下,然后配置相關(guān)的環(huán)境變量,修改配置文件,添加window服務(wù)就行,這里就不詳細(xì)寫了。這里把我的配置文件貼出來給大家參考下:??
[mysqld] loose-default-character-set = utf8 basedir = D:/program/mysql-5.6 datadir = D:/program/mysql-5.6/data port = 3306 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES character_set_server = utf8 [client] loose-default-character-set = utf8
注:basedir是mysql的根目錄,datadir是mysql的數(shù)據(jù)存儲(chǔ)目錄。其他的我就不做解釋了
安裝完mysql是沒有圖形用戶界面的,可以安裝個(gè)Navicat for MySQL之類的軟件,這樣看起來會(huì)比較方便點(diǎn)。
將mysql注冊成為服務(wù):mysqld.exe --install mysql
將mysql服務(wù)進(jìn)行刪除:mysqld.exe --remove mysql
2、安裝完成mysql之后,為php添加mysql支持
打開php的配置文件php.ini(D:/phpEnv/php/php.ini)
(1)(721行); extension_dir = "ext",去掉前面的“;”,并改為extension_dir ="D:/phpEnv/php/ext"打開php的擴(kuò)展支持,ext文件夾下有很多php的擴(kuò)展支持.dll文件,感興趣的同學(xué)可以看一下。
(2)然后就是打開php的mysql擴(kuò)展了
??? (875、876行)去掉前面的“;”
extension=php_mysql.dll extension=php_mysqli.dll
當(dāng)然也可以打開881行的php_pdo_mysql.dll啟用php的pdo支持我一般都用這個(gè)。
注:在第863行到第888行有很多擴(kuò)展選擇,你要用到什么,去掉前面的“;”就可以了。當(dāng)然如果要添加其他的擴(kuò)展支持如redis支持,php本身可能沒有提供相應(yīng)的dll文件,就需要自己去找到相應(yīng)版本的dll添加到ext文件夾中,然后在配置文件中添加一個(gè)extension=…
完成之后,重啟Apache
3)、啟動(dòng)MySQL服務(wù)
net start mysql
MySQL服務(wù)正在啟動(dòng) .
MySQL服務(wù)無法啟動(dòng)。
4)、登陸MySQL服務(wù)器
mysql -uroot -pEnter password:Welcome to the MySQL monitor. Commands end with ; or /g.Your MySQL connection id is 1Server version: 5.1.32-community MySQL Community Edition (GPL)Type 'help;' or '/h' for help. Type '/c' to clear the buffer.mysql>
注意:MySQL的管理員用戶名為root,密碼默認(rèn)為空。
5)、查看數(shù)據(jù)庫
mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || test |+--------------------+3 rows in set (0.02 sec)
可以看到MySQL服務(wù)器中有三個(gè)數(shù)據(jù)庫。
6)、使用數(shù)據(jù)庫
mysql> use testDatabase changed
7)、查看數(shù)據(jù)庫中的表
mysql> show tables;Empty set (0.00 sec)
8)、創(chuàng)建表ttt
mysql> create table ttt(a int,b varchar(20)); Query OK, 0 rows affected (0.00 sec)
9)、插入三條數(shù)據(jù)
mysql> insert into ttt values(1,'aaa'); Query OK, 1 row affected (0.02 sec)mysql> insert into ttt values(2,'bbb'); Query OK, 1 row affected (0.00 sec)mysql> insert into ttt values(3,'ccc'); Query OK, 1 row affected (0.00 sec)
10)、查詢數(shù)據(jù)
mysql> select * from ttt;+------+------+| a | b |+------+------+| 1 | aaa || 2 | bbb || 3 | ccc |+------+------+3 rows in set (0.00 sec)
11)、刪除數(shù)據(jù)
mysql> delete from ttt where a=3;Query OK, 1 row affected (0.01 sec)
刪除后查詢操作結(jié)果:
mysql> select * from ttt; +------+------+| a | b |+------+------+| 1 | aaa || 2 | bbb |+------+------+2 rows in set (0.00 sec)
12)、更新數(shù)據(jù)
mysql> update ttt set b = 'xxx' where a =2;Query OK, 1 row affected (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 0
查看更新結(jié)果:
mysql> select * from ttt; +------+------+| a | b |+------+------+| 1 | aaa || 2 | xxx |+------+------+2 rows in set (0.00 sec)
13)、刪除表
mysql> drop table ttt; Query OK, 0 rows affected (0.00 sec)
查看數(shù)據(jù)庫中剩余的表:
mysql> show tables;Empty set (0.00 sec)
三、更改MySQL數(shù)據(jù)庫root用戶的密碼
1、使用mysql數(shù)據(jù)庫
mysql> use mysqlDatabase changed
2、查看mysql數(shù)據(jù)庫中所有的表
mysql>show tables; +---------------------------+| Tables_in_mysql |+---------------------------+| columns_priv || db || func || help_category || help_keyword || help_relation || help_topic || host || proc || procs_priv || tables_priv || time_zone || time_zone_leap_second || time_zone_name || time_zone_transition || time_zone_transition_type || user |+---------------------------+17 rows in set (0.00 sec)
3、刪除mysql數(shù)據(jù)庫中用戶表的所有數(shù)據(jù)
mysql> delete from user; Query OK, 3 rows affected (0.00 sec)
4、創(chuàng)建一個(gè)root用戶,密碼為"xiaohui"。
mysql>grant all on *.* to root@'%' identified by 'xiaohui' with grant option; Query OK, 0 rows affected (0.02 sec)
5、查看user表中的用戶
mysql> select User from user; +------+| User |+------+| root |+------+1 row in set (0.00 sec)
6、重啟MySQL:更改了MySQL用戶后,需要重啟MySQL服務(wù)器才可以生效。
net stop mysql
MySQL 服務(wù)正在停止..
MySQL 服務(wù)已成功停止。
net start mysql
MySQL 服務(wù)正在啟動(dòng) .
MySQL 服務(wù)已經(jīng)啟動(dòng)成功。
7、重新登陸MySQL服務(wù)器
mysql -uroot -pxiaohui Welcome to the MySQL monitor. Commands end with ; or /g.Your MySQL connection id is 1Server version: 5.1.32-community MySQL Community Edition (GPL)Type 'help;' or '/h' for help. Type '/c' to clear the buffer.mysql>
?
如果修改密碼后net startmysql出現(xiàn)不能啟動(dòng)mysql的1067錯(cuò)誤,則可以使用以下辦法解決:
使用cmd命令:D:/Appserv/mysql/bin/mysqladmin -uroot -p shutdown,然后輸入密碼,再net start mysql 就沒有這個(gè)錯(cuò)誤提示了!
四、數(shù)據(jù)庫的創(chuàng)建與刪除
1、創(chuàng)建數(shù)據(jù)庫testdb
mysql> create database testdb;Query OK, 1 row affected (0.02 sec)
2、使用數(shù)據(jù)庫testdb
mysql> use testdb;Database changed
3、刪除數(shù)據(jù)庫testdb
mysql> drop database testdb; Query OK, 0 rows affected (0.00 sec)
4、退出登陸
mysql>exit ByeC:/Documents and Settings/Administrator>
五、操作數(shù)據(jù)庫數(shù)據(jù)的一般步驟
1、啟動(dòng)MySQL服務(wù)器
2、登陸數(shù)據(jù)庫服務(wù)器
3、使用某個(gè)要操作的數(shù)據(jù)庫
4、操作該數(shù)據(jù)庫中的表,可執(zhí)行增刪改查各種操作。
5、退出登陸。
以上就是win7系統(tǒng)配置php+Apache+mysql環(huán)境的方法,建議大家好好品讀,相信對你是有用的,更多的專業(yè)技術(shù)的知識盡在錯(cuò)新技術(shù)頻道!
新聞熱點(diǎn)
疑難解答
圖片精選