4

How to configure nginx to let magento execute php files.

For example I created phpinfo.php and I'd like to execute it.

Where should I put it? ./ or ./pub/ ?

What do I need to write into the config ?

2
  • 1
    i know this is all depends, but, avoid creating any files like phpinfo.php in root. if you really need it to just check something, ok, but at least name it differently. Commented Nov 24, 2015 at 21:52
  • 1
    Sure, these all for dev. purposes on local or another dev. env. Commented Nov 25, 2015 at 8:42

2 Answers 2

19

If you use the official Nginx config (nginx.conf.sample file in the Magento 2 distribution) then you need change the line 109 from :

location ~ (index|get|static|report|404|503)\.php$ {

to :

location ~ (index|get|static|report|404|503|phpinfo)\.php$ {

and place phpinfo.php to the pub subfolder because pub declared as document root at line 21:

root $MAGE_ROOT/pub;

I use my own Nginx config for Magento 2 and it permits phpinfo.php in the root folder.

2
  • this is pretty interesting, magento 2 sample nginx config allows me to browse and download whole magento shop. Commented Nov 24, 2015 at 17:09
  • @Mage2.PRO I have somewhat related question to your answer posted, can please look at my post, and maybe suggest something? magento.stackexchange.com/q/197290/32271 Thank you. Commented Oct 15, 2017 at 4:50
-5

Don't be confuse so much. I have done magento2 installation with nginx and varnish caching. Please follow the below steps.

Step 1-: Install required packages

$ sudo apt-get install software-properties-common
$ sudo add-apt-repository -y ppa:ondrej/mysql-5.6
$ sudo add-apt-repository -y ppa:ondrej/php5-5.6
$ sudo apt-add-repository -y ppa:duggan/composer
$ sudo apt-get update
$ sudo apt-get install -y php5-fpm nginx varnish php5-gd php5-intl php5-mcrypt php5-xsl mysql-server php5-curl php5-json php5-composer
$ sudo php5enmod mcrypt

Step 2-: Create a database to install magento2.

mysql -p -e "create database magento2"

Step 3-: Varnish server setup.

sudo nano /etc/default/varnish

Default configuration replace from

DAEMON_OPTS="-a :6081 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"

To

DAEMON_OPTS="-a :80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,1024m"

Check default.vcl file port

nano /etc/varnish/default.vcl

Output-:

backend default {
.host = "127.0.0.1";
.port = "8080";
}

Configure the nginx.conf to listen port 8080.

5
  • 2
    Thx for your post, but I asked not that Commented Apr 27, 2016 at 19:44
  • Click on my Article link. I have added nginx.conf for nginx server. Commented Apr 27, 2016 at 19:47
  • 2
    @ArvindRawat Stack Exchange is not a place to promote your site Commented Apr 27, 2016 at 19:50
  • @andyjv I am not promoting here. I wish to post whole configuration file here. But it need more line indentation. Commented Apr 27, 2016 at 19:58
  • 1
    Nevertheless your post doesn't answer on my question. Voting for spam Commented Apr 29, 2016 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.