《PHP學(xué)習(xí):win7系統(tǒng)配置php+Apache+mysql環(huán)境的方法》要點(diǎn):
本文介紹了PHP學(xué)習(xí):win7系統(tǒng)配置php+Apache+mysql環(huán)境的方法,希望對您有用。如果有疑問,可以聯(lián)系我們。
相關(guān)主題:apache配置
PHP實(shí)例B/S架構(gòu)當(dāng)下很流行,因?yàn)锽/S架構(gòu)有眾多優(yōu)點(diǎn),例如:用戶只需有瀏覽器就可使用,維護(hù)升級都比較方便,跨平臺,等等.本文就講講Windows+Apache+PHP+Mysql的開發(fā)環(huán)境如何配置.
PHP實(shí)例如安在win7系統(tǒng)下配置php環(huán)境呢,php+Apache+mysql都是在配置過程中必不可少的元素,php負(fù)責(zé)解析php代碼,apache負(fù)責(zé)服務(wù)器端而mysql是數(shù)據(jù)交互的中轉(zhuǎn)站.
PHP實(shí)例那么如何將php+apache+mysql配置好呢,接下來我們看一下具體的辦法,軟件版本會改變所以需要自己因時(shí)制宜,隨機(jī)應(yīng)變.
PHP實(shí)例第一步:
PHP實(shí)例php-5.5.10-Win32-VC11-x64.zip 下載地址: http://windows.php.net/download/
PHP實(shí)例httpd-2.4.7-win64-VC11.zip 下載地址: http://www.apachelounge.com/download/
PHP實(shí)例mysql-5.6.16-winx64.zip 下載地址: http://dev.mysql.com/downloads/mysql/
PHP實(shí)例第二步:
PHP實(shí)例安裝配置Apache2.4.7(httpd-2.4.7-win64-VC11.zip )
PHP實(shí)例1、解壓下載的安裝包:httpd-2.4.7-win64-VC11.zip將其放到自己的安裝目錄(我的目錄D:\phpEnv\Apache24)
PHP實(shí)例
PHP實(shí)例2.然后對http.conf(D:\phpEnv\Apache24\conf\http.conf)配置文件進(jìn)行修改-使用記事本打開就行
PHP實(shí)例?????(1)修改ServerRoot Apache的根路徑:
PHP實(shí)例??????? (37行)ServerRoot"c:/Apache24"改成=>ServerRoot "D:/phpEnv/Apache24"
PHP實(shí)例?????(2)修改ServerName你的主機(jī)名稱:
PHP實(shí)例??????? 如果此行不修改則啟動apache 提示Starting httpd: AH00558
PHP實(shí)例??????? (217行)ServerName www.example.com:80將前面的#去掉,該屬性在從命令行啟動Apache時(shí)需要用到.
PHP實(shí)例???? (3)修改DocumentRoot Apache拜訪的主文件夾目錄,就是php、html代碼文件的位置.Apache默認(rèn)的路徑是在htdocs(D:\phpEnv\Apache24\htdocs)下面,里面會有個(gè)簡單的入口文件index.html.這個(gè)路徑可以自己進(jìn)行修改,我這里將其配置在我自己新建的文件夾www(D:\phpEnv\www)下.
PHP實(shí)例????????? (247行) DocumentRoot "c:/Apache24/htdocs"
PHP實(shí)例??????? <Directory "c:/Apache24/htdocs">
PHP實(shí)例改為=>
PHP實(shí)例??????? DocumentRoot "D:\phpEnv\www"
??????? <Directory "D:\phpEnv\www">
PHP實(shí)例??? (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
PHP實(shí)例??????? (274行)<IfModule dir_module>?
PHP實(shí)例??????? DirectoryIndex index.html
?????? </IfModule>
PHP實(shí)例改為=>
PHP實(shí)例?????? <IfModuledir_module>
??????? DirectoryIndex? index.php index.htm index.html
??????? </IfModule>
PHP實(shí)例?? (5)設(shè)定serverscript的目錄:
PHP實(shí)例??????? (358行)ScriptAlias/cgi-bin/ "c:/Apache24/cgi-bin/"改為=> ScriptAlias/cgi-bin/ "D:/phpEnv/Apache24/cgi-bin"
PHP實(shí)例? (6)(380行)
PHP實(shí)例??????? <Directory "c:/Apache24/cgi-bin">
????????? AllowOverride None
????????? Options None
????????? Require all granted
??????? </Directory>
PHP實(shí)例改為=>
PHP實(shí)例??????? <Directory "D:/phpEnv/Apache24/cgi-bin">
????????? AllowOverride None
????????? Options None
????????? Require all granted
??????? </Directory>
PHP實(shí)例3、接下來就可以啟動Apache了
PHP實(shí)例開始---運(yùn)行,輸入cmd,打開命令提示符.接著進(jìn)入D:\phpEnv\Apache24\bin目錄下回車httpd回車,如圖所示.
PHP實(shí)例沒有報(bào)錯(cuò)的話就可以測試了(保持該命令窗口為打開的狀態(tài)).
PHP實(shí)例??? 把Apache24\htdocs目錄下的index.html放到D:\phpEnv\www目錄下,用瀏覽器拜訪會出現(xiàn)“It works”那么就說明apache已經(jīng)正確安裝并啟動了.也可以自己寫一個(gè)簡單的index.html文件也可以打開.
PHP實(shí)例
PHP實(shí)例4、將Apache加入到window服務(wù)啟動項(xiàng)里面并設(shè)置成開機(jī)啟動
PHP實(shí)例先關(guān)閉httpd的服務(wù)(將命令窗口關(guān)閉即可)
PHP實(shí)例重新打開一個(gè)新的命令窗口進(jìn)入到D:\phpEnv\Apache24\bin目錄下:
PHP實(shí)例添加HTTP服務(wù)的命令是:httpd.exe -kinstall -n "servicename"? servicename是服務(wù)的名稱,我添加的是:httpd.exe -k install -n "Apache24"命令成功后會有成功的提示,此時(shí)你可以在window服務(wù)啟動項(xiàng)中看到Apache24這個(gè)服務(wù)
PHP實(shí)例然后點(diǎn)擊啟動就可以了,如果不想設(shè)置成開機(jī)啟動的話也可以將啟動類型修改為手動.
PHP實(shí)例如果要卸載這個(gè)服務(wù)的話,先要停止這個(gè)服務(wù),然后輸入httpd.exe -k uninstall -n "Apache24"卸載這個(gè)服務(wù).
PHP實(shí)例當(dāng)然也可以通過D:\phpEnv\Apache24\bin下面的ApacheMonitor.exe來啟動Apache這里就不多說了
PHP實(shí)例如此Apache的配置就基本完成了.
PHP實(shí)例?
PHP實(shí)例二、安裝配置php5.5.10(php-5.5.10-Win32-VC11-x64.zip)
PHP實(shí)例1、將下載的php-5.5.10-Win32-VC11-x64.zip? 解壓到安裝目錄下我的是(D:\phpEnv\php)
PHP實(shí)例2、將目錄下的php.ini-development文件復(fù)制一份并改名為php.ini他是php的配置文件
PHP實(shí)例3、為Apache服務(wù)添加php支持
PHP實(shí)例打開Apache的配置文件http.conf在最后加上
PHP實(shí)例
# php5 support
LoadModule php5_module “D:/phpEnv/php/php5apache2_4.dll”
AddHandler application/x-httpd-php .php
AddType application/x-httpd-php .html .htm
# configure thepath to php.ini
PHPIniDir "D:/phpEnv/php"
PHP實(shí)例這里我添加在LoadModule下面
PHP實(shí)例添加的時(shí)候要保證你的php5apache2_4.dll文件確實(shí)存在php5.5的早期版本里面是沒有這個(gè)文件的,不過高點(diǎn)版本里面已經(jīng)有了,可以打開php安裝目錄找下這個(gè)文件
PHP實(shí)例PHPIniDir"D:/phpEnv/php"這個(gè)就是你的php根目錄
PHP實(shí)例
PHP實(shí)例4.重啟Apache服務(wù)器.
PHP實(shí)例5.測試.
PHP實(shí)例刪除www中其他文件,新建一個(gè)index.php,內(nèi)容為<?php phpinfo(); ?>保存,拜訪出現(xiàn)php的信息就說明php已經(jīng)成功安裝.
PHP實(shí)例備注:
PHP實(shí)例Php的一些常用配置修改:(D:\phpEnv\php\php.ini)
PHP實(shí)例時(shí)區(qū)的設(shè)置:date.timezone = Asia/Shanghai
PHP實(shí)例錯(cuò)誤報(bào)告等級:error_reporting = E_ALL這個(gè)在開發(fā)模式下可以全部打開.
PHP實(shí)例三、安裝配置mysql5.6.16(mysql-5.6.16-winx64.zip)
PHP實(shí)例1、安裝mysql
PHP實(shí)例64位的mysql暫時(shí)沒找到msi的安裝包,因此直接解壓到安裝目錄下,然后配置相關(guān)的環(huán)境變量,修改配置文件,添加window服務(wù)就行,這里就不詳細(xì)寫了.這里把我的配置文件貼出來給大家參考下:??
PHP實(shí)例
[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
PHP實(shí)例注:basedir是mysql的根目錄,datadir是mysql的數(shù)據(jù)存儲目錄.其他的我就不做解釋了
PHP實(shí)例安裝完mysql是沒有圖形用戶界面的,可以安裝個(gè)Navicat for MySQL之類的軟件,這樣看起來會比較方便點(diǎn).
PHP實(shí)例將mysql注冊成為服務(wù):mysqld.exe --install mysql
PHP實(shí)例將mysql服務(wù)進(jìn)行刪除:mysqld.exe --remove mysql
PHP實(shí)例2、安裝完成mysql之后,為php添加mysql支持
PHP實(shí)例打開php的配置文件php.ini(D:\phpEnv\php\php.ini)
PHP實(shí)例(1)(721行); extension_dir = "ext",去掉前面的“;”,并改為extension_dir ="D:\phpEnv\php\ext"打開php的擴(kuò)展支持,ext文件夾下有很多php的擴(kuò)展支持.dll文件,感興趣的同學(xué)可以看一下.
PHP實(shí)例(2)然后就是打開php的mysql擴(kuò)展了
PHP實(shí)例??? (875、876行)去掉前面的“;”
PHP實(shí)例
extension=php_mysql.dll
extension=php_mysqli.dll
PHP實(shí)例當(dāng)然也可以打開881行的php_pdo_mysql.dll啟用php的pdo支持我一般都用這個(gè).
PHP實(shí)例注:在第863行到第888行有很多擴(kuò)展選擇,你要用到什么,去掉前面的“;”就可以了.當(dāng)然如果要添加其他的擴(kuò)展支持如redis支持,php本身可能沒有提供相應(yīng)的dll文件,就需要自己去找到相應(yīng)版本的dll添加到ext文件夾中,然后在配置文件中添加一個(gè)extension=…
PHP實(shí)例完成之后,重啟Apache
PHP實(shí)例3)、啟動MySQL服務(wù)
PHP實(shí)例net start mysql
PHP實(shí)例MySQL服務(wù)正在啟動 .
MySQL服務(wù)無法啟動.
PHP實(shí)例4)、登陸MySQL服務(wù)器
PHP實(shí)例
mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.32-community MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
PHP實(shí)例注意:MySQL的管理員用戶名為root,暗碼默認(rèn)為空.
PHP實(shí)例5)、查看數(shù)據(jù)庫
PHP實(shí)例
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.02 sec)
PHP實(shí)例可以看到MySQL服務(wù)器中有三個(gè)數(shù)據(jù)庫.
PHP實(shí)例6)、使用數(shù)據(jù)庫
PHP實(shí)例
mysql> use test
Database changed
PHP實(shí)例7)、查看數(shù)據(jù)庫中的表
PHP實(shí)例
mysql> show tables;
Empty set (0.00 sec)
PHP實(shí)例8)、創(chuàng)建表ttt
PHP實(shí)例
mysql> create table ttt(a int,b varchar(20));
Query OK, 0 rows affected (0.00 sec)
PHP實(shí)例9)、插入三條數(shù)據(jù)
PHP實(shí)例
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)
PHP實(shí)例10)、查詢數(shù)據(jù)
PHP實(shí)例
mysql> select * from ttt;
+------+------+
| a | b |
+------+------+
| 1 | aaa |
| 2 | bbb |
| 3 | ccc |
+------+------+
3 rows in set (0.00 sec)
PHP實(shí)例11)、刪除數(shù)據(jù)
PHP實(shí)例
mysql> delete from ttt where a=3;
Query OK, 1 row affected (0.01 sec)
PHP實(shí)例刪除后查詢操作結(jié)果:
PHP實(shí)例
mysql> select * from ttt;
+------+------+
| a | b |
+------+------+
| 1 | aaa |
| 2 | bbb |
+------+------+
2 rows in set (0.00 sec)
PHP實(shí)例12)、更新數(shù)據(jù)
PHP實(shí)例
mysql> update ttt set b = 'xxx' where a =2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
PHP實(shí)例查看更新結(jié)果:
PHP實(shí)例
mysql> select * from ttt;
+------+------+
| a | b |
+------+------+
| 1 | aaa |
| 2 | xxx |
+------+------+
2 rows in set (0.00 sec)
PHP實(shí)例13)、刪除表
PHP實(shí)例
mysql> drop table ttt;
Query OK, 0 rows affected (0.00 sec)
PHP實(shí)例查看數(shù)據(jù)庫中剩余的表:
PHP實(shí)例
mysql> show tables;
Empty set (0.00 sec)
PHP實(shí)例三、更改MySQL數(shù)據(jù)庫root用戶的暗碼
PHP實(shí)例1、使用mysql數(shù)據(jù)庫
PHP實(shí)例
mysql> use mysql
Database changed
PHP實(shí)例2、查看mysql數(shù)據(jù)庫中所有的表
PHP實(shí)例
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)
PHP實(shí)例3、刪除mysql數(shù)據(jù)庫中用戶表的所有數(shù)據(jù)
PHP實(shí)例
mysql> delete from user;
Query OK, 3 rows affected (0.00 sec)
PHP實(shí)例4、創(chuàng)建一個(gè)root用戶,暗碼為"xiaohui".
PHP實(shí)例
mysql>grant all on *.* to root@'%' identified by 'xiaohui' with grant option;
Query OK, 0 rows affected (0.02 sec)
PHP實(shí)例5、查看user表中的用戶
PHP實(shí)例
mysql> select User from user;
+------+
| User |
+------+
| root |
+------+
1 row in set (0.00 sec)
PHP實(shí)例6、重啟MySQL:更改了MySQL用戶后,需要重啟MySQL服務(wù)器才可以生效.
PHP實(shí)例net stop mysql
PHP實(shí)例MySQL 服務(wù)正在停止..
MySQL 服務(wù)已成功停止.
PHP實(shí)例net start mysql
MySQL 服務(wù)正在啟動 .
MySQL 服務(wù)已經(jīng)啟動成功.
PHP實(shí)例7、重新登陸MySQL服務(wù)器
PHP實(shí)例
mysql -uroot -pxiaohui
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.32-community MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
PHP實(shí)例如果修改暗碼后net startmysql出現(xiàn)不能啟動mysql的1067錯(cuò)誤,則可以使用以下辦法解決:
使用cmd命令:D:\Appserv\mysql\bin\mysqladmin -uroot -p shutdown,然后輸入暗碼,再net start mysql 就沒有這個(gè)錯(cuò)誤提示了!
PHP實(shí)例四、數(shù)據(jù)庫的創(chuàng)建與刪除
PHP實(shí)例1、創(chuàng)建數(shù)據(jù)庫testdb
PHP實(shí)例
mysql> create database testdb;
Query OK, 1 row affected (0.02 sec)
PHP實(shí)例2、使用數(shù)據(jù)庫testdb
PHP實(shí)例
mysql> use testdb;
Database changed
PHP實(shí)例3、刪除數(shù)據(jù)庫testdb
PHP實(shí)例
mysql> drop database testdb;
Query OK, 0 rows affected (0.00 sec)
PHP實(shí)例4、退出登陸
PHP實(shí)例
mysql>exit
Bye
C:\Documents and Settings\Administrator>
PHP實(shí)例五、操作數(shù)據(jù)庫數(shù)據(jù)的一般步驟
PHP實(shí)例1、啟動MySQL服務(wù)器
PHP實(shí)例2、登陸數(shù)據(jù)庫服務(wù)器
PHP實(shí)例3、使用某個(gè)要操作的數(shù)據(jù)庫
PHP實(shí)例4、操作該數(shù)據(jù)庫中的表,可執(zhí)行增刪改查各種操作.
PHP實(shí)例5、退出登陸.
PHP實(shí)例以上內(nèi)容講述了win7系統(tǒng)配置php+Apache+mysql環(huán)境的辦法,希望大家喜歡.
《PHP學(xué)習(xí):win7系統(tǒng)配置php+Apache+mysql環(huán)境的方法》是否對您有啟發(fā),歡迎查看更多與《PHP學(xué)習(xí):win7系統(tǒng)配置php+Apache+mysql環(huán)境的方法》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/8783.html