Home > Topics > php mysql > body text

Apache+MySQL+PHP environment installation (example summary)

WBOY
Release: 2023-01-23 06:30:01
forward
1907 people have browsed it

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.

Apache+MySQL+PHP environment installation (example summary)

Preface

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.

Preparation work

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.

Apache installation

  • Download link:Click to jump
    This is the official website of Apache. If we click on the link below, the interface version may be different. After all, the times It will change, sir. Generally speaking, I choose the latest version.
    Apache+MySQL+PHP environment installation (example summary)
    Then jump to the following interface. The one in the red box is the compiled environment. The following three are integrated environments. Because you need to develop and build the environment locally, please select the one in the red box. Link.
    Apache+MySQL+PHP environment installation (example summary)
    Here I chose Apache Haus, but you can also choose Apache Lounge. Of course, I believe everyone will download this interface, but I still post it.
    Apache+MySQL+PHP environment installation (example summary)
    After downloading, unzip it to the folder you want to store it. Here I put it on the C drive. The path is C://Apache/
    Apache+MySQL+PHP environment installation (example summary)
    Next, open the conf folder under the directory and open the httpd.conf configuration file.
  • The default path of Apache is: "c:\Apache24" (the version number may be different). If it is different from your installation path, you need to modify the path parameter configuration:
    Define SRVROOT "Your Apache installation directory"
    So here I should write Define SRVROOT "C:/ Apache"
    httpd.conf SRVRROOT配置
  • # Of course, there is also the most important port, which defaults to 80, but there may be situations where the port is occupied. So before starting, please enter the following command in cmd to check:
    netstat -anoApache+MySQL+PHP environment installation (example summary)
  • If the port is occupied, change the port, in httpd Just change Listen in .conf. Here I use 8499 (my QQ number prefix)
    Apache+MySQL+PHP environment installation (example summary)
  • After doing all this, go to the bin folder under the Apache installation directory in cmd, and enter 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.
  • After completing the previous step, you can see that the Apache service has been installed. [View method: Task Manager->Service->View Service]Apache+MySQL+PHP environment installation (example summary)
  • At this time, use cmd to enter in the bin directory under Apachehttpd - 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.
  • Now enter 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. Apache+MySQL+PHP environment installation (example summary)
  • Due to the need for subsequent installation, here we still use cmd to enter 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.

PHP installation

  • First of all, let me post the PHP download address: Miaoah
  • Here I downloaded the thread-safe version (I don’t know what the difference is, the more the merrier)
  • Then unzip it to the directory where you want to put PHP. I still put it hereC://PHP/Apache+MySQL+PHP environment installation (example summary)
  • Then copy php.ini-development in the root directory of PHP and rename it php.ini as the PHP configuration file, and then we open php.iniMake changes. Find extension_dir in php.ini, remove the comment and modify it to **"PHP installation path\ext", I installed it in C:/PHP /**, so here is extension_dir = "C:/PHP/ext"
    Apache+MySQL+PHP environment installation (example summary)

MySQL installation

  • Actually, I am a little too lazy to write, but you can go to Noob [MySQL Installation Tutorial] to take a look, or I will write more about it later.
  • Here is the latest version of MySQL [Address]
    Apache+MySQL+PHP environment installation (example summary)
    Apache+MySQL+PHP environment installation (example summary)
  • But if you install it, because I don’t need other services, so Only MySQLServer is installed. Because I didn’t save the MySQL installation package for this part of the installation, you can check out the novice tutorials or browse CSDN. I won’t go into details here, but let’s talk about the Server Only I chose. After your MySQL is installed, the preparations are all over. Next, we start Apache to connect to PHP, and PHP to connect to MySQL. .

AMP connection work

Apache connection to PHP

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.

  • Change Require all denied to Require all granted (I came here for free, I don’t know why)
<directory></directory>
    AllowOverride none
    Require all granted
Copy after login

Apache+MySQL+PHP environment installation (example summary)

  • 增加一行AddType application/x-httpd-php .php,这个是用来增加Apache1对于php后缀文件的支持的。Apache+MySQL+PHP environment installation (example summary)

  • 现在需要Apache+MySQL+PHP environment installation (example summary)可以作为自己索引页,具体做法就是在DirectoryIndex index.html后面增加索引页index.php。Apache+MySQL+PHP environment installation (example summary)

  • 到了这一步我们基本完成了步骤,这时候我们可以在Apache根目录/htdocs/【我这里是C:\Apache\htdocs】下创建一个HelloPHP.php (只是我想这么叫) ,里面输入:

<?phpphpinfo ();?>
Copy after login
  • 接下来测试一下吧,在Apache根目录下的bin目录打开cmd输入httpd -k start启动Apache,然后打开浏览器,输入:localhost:【你的端口】/HelloPHP.php,这里我是localhost:8499/HelloPHP.php,不记得端口号的可以查看上面,配置在httpd.conf里面啦,Listen对应的值。打开之后大概显示如下。
    Apache+MySQL+PHP environment installation (example summary)
  • 这时候我们还是要再次关闭Apache+MySQL+PHP environment installation (example summary),依旧是在Apache根目录下的bin文件夹中打开cmd输入httpd -k stop,然后接下来我们配置PHP+MySQL。

PHP连接MySQL

这里我们要做的就是在PHP中加载连接MySQL的程序集。这边有PHP官网的教程【怎么打不开?!!

  • 打开php.ini ,在extension板块中找到extension=php_mysqli.dll然后给它去掉注释就行了。
    Apache+MySQL+PHP environment installation (example summary)

说明:不同的PHP版本可能提供不同的连接mysq的程序集,去ext文件夹下看看PHP提供的是什么这里就写什么。不同的程序集可能在连接数据库的时候使用的函数也不一样。

  • 这时候我们找到前文的HelloPHP.php修改为如下内容:
<?php   
    $mysqli = mysqli_connect("localhost","root","这里是你安装MySQL时候的密码") or die("cannt connet"); 
?>
Copy after login
  • 启动Apache+MySQL+PHP environment installation (example summary) ,在Apache根目录下的bin目录打开cmd输入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!

Related labels:
php
source:juejin.im
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template