Before been using such PHPstudy, WampServer like integrated environment, but that is learning the computer, or a build like yourself with a comfortable.
Ado, directly on the tutorial. Platform is windows7, it is Apache2.4 + PHP7.4 + Mysql5.7 combination built.
Step One: Download PHP
Download https://windows.php.net/download
Because Apache is a server environment, so I chose Thread Safe (thread-safe) version, my computer is 64-bit, download the corresponding 64-bit version.
After good download, unzip. (I extract to the PHP directory of the C drive)
Step two: Download Apache
Download http://httpd.apache.org/download.cgi
Then choose "Apache Lounge"
Then according to their computer to download the median compression package on the line corresponding, I downloaded 64.
After the download, unzip, I unzipped directory is "C: \ Apache \"
Step Three: Download MySQL
Download https://dev.mysql.com/downloads/windows/installer/8.0.html
Whether compressed format or one-click installation program can, I use the one-click installation type.
Installation tutorial can be seen https://blog.csdn.net/qq_32786873/article/details/81185221
After installation of the three environments, it is necessary to start our configuration
Step Four: Configure Apache
1, open the httpd.conf file Apache24 / conf directory under the Apache unpacked directory
2, the Define SRVROOT and ServerROOT directory into its own directory unpacked, I extract the directory is "C: \ Apache "
3、打开cmd,进入安装目录下的bin目录,在bin目录下执行安装命令httpd -k install
提示:Service is already installed. 就表示Apache已经安装成功
4、启动Apache服务,打开Apache bin目录下的ApacheMonitor.exe,点击“Start”
5、在浏览器中输入localhost,看到It works! 代表安装成功
如果出现“网络连接错误”之类的提示,有可能是因为80端口被占用(默认端口是80),在httpd.conf文件中搜索Listen,把端口换成其他没被占用端口(比如8088,多试几个就知道哪个端口可以了),修改完毕之后重启Apache服务器。
Apache的默认站点根目录为htdocs,这个目录就是php文件运行的根目录,所有的php文件都要放到htdocs目录下运行,也可以自己更改工作目录,查找DocumentRoot和Directory字段,后面的路径改成自己定义的工作路径即可(博主没有改哦)。
第五步:配置PHP环境
1、在PHP的解压目录中找到php.ini-development直接复制,然后改名为php.ini
2、然后我们打开名为名为php.ini的配置文件,进行修改,里面的extension,这是PHP的调用模块,只要把字段前分号去掉,就可以打开此模块的功能,这一步要按照你使用的需求操作。
3、然后我们设置编码格式为utf-8,用Ctrl+f快捷键进行查找default_charset
4、设置环境变量,编辑系统变量,在path中输入ext文件夹的路径
到此PHP已经配置完毕!
第六步:配置PHP模块到Apache服务器上
1、配置Apache24/conf/目录下的httpd.conf文件,在文件最后加入以下代码
LoadModule php7_module "C:/PHP/php7apache2_4.dll"
PHPIniDir "C:/PHP" # PHP的解压目录
AddType application/x-httpd-php .php .html .htm # 期望能够支持的文件类型
注意:将上述代码中的路径修改成自己的文件路径。注意php7_module后面路径中“php7apache2_4.dll”要和里自己下载的Apache版本一样。打开PHP安装目录看一下就知道了。
2、在设置的工作目录下建立index.php文件,文件内容就是输出PHP信息
<?php
phpinfo()
?>
OK,我们重启Apache服务器,打开我们的网页!(注意:只要修改配置文件,必须重启Apache服务器修改才能生效)
到此PHP已经部署到Apache服务器啦!
第七步:配置Mysql
这一步我们要做的就是把PHP和Mysql相互打通!
1、打开php.ini文件,查找extension_dir,去掉前面的注释并将ext文件路径改成我们自己的ext路径
2、在php.int中继续查找mysqli,下面两句前面的;分号注释掉
3、修改index.php中的内容为
<?php
# phpinfo()
$mysqli = mysqli_connect("localhost","root","root");
if($mysqli){
echo "Mysql连接成功!";
}else{
echo "Mysql连接失败!";
}
?>
重新打开网页,如果出现“Mysql连接成功”,那么恭喜你,你的Apache+PHP+Mysql环境已经搭建好啦!
那么怎么操作Mysql呢?博主用的是Navicat Premium 12,给出下载地址吧https://www.navicat.com.cn/download/navicat-premium
当然,你也可以使用PhpMyAdmin,点击这里查看它的介绍,两个各有特点,自行选择吧~