Centos 7 Install Nginx Php 7
Nginx Server Overview and Prerequisites
Nginx is a highly popular open source web server and reverse proxy software, known for its scalability and performance in the face of increased web traffic. It is used for the hosting of websites, web applications, and other services. The Nginx server is easy to install, configure and make ready for use to serve websites and web services.
Before you start setting up Nginx on your Centos 7 server, you need to ensure that you have the necessary prerequisites such as an up-to-date Centos 7 server with a valid domain name and a static IP address. You should also make sure that your server is properly configured with a suitable firewall. Finally, you’ll need to set up some additional packages such as PHP, MySQL and more.
Installing and Configuring Nginx
Once the prerequisites are taken care of, you’re now ready to proceed with the installation and configuration of Nginx. To install Nginx on our Centos 7 system, we’ll be using the yum package manager. Start off by adding the Nginx software repository that contains all the packages needed for the installation.
Run the following command to add the Nginx repository:
sudo yum -y install epel-release yum-utils
Then, you can use the yum-config-manager to add the Nginx repository with the following command:
sudo yum-config-manager –add-repo https://nginx.org/packages/centos/7/x86_64/
Next, to install Nginx, run the following command:
sudo yum -y install nginx
Once you’ve installed Nginx, you’re now ready to proceed with its configuration. To do this, you’ll need to edit the Nginx configuration file, which is located at /etc/nginx/nginx.conf. This can be done by running the following command:
sudo vi /etc/nginx/nginx.conf
Edit the server section to look like the following:
server {
listen 80 default_server;
server_name your_domain_name_or_IP;
root /var/www/html;
index index.html index.htm;
}
Save and exit the file. Now, start and enable Nginx with the following commands:
sudo systemctl start nginx
sudo systemctl enable nginx
Configuring the Firewall
To make sure that Nginx is accessible from outside our local network, we need to configure the firewall to allow incoming requests on port 80. To do this, run the following command:
sudo firewall-cmd –permanent — add-service=http
Once this is done, you’ll need to reload the firewall for the changes to take effect. To do this, run the following command:
sudo firewall-cmd –reload
You can then go ahead and test if Nginx is working by running the following command:
sudo systemctl status nginx
Installing and Configuring PHP 7
Now, the next step is to install and configure PHP. To install PHP 7, we’ll need to add some additional repositories to our system. Run the following command to add the EPEL repository:
sudo yum -y install epel-release
Then, run the following command to add the Webtatic repository:
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Now, install PHP 7 with all its necessary modules by running the following command:
sudo yum -y install php70w php70w-common php70w-opcache php70w-fpm php70w-gd php70w-mysql php70w-mcrypt
Once the installation is completed, start and enable PHP-FPM by running the following commands:
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
Configuring Nginx and PHP-FPM
With Nginx and PHP-FPM now installed and running, the next step is to configure them to work together. This can be done by running the following command:
sudo vi /etc/nginx/nginx.conf
Add the following lines at the bottom of the file:
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
Save and exit the file. Now, restart Nginx for the changes to take effect by running the following command:
sudo systemctl restart nginx
Testing Nginx and PHP-FPM
To test whether Nginx and PHP-FPM are working correctly together, create a test PHP file with the following contents:
sudo vi /var/www/html/info.php
phpinfo();
?>
Save and close the file. Then, open your web browser and navigate to http://your_domain_or_IP/info.php. You should see the PHP info page, which confirms that Nginx and PHP-FPM are working correctly together.
FAQs
Q) How to install Nginx on Centos 7?
A) To install Nginx on your Centos 7 server, you need to add the Nginx software repository that contains all the packages needed for the installation. Then, you can use the yum package manager to install Nginx with the following command:
sudo yum -y install nginx
Q) How to configure a firewall to allow Nginx requests?
A) To make sure that Nginx is accessible from outside our local network, we need to configure the firewall to allow incoming requests on port 80. To do this, run the following command:
sudo firewall-cmd –permanent — add-service=http
Q) How to install PHP 7 on Centos 7?
A) To install PHP 7 on your Centos 7 system, you’ll need to add some additional repositories to your system. Then, use the yum package manager to install PHP 7 with all its necessary modules by running the following command:
sudo yum -y install php70w php70w-common php70w-opcache php70w-fpm php70w-gd php70w-mysql php70w-mcrypt
Conclusion
In this article, we’ve gone through the process of installing and configuring Nginx and PHP 7 on a Centos 7 server. We’ve also covered how to configure the firewall to allow incoming requests on port 80. We hope you’ve found this article helpful.
Thank you for reading this article. Please read other articles on this website as well.
Related Posts:
- Nginx Php Fpm 7.2 Nginx Php Fpm 7.2 Introduction to Nginx and PHP-FPM Nginx is an open-source web server, reverse proxy server, and load balancer. It is known for being lightweight and fast, and…
- How To Install Nginx On Debian 10 How To Install Nginx On Debian 10 Overview In this guide, we will show how to install Nginx on a Debian 10 server. Nginx (pronounced “engine-x”) is an open source…
- Reverse Proxy Nginx Dan Windows Server Reverse Proxy Nginx Dan Windows Server Introduction to Reverse Proxy Reverse proxy is a server that is used to receive requests from the Internet and forward them to other servers.…
- Failed Install Nginx On Centos Failed Install Nginx On Centos What is Nginx? Nginx is an open source web server designed to handle high traffic websites. It has proven to be reliable over the years…
- Nginx Centos 7.6 Virtual Host Nginx Centos 7.6 Virtual Host Introduction to Nginx Virtual Hosts Virtual Hosts, also called Virtual Servers, are a very important function of web hosting. They allow multiple websites to run…
- How To Install Nginx On Centos 7 Rhel 7 How To Install Nginx On Centos 7 Rhel 7 Nginx is one of the most popular web servers around the globe – being an open-source application, it drives a large…
- How Use Nginx Mysql Ubuntu How to Use Nginx, MySQL and Ubuntu What is Nginx? Nginx is an open source web server and reverse proxy software written by Igor Sysoev. It is a popular choice…
- Reverse Proxy Nginx Centos 7 Reverse Proxy Nginx Centos 7 What is a Reverse Proxy? A reverse proxy is a type of proxy server that retrieves resources on behalf of a client from one or…
- Centos 7 Enable Nginx On Boot Centos 7 Enable Nginx On Boot Overview The ability to enable Nginx on Boot in CentOS 7 is a useful feature for web developers and server administrators. This article will…
- Nginx Proxy Cache Redis Wordpress Centos Nginx Proxy Cache Redis Wordpress Centos Understanding Nginx Proxy Cache Nginx Proxy Cache is a web-acceleration software from Nginx, Inc. It is designed to speed up dynamic web content delivery.…
- Install Php5 Nginx Ubuntu 18.04 Install PHP5 Nginx Ubuntu 18.04 Understanding The Basics of Nginx and PHP Before we learn how to install Nginx and PHP on Ubuntu 18.04, it’s important to understand the basic…
- Ldap Not Found Centos Nginx Php Ldap Not Found Centos Nginx Php What is LDAP? LDAP, or Lightweight Directory Access Protocol, is a standard protocol for storing user and server information over a network. It is…
- Tutorial Start Nginx Ubuntu Webserver Tutorial Start Nginx Ubuntu Webserver Step 1: Prerequisites Before we start configuring Nginx as a web server on Ubuntu, we need to make sure we have the following prerequisites: A…
- How To Config Nginx Upstream On Centos 7 How To Config Nginx Upstream On Centos 7 What is Nginx? Nginx is an open source, high performance web server and reverse proxy developed by Igor Sysoev in 2004. It…
- 404 Nginx Phpmyadmin Centos 7 404 Nginx Phpmyadmin Centos 7 Configuration of Nginx on Centos 7 for Phpmyadmin Setting up Nginx on Centos 7 to work with Phpmyadmin is a very simple process. The first…
- Centos 7 Nginx Letsencrypt Https And Https Centos 7 Nginx Letsencrypt Https And Https Overview Many web servers require secure communications through the HTTPS protocol, and the most common way to do this is with the help…
- Nginx What's Folder Dev Mapper Centos-Root Nginx What's Folder Dev Mapper Centos-Root What Is Nginx? Nginx is an open source web server created in 2004 by Igor Sysoev. It is a high-performance web server with a…
- Install Php Nginx Ubuntu 12.04 Install Php Nginx Ubuntu 12.04 Introduction Welcome to our guide on How to install PHP, Nginx & MySQL on Ubuntu 12.04 LTS. This guide should work on other Linux VPS…
- User Nginx Does Not Exist Centos User Nginx Does Not Exist Centos What is Nginx? Nginx, pronounced “engine-x”, is an open source web server, reverse proxy server, IMAP/POP3 proxy server, and HTTP cache server. Nginx has…
- Setting Proxy Nginx Centos 7 Setting Proxy Nginx Centos 7 Introduction Setting up a proxy server on a CentOS 7 server is a relatively straightforward task. Nginx is a powerful open source reverse proxy server…
- Ubuntu Server Postgresql Nginx Php Digitalocean Laravel Ubuntu Server Postgresql Nginx Php Digitalocean Laravel Introduction To The Stack Ubuntu Server, Postgresql, Nginx, PHP, Digitalocean and Laravel are an exceptional combination of elements that, when put together, make…
- Centos 7 Migrate From Apache To Nginx Centos 7 Migrate From Apache To Nginx Introduction CentOS 7 is a popular Linux operating system (OS) that is used in many businesses and organizations. It is a stable and…
- Nginx Docker Swarm Config With Defferent Server Nginx Docker Swarm Config With Different Server Introduction to Nginx and Docker Nginx is a popular open-source web server that is used for serving static content, as well as for…
- Selinux Enable Php Fpm Nginx Centos 7 Selinux Enable Php Fpm Nginx Centos 7 What is Selinux Enable Php Fpm Nginx Centos 7? Selinux Enable Php Fpm Nginx CENTOS 7 is an easy-to-use web server and operating…
- Nginx Reverse Proxy Apache Centos Nginx Reverse Proxy Apache Centos Overview Nginx is one of the most popular web servers on the internet, used by millions of people to host websites, applications, and services. It…
- Cannot Start Nginx On Centos 7 Failed To Exec Airflow Cannot Start Nginx On Centos 7 Failed To Exec Airflow What Is Nginx in Centos 7? Nginx is an open source web server that powers some of the largest and…
- Bash Install Nginx On Ubuntu How To Install Nginx On Ubuntu What is Nginx? Nginx is a web server that is gaining popularity in the world of web hosting. Nginx is an open source web…
- Install Nginx Phpmyadmin Centos 7 Install Nginx Phpmyadmin Centos 7 What is Nginx? Nginx is a web server that is used in Linux-based operating systems such as Centos 7. It is designed to handle high-traffic…
- Web Server Nginx Install Di Centos 7 Web Server Nginx Install Di Centos 7 Introduction to Nginx Nginx is a popular open source web server used to host websites and other applications. It is known for its…
- Error 502 Nginx On Server Centos Error 502 Nginx On Server Centos What is Error 502 Nginx On Server Centos? Error 502 Nginx On Server Centos is a type of HTTP status code error that occurs…