Tutorial

How To Install Linux, Nginx, MySQL, PHP (LEMP) stack On CentOS 7

How To Install Linux, Nginx, MySQL, PHP (LEMP) stack On CentOS 7
Not using CentOS 7?Choose a different version or distribution.
CentOS 7

Introduction

A LEMP software stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the ENginx web server (which replaces the Apache component of a LAMP stack). The site data is stored in a MySQL-based database, and dynamic content is processed by PHP.

In this guide, we’ll get a LEMP stack with PHP 7.4 installed on a CentOS 7 server, using MariaDB as the database management system. MariaDB works as a drop-in replacement for the original MySQL server, which in practice means you can switch to MariaDB without having to make any configuration or code changes in your application.

Prerequisites

Before you begin with this guide, you should have a separate, non-root user account set up on your server. You can learn how to do this by completing steps 1-4 in the initial server setup for CentOS 7.

Step 1 — Installing Nginx

In order to display web pages to our site visitors, we are going to employ Nginx, a high-performance web server. To get the latest Nginx version, we’ll first install the EPEL repository, which contains additional software for the CentOS 7 operating system.

To add the CentOS 7 EPEL repository, run the following command:

  1. sudo yum install epel-release

Since we are using a sudo command, these operations get executed with root privileges. It will ask you for your regular user’s password to verify that you have permission to run commands with root privileges. You’ll also be prompted to confirm installation, so press Y to proceed.

Now that the EPEL repository is installed on your server, install Nginx using the following yum command:

  1. sudo yum install nginx

Once the installation is finished, start the Nginx service with:

  1. sudo systemctl start nginx

You can do a spot check right away to verify that everything went as planned by visiting your server’s public IP address in your web browser (see the note under the next heading to find out what your public IP address is if you do not have this information already):

Open in a web browser:
http://server_domain_name_or_IP/

You will see the default CentOS 7 Nginx web page, which is there for informational and testing purposes. It should look something like this:

CentOS 7 Nginx Default

If you see this page, then your web server is now correctly installed.

To enable Nginx to start on boot, run the following command:

  1. sudo systemctl enable nginx

How To Find Your Server’s Public IP Address

If you do not know what your server’s public IP address is, there are a number of ways you can find it. Usually, this is the address you use to connect to your server through SSH.

From the command line, you can find this a few ways. First, you can use the iproute2 tools to get your address by typing this:

  1. ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

This will give you one or two lines back. They are both correct addresses, but your computer may only be able to use one of them, so feel free to try each one.

An alternative method is to use an outside party to tell you how it sees your server. You can do this by asking a specific server what your IP address is:

  1. curl http://icanhazip.com

Regardless of the method you use to get your IP address, you can type it into your web browser’s address bar to get to your server.

Step 2 — Installing MariaDB

Now that we have our web server up and running, it is time to install MariaDB, a MySQL drop-in replacement. MariaDB is a community-developed fork of the MySQL relational database management system.

Again, we can use yum to acquire and install our software. This time, we’ll also install some other helper packages that will assist us in getting our components to communicate with each other:

  1. sudo yum install mariadb-server mariadb

When the installation is complete, we need to start MariaDB with the following command:

  1. sudo systemctl start mariadb

Now that our MariaDB database is running, we want to run a security script that will remove some dangerous defaults and lock down access to our database. Start the interactive script by running:

  1. sudo mysql_secure_installation

The prompt will ask you for your current root MariaDB password. Since you just installed MariaDB, you most likely won’t have one, so leave it blank by pressing enter. Then the prompt will ask you if you want to set a root password. Go ahead and enter Y, and follow the instructions:

mysql_secure_installation prompts:
Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success!

For the rest of the questions, you should hit the “ENTER” key through each prompt to accept the default values. This will remove some sample users and databases, disable remote root logins, and load these new rules so that MySQL immediately respects the changes we have made.

The last thing you will want to do is enable MariaDB to start on boot. Use the following command to do so:

  1. sudo systemctl enable mariadb

At this point, your database system is now set up and we can move on.

Step 3 — Installing PHP

PHP is the component of our setup that will process code to display dynamic content. It can run scripts, connect to our MySQL databases to get information, and hand the processed content over to our web server to display.

The PHP version available by default within CentOS 7 servers is outdated, and for that reason, we’ll need to install a third-party package repository in order to obtain PHP 7+ and get it installed on your CentOS 7 server. Remi is a popular package repository providing the most up-to-date PHP releases for CentOS servers.

To install the Remi repository for CentOS 7, run:

  1. sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

After the installation is done, you’ll need to run a command to enable the repository containing your preferred version of PHP. To check which PHP 7+ releases are available in the Remi repository, run:

  1. yum --disablerepo="*" --enablerepo="remi-safe" list php[7-9][0-9].x86_64

You’ll see output like this:

Output
Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * remi-safe: mirrors.ukfast.co.uk Available Packages php70.x86_64 2.0-1.el7.remi remi-safe php71.x86_64 2.0-1.el7.remi remi-safe php72.x86_64 2.0-1.el7.remi remi-safe php73.x86_64 2.0-1.el7.remi remi-safe php74.x86_64 1.0-3.el7.remi remi-safe php80.x86_64 1.0-3.el7.remi remi-safe

In this guide, we’ll install PHP 7.4, which is currently the most updated stable version of PHP. To enable the correct Remi package to get PHP 7.4 installed, run:

  1. sudo yum-config-manager --enable remi-php74

Now we can proceed to use yum for installing PHP as usual. The following command will install all the required packages to get PHP 7.4 set up within Nginx and allow it to connect to MySQL-based databases:

  1. sudo yum install php php-mysqlnd php-fpm

To confirm that PHP is available as your chosen version, run:

  1. php --version

You’ll see output like this:

Output
PHP 7.4.5 (cli) (built: Apr 14 2020 12:54:33) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies

PHP is now successfully installed on your system. Next, we need to make a few adjustments to the default configuration. To facilitate editing files on CentOS, we’ll first install nano, a more user-friendly text editor than vi:

  1. sudo yum install nano

Open the /etc/php-fpm.d/www.conf configuration file using nano or your editor of choice:

  1. sudo nano /etc/php-fpm.d/www.conf

Now look for the user and group directives. If you are using nano, you can hit CTRL+W to search for these terms inside the open file.

/etc/php-fpm.d/www.conf
…
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache user chosen to provide access to the same directories as httpd
user = apache
; RPM: Keep a group allowed to write in log dir.
group = apache

You’ll notice that both the user and group variables are set to apache. We need to change these to nginx:

/etc/php-fpm.d/www.conf
…
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

Next, locate the listen directive. By default, php-fpm will listen on a specific host and port over TCP. We want to change this setting so it listens on a local socket file, since this improves the overall performance of the server. Change the line containing the listen directive to the following:

/etc/php-fpm.d/www.conf
listen = /var/run/php-fpm/php-fpm.sock;

Finally, we’ll need to change the owner and group settings for the socket file we just defined within the listen directive. Locate the listen.owner, listen.group and listen.mode directives. These lines are commented out by default. Uncomment them by removing the preceding ; sign at the beginning of the line. Then, change the owner and group to nginx:

/etc/php-fpm.d/www.conf
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

Save and close the file when you’re done editing. If you are using nano, do so by pressing CTRL + X, then Y and ENTER.

To enable and start the php-fpm service, run:

  1. sudo systemctl start php-fpm

Your PHP environment is now ready. Next, we’ll configure Nginx so that it sends all requests for PHP scripts to be processed by php-fpm.

Step 4 — Configuring Nginx to Process PHP Pages

Now, we have all of the required components installed. The only configuration change we still need to do is tell Nginx to use our PHP processor for dynamic content.

Nginx has a dedicated directory where we can define each hosted website as a separate configuration file, using a server block. This is similar to Apache’s virtual hosts.

With the default installation, however, this directory is empty. We’ll create a new file to serve as the default PHP website on this server, which will override the default server block defined in the /etc/nginx/nginx.conf file.

First, open a new file in the /etc/nginx/conf.d directory:

  1. sudo nano /etc/nginx/conf.d/default.conf

Copy the following PHP server definition block to your configuration file, and don’t forget to replace the server_name directive so that it points to your server’s domain name or IP address:

/etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  server_domain_or_IP;

    root   /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Save and close the file when you’re done.

Next, restart Nginx to apply the changes:

  1. sudo systemctl restart nginx

Your web server is now fully set up. In the next step, we’ll test the PHP integration to Nginx.

Step 5 — Testing PHP Processing on your Web Server

Now that your web server is set up, we can create a test PHP script to make sure Nginx is correctly handling .php scripts with the help of php-fpm.

Before creating our script, we’ll make a change to the default ownership settings on Nginx’s document root, so that our regular sudo user is able to create files in that location.

The following command will change the ownership of the default Nginx document root to a user and group called sammy, so be sure to replace the highlighted username and group in this command to reflect your system’s username and group.

  1. sudo chown -R sammy.sammy /usr/share/nginx/html/

We’ll now create a test PHP page to make sure the web server works as expected.

Create a new PHP file called info.php at the /usr/share/nginx/html directory:

  1. nano /usr/share/nginx/html/info.php

The following PHP code will display information about the current PHP environment running on the server:

/usr/share/nginx/html/info.php
<?php

phpinfo();

When you are finished, save and close the file.

Now we can test whether our web server can correctly display content generated by a PHP script. Go to your browser and access your server hostname or IP address, followed by /info.php:

http://server_host_or_IP/info.php

You’ll see a page similar to this:

CentOS 7 PHP 7.4 info

After checking the relevant information about your PHP server through that page, it’s best to remove the file you created as it contains sensitive information about your PHP environment and your CentOS server. You can use rm to remove that file:

  1. rm /usr/share/nginx/html/info.php

You can always regenerate this file if you need it later.

Conclusion

In this guide, you’ve built a flexible foundation for serving PHP websites and applications to your visitors, using Nginx as web server and the latest PHP release version. You’ve set up Nginx to handle PHP requests through php-fpm, and you also set up a MariaDB database to store your website’s data.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Default avatar

Developer Advocate

Dev/Ops passionate about open source, PHP, and Linux.


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
81 Comments
Leave a comment...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

I have the next error when I type sudo systemctl start nginx.service

Job for nginx.service failed. See ‘systemctl status nginx.service’ and ‘journalctl -xn’ for details.

:(

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
July 23, 2014

@dgonzalez: Sounds like there is a typo or syntax error in your Nginx configuration file. To test it, run:

sudo nginx -t

Not all changes are highlighted red in default.conf listing in my nginx config file.

The instructions root and index are carried out into the section server{}, although by default they are found inside the section of location / {}.

Also added try_files $uri $uri/ =404; instruction into location / {}.

I think, instead of the edit file, simpler it will copy the listing of configuration proposed.

I get error: 404 Not Found when I try to access websiteaddress.com/info.php

I put info.php in /usr/share/nginx/html/ via FileZilla.

I have the same error.

how can I solved ?

It’a all good now. :)

Thanks, d.v.bogdanov - I was stuck on this tutorial for a bit, and your comment helped me fixed the problem! :)

Yeah, thanks d.v.bogdanov and rdebeasi. I completely missed that as well. Be nice if the author could go back and make those changes a little clearer. Otherwise very helpful startup article.

To save some the headache that I went through.

  1. In the line sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm : the el7 is the letter E, the letter L, the Numbr 7

  2. Before sudo yum install nginx will work, you must install EPEL. This can be done with these codes.

wget http://dl.fedoraproject.org/pub/epel/beta/7/x86_64/epel-release-7-0.2.noarch.rpm

rpm -ivh epel-release-7-0.2.noarch.rpm

Thanks Very much !

works for me all but a small detail that I can not fix …

when I put in the nginx configuration file (/etc/nginx/nginx.conf) about “listen = /var/run/php-fpm/php-fpm.sock " the web does not work, I get a little clear error”

the file “/etc/nginx/conf.d/default.conf” is well configured with the following "fastcgi_pass unix:/var/run/php-fpm/ php-fpm.sock; " but does not work.

however when I put in the two configuration files that “127.0.0.1:9000” if it works

the question is, what can be the problem? in the tutorial I see that you just have to edit what I put, but it may be that I miss something?

thank you very much for your tutorial and help

all right with the exception of reading the info.php file. 404 Not Found. What’s wrong?

resolved. it works : )

Can you say what you did to resolve it? I’ve gone through this entire thread. I still get 404 Not found.

Here is the tail of the nginx error log:

2015/04/23 15:50:19 [error] 876#0: *6 open() "/usr/share/nginx/html/404.html" failed (2: No such file or directory), client: <removed>, server: <removed>, request: "GET /info.php HTTP/1.1", host: "<removed>"
2015/04/23 15:53:15 [error] 876#0: *8 open() "/usr/share/nginx/html/404.html" failed (2: No such file or directory), client: <removed>, server: <removed>, request: "GET /info.php HTTP/1.1", host: "<removed>"
2015/04/23 15:55:37 [error] 2261#0: *1 FastCGI sent in stderr: "Unable to open primary script: /scripts/info.php (No such file or directory)" while reading response header from upstream, client: <removed>, server: localhost, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "<removed>"
2015/04/23 15:58:13 [error] 2261#0: *3 FastCGI sent in stderr: "Unable to open primary script: /scripts/info.php (No such file or directory)" while reading response header from upstream, client: <removed>, server: localhost, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "<removed>"
2015/04/23 16:11:03 [error] 2314#0: *1 FastCGI sent in stderr: "Unable to open primary script: /scripts/info.php (No such file or directory)" while reading response header from upstream, client: <removed>, server: <removed>, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "<removed>"
2015/04/23 16:11:18 [error] 2314#0: *1 FastCGI sent in stderr: "Unable to open primary script: /scripts/info.php (No such file or directory)" while reading response header from upstream, client: <removed>, server: <removed>, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "<removed>"
2015/04/23 16:24:38 [error] 2314#0: *4 FastCGI sent in stderr: "Unable to open primary script: /scripts/info.php (No such file or directory)" while reading response header from upstream, client: <removed>, server: <removed>, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "<removed>"
2015/04/23 16:33:33 [emerg] 11604#0: unknown "scripts" variable

server { listen 80; server_name server_domain_name_or_IP;

root   /usr/share/nginx/html/foo_com;               ####  I have chang this !!!!
index index.php index.html index.htm;

location / {
    try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /usr/share/nginx/html;
}

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

}

What’s wrong with here ?

And How to config 【VirtualHost】

: ( It does not work

location ~ \.php$ {
    root           /usr/share/nginx/html;
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

Please add the following lines to the article.

sudo vi /etc/php-fpm.d/www.conf

user = nginx group = nginx

systemctl restart php-fpm

chown -R nginx:nginx /usr/share/nginx/html (for wordpress and etc.)

You also need to uncomment the lines “listener.group” and “listener.mode” if it still doesn’t work.

When I type yum install phpmyadmin its says “No package phpmyadmin available. Error: Nothing to do” and I did install EPEL 7-1.

any ideas?

if you need some more php extensions installed, you can get the epel repos here.

http://rpm.pbone.net/index.php3/stat/4/idpl/27122196/dir/redhat_el_7/com/epel-release-7-1.noarch.rpm.html

Noob Alert

Hello when I input “sudo systemctl start nginx.service” it does nothing just goes to next line Please advise thanks James

try to input without quotes.

This comment has been deleted

    This comment has been deleted

      This comment has been deleted

        I have followed you instruction but I got 502 error. I have another server with centos 6.5 so I have configured it just like my other server, which is:

        in default.conf (or in any vhost conf file) change

         fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        
        

        to

        fastcgi_pass 127.0.0.1:9000;
        
        

        and in /etc/php-fpm.d/www.conf

        from:

        listen = /var/run/php-fpm/php-fpm.sock
        
        

        to

        listen 127.0.0.1:9000
        

        restart both services and it worked. Could you tell me what is the difference between .sock file and ip:9000 ?

        I have same question too,hope someone can comment on it.Thanks

        This comment has been deleted

          Thanks for the tutorial mate but this won’t work if you don’t set the right configuration for php-fpm, you need to edit /etc/php-fpm.d/www.conf and search for “listen.owner” uncomment the line and set it like this “listen.owner = nginx” same for group and finally set the mode on 0660 (beware 0666 is vulnerable)

          When trying to install phpmyadmin i have error: “No package phpmyadmin available. Error: Nothing to do” Maybe i am doing something wrong?

          I found a cure to my problem friends, this tutorial give another easier way of instaling nginx, phpmyadmin and more on a server.

          Thanks! Good article.

          I visit the address :http://your_server_IP_address/info.php but this page don’t give me information about my server from the perspective of PHP. just show: <?php phpinfo(); ?> why? thx

          solved

          running into this:

          /etc/php-fpm.d/www.conf unknown entry ‘listen’

          any ideas?

          I keep getting a 404 Not Found when trying to view myIPAddress/info.php… everything seemed to work up to that point. I see there were a couple earlier comments from people having this problem but there wasn’t a solution posted… does anybody have any advice?

          Well I guess I messed up with the default.conf editing. I just copied & pasted the syntax from step 4 and now it works.

          Great ! I found systemctl is for Centos 7 only. If any reader trying on Centos 6 like me, then just /etc/init.d/ instead like below,

          [root@localhost html]# history | grep init.d

          84 /etc/init.d/nginx start 95 /etc/init.d/nginx stop 106 /etc/init.d/php-fpm start 108 /etc/init.d/nginx restart 112 history | grep init.d [root@localhost html]#

          I am getting transaction check error while trying to install php,

          sudo yum install php php-mysql php-fpm

          Transaction check error: file /etc/my.cnf from install of mariadb-libs-1:5.5.40-2.el7_0.x86_64 conflicts with file from package MariaDB-common-10.0.15-1.el6.x86_64

          Works now in instruction there is error

          location ~ \.php$ {
              try_files $uri =404;
          

          change it as below

              try_files $uri $uri=404
          

          then works

          I have followed you instruction but I got 502 error. I have another server with centos 6.5 so I have configured it just like my other server, which is:

          in default.conf (or in any vhost conf file) change

           fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
          
          

          to

          fastcgi_pass 127.0.0.1:9000;
          
          

          and in /etc/php-fpm.d/www.conf

          from:

          listen = /var/run/php-fpm/php-fpm.sock
          
          

          to

          listen 127.0.0.1:9000
          

          restart both services and it worked. Could you tell me what is the difference between .sock file and ip:9000 ?

          I have same question too,hope someone can comment on it.Thanks

          This comment has been deleted

            Thanks for the tutorial mate but this won’t work if you don’t set the right configuration for php-fpm, you need to edit /etc/php-fpm.d/www.conf and search for “listen.owner” uncomment the line and set it like this “listen.owner = nginx” same for group and finally set the mode on 0660 (beware 0666 is vulnerable)

            When trying to install phpmyadmin i have error: “No package phpmyadmin available. Error: Nothing to do” Maybe i am doing something wrong?

            I found a cure to my problem friends, this tutorial give another easier way of instaling nginx, phpmyadmin and more on a server.

            Thanks! Good article.

            I visit the address :http://your_server_IP_address/info.php but this page don’t give me information about my server from the perspective of PHP. just show: <?php phpinfo(); ?> why? thx

            solved

            running into this:

            /etc/php-fpm.d/www.conf unknown entry ‘listen’

            any ideas?

            I keep getting a 404 Not Found when trying to view myIPAddress/info.php… everything seemed to work up to that point. I see there were a couple earlier comments from people having this problem but there wasn’t a solution posted… does anybody have any advice?

            Well I guess I messed up with the default.conf editing. I just copied & pasted the syntax from step 4 and now it works.

            Great ! I found systemctl is for Centos 7 only. If any reader trying on Centos 6 like me, then just /etc/init.d/ instead like below,

            [root@localhost html]# history | grep init.d

            84 /etc/init.d/nginx start 95 /etc/init.d/nginx stop 106 /etc/init.d/php-fpm start 108 /etc/init.d/nginx restart 112 history | grep init.d [root@localhost html]#

            I am getting transaction check error while trying to install php,

            sudo yum install php php-mysql php-fpm

            Transaction check error: file /etc/my.cnf from install of mariadb-libs-1:5.5.40-2.el7_0.x86_64 conflicts with file from package MariaDB-common-10.0.15-1.el6.x86_64

            Works now in instruction there is error

            location ~ \.php$ {
                try_files $uri =404;
            

            change it as below

                try_files $uri $uri=404
            

            then works

            I am having trouble accessing my ip in my browser (http://server_domain_name_or_IP/). I just get a “Web page not available” error. I also could not access the index.php file, though I setup the file correctly and it appeared to be created successfully.

            I’ve gone through all the steps above successfully, and all the initial server setup and additional server setup instructions for CentOS.

            Does anyone know what I might be missing?

            Kamal Nasser
            DigitalOcean Employee
            DigitalOcean Employee badge
            January 31, 2015

            Hi! Can you try starting nginx?

            sudo systemctl start nginx.service
            

            If that doesn’t work, please post the output of the following command:

            sudo netstat -plutn
            

            That appears to work, when I enter that command no errors are shown. Just to be sure, I should be using my IP Address that is listed on the Dashboard for my droplet, correct? Is this because I am not listening on port 80? If so, how do I begin listening on port 80? During the initial server setup process I changed the SSH port, does that have something to do with it?

            Is it safe to post the output to this public comment? It contains the ports I am listening on and my IP address.

            Kamal Nasser
            DigitalOcean Employee
            DigitalOcean Employee badge
            January 31, 2015

            It’s safe to post it, but you can censor your IP address if you would prefer that. :)

            It looks like nginx is indeed listening on port 80:

            Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
            tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3110/nginx: master
            

            As you can see, the “nginx: master” process’s local address is 0.0.0.0:80, which means that it’s listening on port 80 on all interfaces (lo, the droplet’s loopback interface 127.0.0.1, and eth0, your public IPv4 and IPv6 addresses).

            Do you have a firewall running? What’s the output of:

            sudo iptables-save
            

            I do have a firewall running.

            Here is the output for sudo iptables-save

            # Generated by iptables-save v1.4.21 on Sat Jan 31 15:05:59 2015
            *nat
            :PREROUTING ACCEPT [3216:174251]
            :INPUT ACCEPT [12:608]
            :OUTPUT ACCEPT [475:34755]
            :POSTROUTING ACCEPT [475:34755]
            :OUTPUT_direct - [0:0]
            :POSTROUTING_ZONES - [0:0]
            :POSTROUTING_ZONES_SOURCE - [0:0]
            :POSTROUTING_direct - [0:0]
            :POST_public - [0:0]
            :POST_public_allow - [0:0]
            :POST_public_deny - [0:0]
            :POST_public_log - [0:0]
            :PREROUTING_ZONES - [0:0]
            :PREROUTING_ZONES_SOURCE - [0:0]
            :PREROUTING_direct - [0:0]
            :PRE_public - [0:0]
            :PRE_public_allow - [0:0]
            :PRE_public_deny - [0:0]
            :PRE_public_log - [0:0]
            -A PREROUTING -j PREROUTING_direct
            -A PREROUTING -j PREROUTING_ZONES_SOURCE
            -A PREROUTING -j PREROUTING_ZONES
            -A OUTPUT -j OUTPUT_direct
            -A POSTROUTING -j POSTROUTING_direct
            -A POSTROUTING -j POSTROUTING_ZONES_SOURCE
            -A POSTROUTING -j POSTROUTING_ZONES
            -A POSTROUTING_ZONES -o eth0 -g POST_public
            -A POSTROUTING_ZONES -g POST_public
            -A POST_public -j POST_public_log
            -A POST_public -j POST_public_deny
            -A POST_public -j POST_public_allow
            -A PREROUTING_ZONES -i eth0 -g PRE_public
            -A PREROUTING_ZONES -g PRE_public
            -A PRE_public -j PRE_public_log
            -A PRE_public -j PRE_public_deny
            -A PRE_public -j PRE_public_allow
            COMMIT
            # Completed on Sat Jan 31 15:05:59 2015
            # Generated by iptables-save v1.4.21 on Sat Jan 31 15:05:59 2015
            *mangle
            :PREROUTING ACCEPT [13143:924742]
            :INPUT ACCEPT [13143:924742]
            :FORWARD ACCEPT [0:0]
            :OUTPUT ACCEPT [8559:964446]
            :POSTROUTING ACCEPT [8576:967817]
            :FORWARD_direct - [0:0]
            :INPUT_direct - [0:0]
            :OUTPUT_direct - [0:0]
            :POSTROUTING_direct - [0:0]
            :PREROUTING_ZONES - [0:0]
            :PREROUTING_ZONES_SOURCE - [0:0]
            :PREROUTING_direct - [0:0]
            :PRE_public - [0:0]
            :PRE_public_allow - [0:0]
            :PRE_public_deny - [0:0]
            :PRE_public_log - [0:0]
            -A PREROUTING -j PREROUTING_direct
            -A PREROUTING -j PREROUTING_ZONES_SOURCE
            -A PREROUTING -j PREROUTING_ZONES
            -A INPUT -j INPUT_direct
            -A FORWARD -j FORWARD_direct
            -A OUTPUT -j OUTPUT_direct
            -A POSTROUTING -j POSTROUTING_direct
            -A PREROUTING_ZONES -i eth0 -g PRE_public
            -A PREROUTING_ZONES -g PRE_public
            -A PRE_public -j PRE_public_log
            -A PRE_public -j PRE_public_deny
            -A PRE_public -j PRE_public_allow
            COMMIT
            # Completed on Sat Jan 31 15:05:59 2015
            # Generated by iptables-save v1.4.21 on Sat Jan 31 15:05:59 2015
            *security
            :INPUT ACCEPT [9903:746912]
            :FORWARD ACCEPT [0:0]
            :OUTPUT ACCEPT [8559:964446]
            :FORWARD_direct - [0:0]
            :INPUT_direct - [0:0]
            :OUTPUT_direct - [0:0]
            -A INPUT -j INPUT_direct
            -A FORWARD -j FORWARD_direct
            -A OUTPUT -j OUTPUT_direct
            COMMIT
            # Completed on Sat Jan 31 15:05:59 2015
            # Generated by iptables-save v1.4.21 on Sat Jan 31 15:05:59 2015
            *raw
            :PREROUTING ACCEPT [13143:924742]
            :OUTPUT ACCEPT [8559:964446]
            :OUTPUT_direct - [0:0]
            :PREROUTING_direct - [0:0]
            -A PREROUTING -j PREROUTING_direct
            -A OUTPUT -j OUTPUT_direct
            COMMIT
            # Completed on Sat Jan 31 15:05:59 2015
            # Generated by iptables-save v1.4.21 on Sat Jan 31 15:05:59 2015
            *filter
            :INPUT ACCEPT [0:0]
            :FORWARD ACCEPT [0:0]
            :OUTPUT ACCEPT [8559:964446]
            :FORWARD_IN_ZONES - [0:0]
            :FORWARD_IN_ZONES_SOURCE - [0:0]
            :FORWARD_OUT_ZONES - [0:0]
            :FORWARD_OUT_ZONES_SOURCE - [0:0]
            :FORWARD_direct - [0:0]
            :FWDI_public - [0:0]
            :FWDI_public_allow - [0:0]
            :FWDI_public_deny - [0:0]
            :FWDI_public_log - [0:0]
            :FWDO_public - [0:0]
            :FWDO_public_allow - [0:0]
            :FWDO_public_deny - [0:0]
            :FWDO_public_log - [0:0]
            :INPUT_ZONES - [0:0]
            :INPUT_ZONES_SOURCE - [0:0]
            :INPUT_direct - [0:0]
            :IN_public - [0:0]
            :IN_public_allow - [0:0]
            :IN_public_deny - [0:0]
            :IN_public_log - [0:0]
            :OUTPUT_direct - [0:0]
            -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
            -A INPUT -i lo -j ACCEPT
            -A INPUT -j INPUT_direct
            -A INPUT -j INPUT_ZONES_SOURCE
            -A INPUT -j INPUT_ZONES
            -A INPUT -p icmp -j ACCEPT
            -A INPUT -j REJECT --reject-with icmp-host-prohibited
            -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
            -A FORWARD -i lo -j ACCEPT
            -A FORWARD -j FORWARD_direct
            -A FORWARD -j FORWARD_IN_ZONES_SOURCE
            -A FORWARD -j FORWARD_IN_ZONES
            -A FORWARD -j FORWARD_OUT_ZONES_SOURCE
            -A FORWARD -j FORWARD_OUT_ZONES
            -A FORWARD -p icmp -j ACCEPT
            -A FORWARD -j REJECT --reject-with icmp-host-prohibited
            -A OUTPUT -j OUTPUT_direct
            -A FORWARD_IN_ZONES -i eth0 -g FWDI_public
            -A FORWARD_IN_ZONES -g FWDI_public
            -A FORWARD_OUT_ZONES -o eth0 -g FWDO_public
            -A FORWARD_OUT_ZONES -g FWDO_public
            -A FWDI_public -j FWDI_public_log
            -A FWDI_public -j FWDI_public_deny
            -A FWDI_public -j FWDI_public_allow
            -A FWDO_public -j FWDO_public_log
            -A FWDO_public -j FWDO_public_deny
            -A FWDO_public -j FWDO_public_allow
            -A INPUT_ZONES -i eth0 -g IN_public
            -A INPUT_ZONES -g IN_public
            -A IN_public -j IN_public_log
            -A IN_public -j IN_public_deny
            -A IN_public -j IN_public_allow
            -A IN_public_allow -p tcp -m tcp --dport 8930 -m conntrack --ctstate NEW -j ACCEPT
            COMMIT
            # Completed on Sat Jan 31 15:05:59 2015
            

            and for sudo netstat -plutn

            Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
            tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1140/master         
            tcp        0      0 0.0.0.0:8930            0.0.0.0:*               LISTEN      841/sshd            
            tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      2868/mysqld         
            tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      3110/nginx: master  
            tcp6       0      0 ::1:25                  :::*                    LISTEN      1140/master         
            tcp6       0      0 :::8930                 :::*                    LISTEN      841/sshd            
            udp        0      0 162.243.155.241:123     0.0.0.0:*                           362/ntpd            
            udp        0      0 127.0.0.1:123           0.0.0.0:*                           362/ntpd            
            udp        0      0 0.0.0.0:123             0.0.0.0:*                           362/ntpd            
            udp        0      0 0.0.0.0:5353            0.0.0.0:*                           347/avahi-daemon: r 
            udp        0      0 0.0.0.0:49237           0.0.0.0:*                           347/avahi-daemon: r 
            udp6       0      0 fe80::601:3aff:fe4b:123 :::*                                362/ntpd            
            udp6       0      0 2604:a880:1:20::12::123 :::*                                362/ntpd            
            udp6       0      0 ::1:123                 :::*                                362/ntpd            
            udp6       0      0 :::123                  :::*                                362/ntpd 
            

            It looks like it is listening on port 80

            Kamal Nasser
            DigitalOcean Employee
            DigitalOcean Employee badge
            February 2, 2015

            You can allow ports 80 and 443 (HTTP and HTTPS) to go through the firewall by running the following commands:

            sudo firewall-cmd --permanent --add-service=http
            sudo firewall-cmd --permanent --add-service=https
            sudo firewall-cmd --reload
            

            That worked!!! Great! Thank you so much. What I had done was added those services to the port I created but never added them to port 80. Thank you!

            Kamal Nasser
            DigitalOcean Employee
            DigitalOcean Employee badge
            February 2, 2015

            No problem! I’m happy I could help :)

            Great tutorial. However I experienced problems with php files, for I received a 404 error everytime I tried to access my phpinfo.php file.

            The root directory is /usr/share/nginx/html, BUT don’t be fooled for having declared the index.php in the index line. That root directory is for static content. I spent like 2 hours literally going crazy because when you see a 404 error you might think Nginx is getting the root directory from another one… but in my case I edited the index.html and it got affected, so Nginx was indeed targeting that root directory.

            Checking the error log file I see that for php files (I still don’t know why)

            What I did, according to my personal needs, was use the same root for all. I just stated it once at the server level and it’ll be inherited by all the locations.

            Here’s my default.conf file:

            server {
                listen       80;
                server_name  www.alemany.me;
            
                #charset koi8-r;
                access_log  /var/log/nginx/alemany.access.log  main;
                error_log /var/log/nginx/alemany.error.log;
            
                root   /usr/share/nginx/html;
                index index.php index.html index.htm;
            
                error_page 404 /404.html;
                error_page 500 502 503 504 /50x.html;
                location = /50x.html {
                    root /usr/share/nginx/html;
                }
            
                location ~ \.php$ {
                    try_files $uri =404;
                    include fastcgi_params;
                    fastcgi_pass unix:/var/run/php-fpm.sock; 
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                }
            }
            

            I’m not being redundant here. I might be jumping a couple of things here.

            Anyway, this is how I worked around this and it’s up and running right now.

            Best regards.

            Did you check file access permissions. You need read permissions. This is typical error.

            I don’t think that was the problem. Everytime I tried to access my index.php and got the 404 error, I checked in the logs and by unknown reasons Nginx was looking for the php file in /etc/nginx/html/index.php as you can see below:

            2015/03/18 09:37:13 [error] 13192#0: *1 FastCGI sent in stderr: "Unable to open primary script: /etc/nginx/html/index.php (No such file or directory)" while reading response header from upstream, client: 200.55.154.30, server: www.alemany.me, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.alemany.me"
            

            I worked around this as I mention previously. If there’s a more orthodoxe way, please share it with me.

            One more thing.

            you root is pointing to

            root /usr/share/nginx/html

            You should change this if you want it to point somewhere else.

            work foot thank you

            sudo vi /etc/php-fpm.d/www.conf im not having above path. pleae help.

            Maybe you do not install php-fpm yet?Or you can find it in whole etc path like: sudo find /etc -name “www.conf”

            Hi, I got some issues start from step four: Configure Nginx to Process PHP Pages

            After I typed this $ sudo vi /etc/nginx/conf.d/default.conf. I can’t find

                listen       80;
                server_name  localhost;
            
                location / {
                    root   /usr/share/nginx/html;
                    index  index.html index.htm;
                }
                error_page   500 502 503 504  /50x.html;
                location = /50x.html {
                    root   /usr/share/nginx/html;
                }
            }```
            
            ..to make an edit. It just showing me as a *blank*. Here's the [screencast](https://cl.ly/image/0C2w2d1l3z0r)
            
            I sent a ticket to DigitalOcean Support, they told me to force go on but  I can't put this ```<?php phpinfo(); ?>``` in the file at** step five**. 
            
            Guys, help me!

            I installed this way, and it only installed php 5.4. When I upgraded to php 5.6 with “yum install php56w-common”…etc, now Nginx and php-fpm are not linked to each other.

            The default php56w* does not seem to install the php-fpm at this location: /var/run/php-fpm/php-fpm.sock

            What should be the path? Do I need to change it in /etc/php-fpm.conf or something?

            Any PHP from Nginx is giving me 502 bad gateway error.

            My /etc/php-fpm.conf file has the following:

            pid = /var/run/php-fpm/php-fpm.sock
            

            Should I leave that as the default “pid = /var/run/php-fpm/php-fpm.pid” instead? What’ the difference between sock and pid?

            Thanks but how do I create virtual host for my wordpress sites?

            hello , i had some problems, I install the php5.6 but the nginx cannot work with it,how to config the php5.6 and make it work with nginx

            centos7 + php5.6 + nginx

            Thanks for you comprehensive tutorial. My web server is up and running, but cannot process the php script. Every time i open http://geosukarno.com/info.php , the info.php always served as download file.

            You can see my Nginx’s /etc/nginx/conf.d/default.conf at this txt file: http://geosukarno.com/nginx__default.conf.txt

            I tried: systemctl restart nginx and: systemctl restart php-fpm didn’t help.

            Is somebody can help me, what i’m miss, that php script cannot be processed?

            I think i miss something. 8 hours until 6 hours ago, after i tried using SSL (http://www.server-world.info/en/note?os=CentOS_7&p=nginx&f=4), i tried some troubleshooting, such as restart the droplets, make sure the nginx’s default.conf as same as tutorial’s , still nginx cannot process the php script.

            I always tried call info.php on https protocol (https://geosukarno.com/info.php), still nginx didn’t process the php script. Now after 8 hour, i accidently call info.php on http protocol, and it’s work. Nginx can process the php script. This 8 hours long, i didn’t realize nginx already can process the php script, but on http protocol.

            So, another problem still not solved yet. Why nginx cannot process php script when it called on https protocol? Every time i open https://geosukarno.com/info.php , the info.php always served as download file.

            I made SSL certificate by following tutorial from server-world.info http://www.server-world.info/en/note?os=CentOS_7&p=nginx&f=4

            Now i know why nginx didn’t process php script on http protocol. Because at early time, in nginx’s /etc/nginx/conf.d/default.conf , i’m using wrong server_name. I was using server_name gitu; gitu is my hostname. But my domain for this droplet is geosukarno.com Thats why nginx didn’t process the php script on http protocol.

            You can see my first Nginx’s /etc/nginx/conf.d/default.conf that made nginx cannot process php script on http protocol at this txt file: http://geosukarno.com/nginx__1__default.conf.txt https://geosukarno.com/nginx__1__default.conf.txt

            But until now, nginx still cannot process php script on https protocol.

            This comment has been deleted

              I found why php script cannot be processed when called with https protocol on my nginx.

              The mistake is, regarding to server-world.info’s tutorial (http://www.server-world.info/en/note?os=CentOS_7&p=nginx&f=4) i put these 3 statements in /etc/nginx/nginx.conf

              listen      443 ssl;
              ssl_certificate     /etc/pki/tls/certs/server.crt;
              ssl_certificate_key /etc/pki/tls/certs/server.key;
              

              Regarding to this tutorial, we using Nginx server block configuration file in /etc/nginx/conf.d/default.conf

              Then i move those 3 statements from /etc/nginx/nginx.conf into /etc/nginx/conf.d/default.conf

              You can see my Nginx server block configuration file /etc/nginx/conf.d/default.conf at https://geosukarno.com/nginx__3__default.conf.txt

              Maybe you wondering what’s another statements on my default.conf ? Well i got that configuration statements from chrismeller’s tutorial: https://blog.chrismeller.com/configuring-and-optimizing-php-fpm-and-nginx-on-ubuntu-or-debian

              Now my nginx can process php script on http and https protocol.

              There is a slight typo in the /etc/php-fpm.d/www.conf section.

              On the code snippets, you have the file name listed as /etc/php-php.d/www.conf — X of 3

              Great guide though, thanks. I also had to set listen.owner and listen.group to nginx instead of nobody, as I was getting 502 responses.

              I’m using a brand new CentOS 7 droplet with Nginx 1.6.3 installed and I’m writing this in the year 2016.

              My problem is with the line: sudo vi /etc/nginx/conf.d/default.conf

              I am not finding the /etc/nginx/conf.d/default.conf file on my server.

              Any idea where this file is?

              Any help is definitely appreciated.

              My /etc/nginx folder has the following in it:

              total 76K
              drwxr-xr-x   4 root root 4.0K Feb  5 13:59 .
              drwxr-xr-x. 82 root root 4.0K Feb  5 16:18 ..
              drwxr-xr-x   2 root root 4.0K Jan 26 13:15 conf.d
              drwxr-xr-x   2 root root 4.0K Jan 26 13:15 default.d
              -rw-r--r--   1 root root 1.1K Jan 26 13:15 fastcgi.conf
              -rw-r--r--   1 root root 1.1K Jan 26 13:15 fastcgi.conf.default
              -rw-r--r--   1 root root  964 Jan 26 13:15 fastcgi_params
              -rw-r--r--   1 root root  964 Jan 26 13:15 fastcgi_params.default
              -rw-r--r--   1 root root 2.8K Jan 26 13:15 koi-utf
              -rw-r--r--   1 root root 2.2K Jan 26 13:15 koi-win
              -rw-r--r--   1 root root 3.9K Jan 26 13:15 mime.types
              -rw-r--r--   1 root root 3.9K Jan 26 13:15 mime.types.default
              -rw-r--r--   1 root root 1.5K Jan 26 13:15 nginx.conf
              -rw-r--r--   1 root root 2.6K Jan 26 13:15 nginx.conf.default
              -rw-r--r--   1 root root  596 Jan 26 13:15 scgi_params
              -rw-r--r--   1 root root  596 Jan 26 13:15 scgi_params.default
              -rw-r--r--   1 root root  623 Jan 26 13:15 uwsgi_params
              -rw-r--r--   1 root root  623 Jan 26 13:15 uwsgi_params.default
              -rw-r--r--   1 root root 3.6K Jan 26 13:15 win-utf
              
              

              For anyone else who has this problem. I found it! The name of the file is /etc/nginx/nginx.conf.

              Credit goes to this tutorial: https://garage.godaddy.com/tech/config/how-to-install-and-configure-nginx-on-centos-7

              Found that the server block defined in /etc/nginx/conf.d/default.conf was conflicting with the server block in /etc/nginx/nginx.conf and was downloading the php file rather than processing it. I just commented out the server block in /etc/nginx/nginx.conf and ran ` sudo service nginx restart && sudo service php-fpm restart Worked perfectly.

              This tutorial need to be update… Tested now but when i run info.php my browser try to download instead execute it ! What’s wrong ?

              listen.owner = nobody
              listen.group = nobody
              

              Should be

              listen.owner = nginx
              listen.group = nginx
              

              Else, the socket will be assigned to nobody and will have Permission denied errors for nginx.

              It seems like if we use nginx with php. we do not need to install php. the php package is for httpd

              Great tutorial, but could us an update. As of today, the default install of nginx 1.6.3 I get on my Centos 7.2 droplet has empty conf.d and default.d dirs. nginx.conf and nginx.conf.default are different, and both are slightly different from the server block described in the tutorial.

              conf.d default.d fastcgi.conf fastcgi.conf.default fastcgi_params fastcgi_params.default koi-utf koi-win mime.types mime.types.default nginx.conf nginx.conf.default scgi_params scgi_params.default uwsgi_params uwsgi_params.default win-utf

              Thanks for this tutorial.

              One thing I found concerning step three: phph-fpm: In order for php-fpm to be able to use the socket, I had to add the directory:

              [root@sargas ko]# mkdir /var/run/php-fpm
              

              Otherwise I got this error:

              [root@sargas ko]# systemctl start php-fpm
              Job for php-fpm.service failed because the control process exited with error code. See "systemctl status php-fpm.service" and "journalctl -xe" for details.
              

              If You see this message in error.log: [error] 4068#0: *1 FastCGI sent in stderr: PHP message: PHP Fatal error

              Do this:

              chmod -R 777 /var/lib/php/session
              

              In /etc/php-php.d/www.conf, you mention the socket owner and group for php-fpm should be set to “nobody,” but don’t really indicate why:

              listen.owner = nobody
              listen.group = nobody
              

              While this does appear to work for PHP 5.4 on CentOS 7, it wouldn’t for later versions of PHP. The error you’ll get is:

              *11 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (13: Permission denied) while connecting to upstream
              

              For later versions of PHP (i.e. php56u from IUS), sources indicate specifying the web server user/group would be necessary and also safe:

              I’m having an issue where there is no default.conf file in /etc/nginx/conf.d

              Thanks for sharing this info in simple steps . It works

              Hi,

              When i try to open the ‘info.php’ file it just downloads it! I’m stuck with this so i’m hoping someone can help me :P.

              This is my default.conf

              server {
                  listen       80;
                  server_name  lekkerminecraft.nl www.lekkerminecraft.nl;
              
                  root   /usr/share/nginx/html;
                  index index.php index.html index.htm;
              
                  location / {
                      try_files $uri $uri/ =404;
                  }
                  error_page 404 /404.html;
                  error_page 500 502 503 504 /50x.html;
                  location = /50x.html {
                      root /usr/share/nginx/html;
                  }
              
                  location ~ \.php$ {
                      try_files $uri =404;
                      fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                      fastcgi_index index.php;
                      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                      include fastcgi_params;
                  }
              }
              

              Hello…

              I did everything, but it doesn’t open php files. It’s downloading all…

              set up nginx conf file for php processing, and sudo systemctl restart nginx

              after instaling php i update php to 5.6.30 version

              now i have problem with nginx configuration

              /etc/nginx/conf.d/default.conf is missing i set configuration in /etc/nginx/nginx.conf

              but when i create info.php file i have

              The page you are looking for is temporarily unavailable. Please try again later.
              /usr/share/nginx/html/50x.html
              

              SOLVE: uncomment line listen.mode = 0660 in /etc/php-fpm.d/www.conf

              I get this error every time I install php, everything works great until I install php then I no longer get access to my page. I am a noob to this but I have tried php on httpd and now on nginx and I get the same result, so what am I doing wrong LOL I followed these instructions and installed on CentOS 7.

              This site can’t be reached

              http://192.168.1.74/info.php is unreachable. Search Google for info ERR_ADDRESS_UNREACHABLE

              Please help :)

              What could I be doing wrong, to have nginx download the php files instead of executing them?

              i ran into this problem, just have to set up the nginx conf file properly. and then make sure to restart server with sudo systemctl restart nginx

              systemctl: command not found ? Why ? On Centos 6.9

              A disgusting article. I’m very sorry that I started configuring my server for it. Everything works with .html files, but as soon as I deal with .px, I download the file. How to solve this problem?

              If you can’t see the Nginx default page after installing it might due to a firewall ! Just run this and it should work :

              sudo firewall-cmd --permanent --zone=public --add-service=http 
              sudo firewall-cmd --permanent --zone=public --add-service=https
              sudo firewall-cmd --reload
              

              very helpful in setting up my webserver using nginx and getting the php/mysql stuff working. thanks so much for the writing!

              If you look at the line below with “location ~ .php$ {” That should be a forward slash like this… “location ~ /.php$ {”

              -Carlos

              server { listen 80; server_name server_domain_name_or_IP;

              # note that these lines are originally from the "location /" block
              root   /usr/share/nginx/html;
              index index.php index.html index.htm;
              
              location / {
                  try_files $uri $uri/ =404;
              }
              error_page 404 /404.html;
              error_page 500 502 503 504 /50x.html;
              location = /50x.html {
                  root /usr/share/nginx/html;
              }
              
              location ~ \.php$ {
                  try_files $uri =404;
                  fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                  fastcgi_index index.php;
                  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                  include fastcgi_params;
              }
              

              }

              This was a great instruction guide, however the major part which is lacking for everyone is a basic troubleshooting guide.

              Even though these instructions are clear, they lack a helping hand when it comes to simple troubleshooting or overlooking an aspect of the config files.

              What will be great is an addition of 1-3 examples of issues that most users will run into when following these instructions.

              That way it can be referred back to when someone is really not sure of what was overlooked or missed.

              How do use one vps for multi website?

              I followed this article, but finally get info.php file instead of open it correctly. Who can help me please?

              I got error 50x when accessing info.php

              Great article guys, super helpful.

              One thing I had to do was install yum-utils in order to run

              sudo yum-config-manager --enable remi-php74
              

              I’m on CentOS 7.9, just incase anyone else has the same problem.

              Use this script to install LEMP stack on CENTOS https://github.com/amith7319/LEMP-Stack.git

              Excellent article and saved me hours. Refer to it every time I install a LEMP server.

              Try DigitalOcean for free

              Click below to sign up and get $200 of credit to try our products over 60 days!

              Sign up

              Join the Tech Talk
              Success! Thank you! Please check your email for further details.

              Please complete your information!

              Become a contributor for community

              Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

              DigitalOcean Documentation

              Full documentation for every DigitalOcean product.

              Resources for startups and SMBs

              The Wave has everything you need to know about building a business, from raising funding to marketing your product.

              Get our newsletter

              Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

              New accounts only. By submitting your email you agree to our Privacy Policy

              The developer cloud

              Scale up as you grow — whether you're running one virtual machine or ten thousand.

              Get started for free

              Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

              *This promotional offer applies to new accounts only.