Create a new PHP project and configure Nginx so that it can be accessed directly from the browser

Source: Internet
Author: User
Environment

Speaking of the environment, I am using Eclipse, the server is Nginx. Tools php nginx eclipse Specific steps to create a new PHP project

As shown in figure:

All the way next, the following content is temporarily not modified.

Then add the php file

Write a little bit of test content. Mine is this:

<?php 

echo "Hello php!\n";

$var = 0;
$var + 5;
Var_dump ($var);

echo "bye!\n";


Configure Nginx

In Nginx's Conf folder there is a main.conf, we can directly modify this, of course, the more recommended method is to create a conf file of their own.

We create a new vhosts folder in the Conf folder to store the Conf file for the PHP website.

Now we create a new php-test.conf file in the Vhosts folder.

Edit the contents of the inside.
First copy the contents of the main.conf, and then modify the good.
My final content is this:

server {
    listen          ;
    server_name     www.php-test.com;
    Root            d:/code/php-test;
    Index index.php;

    CharSet         Utf-8;

    Access_log      f:/devenv/logs/php-test.access.log  main;
    Error_log       F:/devenv/logs/php-test.error.log;

    # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9001

    location ~ \.php$ {
        try_files $fastcgi _SCRI Pt_name = 404;
        Fastcgi_pass        127.0.0.1:9001;
        Fastcgi_index       index.php;
        Fastcgi_param       script_filename $document _root$fastcgi_script_name;
        Include             fastcgi_params;
    }

    # Deny access to. htaccess files, if Apache ' s document Root
    # concurs with Nginx ' one

    location ~/\.ht {
        D Eny all  ;
    }

We compare main.conf to know where the changes, on-demand changes can be.
server_name there actually write 127.0.0.1, I am here to modify the system of the hosts file let it point to 127.0.0.1. So actually the effect is the same.

Save the Conf file.

Next, start Nginx and PHP, and then you can access it in the browser.

Let's test, in the browser input http://www.php-test.com/index.php "PS: replace www.php-test.com into their own just write server_name", and then you can see the results of the operation.
Note that if you are running eclipse at this point, you may be in debug mode and you will see the results out of debugging.

PS: In fact, eclipse to configure to achieve a single step of PHP debugging, the next article will introduce this.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.