Server (Win server2012)+IIS manager configures PHP server and deploy website explanation

I plan to build a website project with IIS. Because the backend of the project is PHP, I want to configure the PHP server environment in IIS. Speaking of port issues, because the default port of IIS and phpstudy is 80, so the two ports will conflict, how to avoid port conflicts? How to build a website project with IIS and configure the environment of the PHP server? After all, this is the first time I have come into contact with this thing, so I had to find this stuff online first. If you are exposed to this thing for the first time, it is best to deploy the test in a virtual machine (win server2012) environment. If your test is successful, then deploy the website in the cloud server environment (follow the test steps), and finally you can visit the website.

When I was in the process of testing, I encountered many problems, such as 404, 500, etc. in general, these indicate configuration errors, path file errors, etc., these problems are very confused every time, and then myself Go explore and find online solutions. After a period of time, it has finally been resolved. I must have learned a lot during this period of time. After all, these gadgets are my first contact. Isn’t that too much hhh? Okay, let me summarize:

First of all, let me remind you that if you don't have IIS, you must first install IIS, and then install phpstudy. (Note: All functions are ticked in IIS installation). The operation of this installation is very simple, I believe your installation is not difficult, just ignore it!

Why install IIS before installing phpstudy. If IIS is not installed, there is no inetput folder and wwwroot folder in the C drive, they are the default sites. Therefore, IIS must be installed first. After installation, their folders will automatically be displayed.

Another detail is that the directory in the phpstudy installation is generally placed in inetpub->wwwroot , because I need IIS to configure the environment of the php server. Then put the project (self-developed stuff) in the inetpub->wwwroot->phpstudy_pro->WWW directory.

Finally, the installation steps are OK! Next is deployment and configuration.

1. IIS build website

First open the IIS manager, and click Add website:

(1) Website name: You can write any name;

(2) Physical path: select the directory location of the development project, I usually put it in the folder of i neput->wwwroot->phpstudy_pro->www->development project ;

(3) The application pool is DefaultAppPool ;

(4) Other optional fields.

 

In addition, click Connect as -> tick the feature user and click Settings -> set credentials to fill in the user name and password (your own administrator account and password), if you don’t have this set of identity authorization, otherwise there will be no way in the web page. The image cannot be displayed when accessing the path file. For example, I put my picture on the web page, so the path file of the picture is always accessed on the web page. In addition, tick all permissions of the user to allow.

This is OK, and then try to open whether you can visit the website. If you can access the website, then you can configure the php server. After the IIS deployment of the website is completed, you must not neglect the test of visiting the website. Because I deployed the website directly and configured the php server in the test and got it right, the result was an error of 500 internal server, indicating a configuration error. After finding many solutions, it was not feasible. I had to redeploy the website and configure it, so I learned this lesson. My method is to deploy the website and get it done, you can use pseudo-static pages or static pages to test, and then can you visit the website. If you can access it, then you can configure the php server environment.

 

2. How to change the port of phpstudy

     Don't start the server first, because IIS is always on there, otherwise the production port conflicts. First click on the website -> management -> modify -> port, the port is changed to 8080 .

After changing the port, you can start the php server so that the port does not conflict. OK!

3. Configure php server

Select your own website on the left and click "Handler Mapping".

 

First, click Add Module Mapping -> Edit Module Mapping in the pop-up box on the right , and then fill in various input boxes as shown in the figure below, and finally confirm.

(The executable file is phpstudy_pro\Extensions\php\php7.3.4nts\php-cgi.exe)

Then it pops up and select " Yes ". The php program mapping is done OK!

 

Go back to the IIS homepage and click " FastCGI Settings ".

After opening the "FastCGI Settings", select the mapping module path added before, and then click Edit, then find "Monitor all changes to the file" and change the file in the php configuration directory.

Monitor the changes made to the file as phpstudy_pro\Extensions\php\php7.3.4nts\php.ini

 The above IIS configuration php has been completed, and the website (dynamic page) can basically be accessed, but some dynamic content is not displayed, and an error 404.3 is reported. According to my own exploration of these, it shows that the web configuration file has not been completed, so I found the web.config in my project directory and opened it. The original configuration code is:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="php" path=".php" verb="*" modules="FastCgiModule" scriptProcessor="C:\inetpub\wwwroot\phpstudy_pro\Extensions\php\php7.3.4nts\php-cgi.exe" resourceType="File" />
        </handlers>
        <defaultDocument>
            <files>
                <!—因保密路径文件,这个就是默认文档,可以不用管-->
            </files>
        </defaultDocument>
        <httpErrors errorMode="Detailed" />
    </system.webServer>
</configuration>

Then you need to find path=".php" , add it as " * ", and path="*.php" . Change to the following:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="php" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="C:\inetpub\wwwroot\phpstudy_pro\Extensions\php\php7.3.4nts\php-cgi.exe" resourceType="File" />
        </handlers>
        <defaultDocument>
            <files>
                <!—因保密路径文件,这个就是默认文档,可以不用管-->
            </files>
        </defaultDocument>
        <httpErrors errorMode="Detailed" />
    </system.webServer>
</configuration>

Finally save the web.config configuration file, you can visit the website and some dynamic pages are displayed! Explain that the entire deployment of the website and configuration of the PHP server environment is done!

It is certainly not easy to solve these problems and explore these things by yourself! It is my greatest pleasure to solve the bug! Personally like to delve into (*^▽^*)!

If you have any questions, please leave a message!

Guess you like

Origin blog.csdn.net/h907310116/article/details/109168841