win7系統(tǒng)配置php.html" target="_blank">php+Apache+mysql環(huán)境的方法,大家都了解嗎?php負責解析php代碼,apache負責服務器端,mysql是數(shù)據(jù)交互的中轉站,接下來錯新技術頻道帶大家一起學習,希望大家在實戰(zhàn)中能隨機應變。
第一步:
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)配置文件進行修改-使用記事本打開就行
?????(1)修改ServerRoot Apache的根路徑:
??????? (37行)ServerRoot"c:/Apache24"改成=>ServerRoot "D:/phpEnv/Apache24"
?????(2)修改ServerName你的主機名稱:
??????? 如果此行不修改則啟動apache 提示Starting httpd: AH00558
??????? (217行)ServerName www.example.com:80將前面的#去掉,該屬性在從命令行啟動Apache時需要用到。
???? (3)修改DocumentRoot Apache訪問的主文件夾目錄,就是php、html代碼文件的位置。Apache默認的路徑是在htdocs(D:/phpEnv/Apache24/htdocs)下面,里面會有個簡單的入口文件index.html。這個路徑可以自己進行修改,我這里將其配置在我自己新建的文件夾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項目的入口。Apache默認的入口只有index.html需要添加其他兩個的支持,當然這個入口文件的設置可以根據(jù)自己的需要增減,如果要求比較嚴格的話可以只寫一個index.php,這樣在項目里面的入口就只能是index.php
??????? (274行)<IfModule dir_module>?
??????? DirectoryIndex index.html
?????? </IfModule>
改為=>
?????? <IfModuledir_module>
??????? DirectoryIndex? index.php index.htm index.html
??????? </IfModule>
?? (5)設定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、接下來就可以啟動Apache了
開始---運行,輸入cmd,打開命令提示符。接著進入D:/phpEnv/Apache24/bin目錄下回車httpd回車,如圖所示.
沒有報錯的話就可以測試了(保持該命令窗口為打開的狀態(tài))。
??? 把Apache24/htdocs目錄下的index.html放到D:/phpEnv/www目錄下,用瀏覽器訪問會出現(xiàn)“It works”那么就說明apache已經正確安裝并啟動了。也可以自己寫一個簡單的index.html文件也可以打開。
4、將Apache加入到window服務啟動項里面并設置成開機啟動
先關閉httpd的服務(將命令窗口關閉即可)
重新打開一個新的命令窗口進入到D:/phpEnv/Apache24/bin目錄下:
添加HTTP服務的命令是:httpd.exe -kinstall -n "servicename"? servicename是服務的名稱,我添加的是:httpd.exe -k install -n "Apache24"命令成功后會有成功的提示,此時你可以在window服務啟動項中看到Apache24這個服務
然后點擊啟動就可以了,如果不想設置成開機啟動的話也可以將啟動類型修改為手動。
如果要卸載這個服務的話,先要停止這個服務,然后輸入httpd.exe -k uninstall -n "Apache24"卸載這個服務。
當然也可以通過D:/phpEnv/Apache24/bin下面的ApacheMonitor.exe來啟動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文件復制一份并改名為php.ini他是php的配置文件
3、為Apache服務添加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下面
添加的時候要保證你的php5apache2_4.dll文件確實存在php5.5的早期版本里面是沒有這個文件的,不過高點版本里面已經有了,可以打開php安裝目錄找下這個文件
PHPIniDir"D:/phpEnv/php"這個就是你的php根目錄
4.重啟Apache服務器。
5.測試。
刪除www中其他文件,新建一個index.php,內容為<?php phpinfo(); ?>保存,訪問出現(xiàn)php的信息就說明php已經成功安裝。
備注:
Php的一些常用配置修改:(D:/phpEnv/php/php.ini)
時區(qū)的設置:date.timezone = Asia/Shanghai
錯誤報告等級:error_reporting = E_ALL這個在開發(fā)模式下可以全部打開。
三、安裝配置mysql5.6.16(mysql-5.6.16-winx64.zip)
1、安裝mysql
64位的mysql暫時沒找到msi的安裝包,因此直接解壓到安裝目錄下,然后配置相關的環(huán)境變量,修改配置文件,添加window服務就行,這里就不詳細寫了。這里把我的配置文件貼出來給大家參考下:??
[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ù)存儲目錄。其他的我就不做解釋了
安裝完mysql是沒有圖形用戶界面的,可以安裝個Navicat for MySQL之類的軟件,這樣看起來會比較方便點。
將mysql注冊成為服務:mysqld.exe --install mysql
將mysql服務進行刪除: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的擴展支持,ext文件夾下有很多php的擴展支持.dll文件,感興趣的同學可以看一下。
(2)然后就是打開php的mysql擴展了
??? (875、876行)去掉前面的“;”
extension=php_mysql.dll extension=php_mysqli.dll
當然也可以打開881行的php_pdo_mysql.dll啟用php的pdo支持我一般都用這個。
注:在第863行到第888行有很多擴展選擇,你要用到什么,去掉前面的“;”就可以了。當然如果要添加其他的擴展支持如redis支持,php本身可能沒有提供相應的dll文件,就需要自己去找到相應版本的dll添加到ext文件夾中,然后在配置文件中添加一個extension=…
完成之后,重啟Apache
3)、啟動MySQL服務
net start mysql
MySQL服務正在啟動 .
MySQL服務無法啟動。
4)、登陸MySQL服務器
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,密碼默認為空。
5)、查看數(shù)據(jù)庫
mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || test |+--------------------+3 rows in set (0.02 sec)
可以看到MySQL服務器中有三個數(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)
刪除后查詢操作結果:
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
查看更新結果:
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)建一個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服務器才可以生效。
net stop mysql
MySQL 服務正在停止..
MySQL 服務已成功停止。
net start mysql
MySQL 服務正在啟動 .
MySQL 服務已經啟動成功。
7、重新登陸MySQL服務器
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)不能啟動mysql的1067錯誤,則可以使用以下辦法解決:
使用cmd命令:D:/Appserv/mysql/bin/mysqladmin -uroot -p shutdown,然后輸入密碼,再net start mysql 就沒有這個錯誤提示了!
四、數(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、啟動MySQL服務器
2、登陸數(shù)據(jù)庫服務器
3、使用某個要操作的數(shù)據(jù)庫
4、操作該數(shù)據(jù)庫中的表,可執(zhí)行增刪改查各種操作。
5、退出登陸。
以上就是win7系統(tǒng)配置php+Apache+mysql環(huán)境的方法,建議大家好好品讀,相信對你是有用的,更多的專業(yè)技術的知識盡在錯新技術頻道!
新聞熱點
疑難解答
圖片精選