This article brings you relevant knowledge about PHP, which mainly introduces the relevant content about the installation of Apache, MySQL, and PHP environments. Let's take a look at it together. I hope it will be helpful to everyone.
Since I am learning PHP development recently, it is inevitable to involve environments such as AMP and NMP. Of course, I initially used integrated environments such as PHPWAMP and PHPStudy. However, since I have installed MySQL server before, when I open my own MySQL again, it seems that due to these integrated environments, the MySQL I installed cannot be opened (because my programming skills are weak, so I am busy I guess it was because the service or something was changed to an integrated environment, so I couldn't connect). In short, I couldn't solve this problem in the end.
But I believe there must be a way to solve it, although in the end I decided to install this AMP environment by myself, and by the way, I could learn Apache and PHP by myself instead of simply becoming someone else's user.
So I need to say here that the order of my installation is APM (Apache->PHP->MySQL). As far as I understand, Apache must be Install it first, because later debugging, environment and other things require the use of Apache.
Define SRVROOT "Your Apache installation directory"
Define SRVROOT "C:/ Apache"
netstat -ano
httpd -k install
in cmd, because I have already It has been installed, so I cannot show a successful example. You can almost tell whether the installation is successful by reading English. httpd - k start
, by the way, the restart command will be mentioned here. httpd -k restart
will be often used later. The Apache service will be started here. Of course, you can also start it manually in the service list. This is not good enough. Of course, in order to practice your skills, it is recommended to input using cmd yourself. localhost:[port number]
in the browser to check whether Apache has started successfully. The port number I prepared locally is 8499 (my name starts with QQ), so I entered localhost:8499
in the browser, and when I saw the following interface, the installation was successful.
httpd -k stop
in the bin folder under the Apache installation directory to pause the Apache service to facilitate our next step. For PHP installation, if you only need Apache, of course it will be completely ojbk at this point. extension_dir = "C:/PHP/ext"
The main thing we have to do here is to modify the httpd in the conf folder under the Apache installation root directory .conf to configure Apache and PHP to work together.
<directory></directory> AllowOverride none Require all granted
增加一行AddType application/x-httpd-php .php,这个是用来增加Apache1对于php后缀文件的支持的。
现在需要Apache+MySQL+PHP environment installation (example summary)可以作为自己索引页,具体做法就是在DirectoryIndex index.html后面增加索引页index.php。
到了这一步我们基本完成了步骤,这时候我们可以在Apache根目录/htdocs/【我这里是C:\Apache\htdocs】下创建一个HelloPHP.php (只是我想这么叫) ,里面输入:
<?phpphpinfo ();?>
httpd -k start
启动Apache,然后打开浏览器,输入:localhost:【你的端口】/HelloPHP.php,这里我是localhost:8499/HelloPHP.php
,不记得端口号的可以查看上面,配置在httpd.conf里面啦,Listen对应的值。打开之后大概显示如下。httpd -k stop
,然后接下来我们配置PHP+MySQL。这里我们要做的就是在PHP中加载连接MySQL的程序集。这边有PHP官网的教程【怎么打不开?!!】
说明:不同的PHP版本可能提供不同的连接mysq的程序集,去ext文件夹下看看PHP提供的是什么这里就写什么。不同的程序集可能在连接数据库的时候使用的函数也不一样。
<?php $mysqli = mysqli_connect("localhost","root","这里是你安装MySQL时候的密码") or die("cannt connet"); ?>
httpd -k start
启动Apache,然后打开浏览器,输入:localhost:【你的端口】/HelloPHP.php,这里我是localhost:8499/HelloPHP.php
,不记得端口号的可以查看上面,配置在httpd.conf里面啦,Listen对应的值。然后发现没有错误信息,那么到此AMP环境的搭建就完成了。推荐学习:《PHP视频教程》
The above is the detailed content of Apache+MySQL+PHP environment installation (example summary). For more information, please follow other related articles on the PHP Chinese website!