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:
- 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…
- 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…
- How To Install Flask Nginx On Ubuntu 1604 How To Install Flask Nginx On Ubuntu 1604 Introduction Flask is a web application framework based on Python. It is highly useful for web developers due to its flexibility and…
- 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…
- How To Hide Nginx In Centos 7 How To Hide Nginx In Centos 7 What is Nginx? Nginx is a powerful web server and is one of the most popular web server software available today. It's a…
- Certbot Centos 7 Nginx Staging Certbot Centos 7 Nginx Staging: An Easy Step By Step Guide What Is Certbot? Certbot is a free, open-source software tool that allows you to easily obtain digital certificates from…
- 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…
- Install Rails On Ubuntu Nginx Rbenv Install Rails On Ubuntu Nginx Rbenv Introduction Rails is an open-source web application framework written in Ruby. It is designed to make programming web applications easier by providing a full…
- Centos7 Nginx Php-Fpm Sock CentOS7 Nginx Php-Fpm Sock What is CentOS? CentOS (Community ENTerprise Operating System) is a Linux distribution that provides a free, enterprise-class, community-supported computing platform functionally compatible with its upstream source,…
- How To Start Nginx On Centos 7 How To Start Nginx On Centos 7 Overview Nginx is a high-performance web server that is used to serve web pages and applications. It is a widely-used open source software…
- 502 Bad Gateway Nginx Centos Gcloud 502 Bad Gateway Nginx Centos Gcloud What is a 502 Bad Gateway Error? The 502 Bad Gateway error is an HTTP status code that occurs when a server, like a…
- Setting Php Nginx Ubuntu Vps Setting Up a PHP, Nginx, and Ubuntu VPS What is a VPS? A Virtual Private Server (VPS) is a type of virtualized hosting. It works in the same way as…
- Nginx Php-Fpm Php Mariadb Mysql Centos 7.2 Digitalocean Nginx, Php-Fpm, Php, Mariadb, Mysql, Centos 7.2 Digitalocean Introduction: What is Nginx? Nginx is a powerful web server that was first released in 2004. It is known for being a…
- How To Install Lets Encrypt On Centos 7 Nginx How To Install Lets Encrypt On Centos 7 Nginx Purpose of Lets Encrypt Lets Encrypt is a free and open-source encryption certificate authority that provides digital certificates to website owners…
- How To Install Cachet Nginx How To Install Cachet Nginx Overview Cachet is an open-source monitoring platform that is widely used by web developers, DevOps engineers, and system administrators for monitoring the performance of a…
- Can I Install Phpmyadmin In Nginx Can I Install Phpmyadmin In Nginx? PHPmyadmin is a web-based management tool for databases such as MySQL and MariaDB. It is a popular tool for web developers and database administrators…
- 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…
- Centos 7.6 Nginx 403 Forbidden Centos 7.6 Nginx 403 Forbidden Introduction Nginx is a reliable, high-performance web server that is popular among developers and system administrators alike. It is a powerful and efficient open source…
- 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…
- Install Phpmyadmin On Nginx Centos 7 Install Phpmyadmin On Nginx Centos 7 Introduction PhpMyAdmin is one of the most popular tools used to manage and administer a MySQL database. It is a web-based application and can…
- 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…
- 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…
- Linux Nginx Mysql Php Lemp Linux Nginx Mysql Php Lemp What is Linux, Nginx, MySQL, PHP (LEMP)? Linux, Nginx, MySQL, PHP (LEMP) is a software stack combination of Linux, Nginx, MySQL, and PHP, commonly referred…
- Remove Nginx Completely Centos 7 Remove Nginx Completely Centos 7 Overview This article will provide a brief overview of Nginx, some of the ways it can be removed from a Centos 7 system and directions…
- 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…
- Nginx Service Is Failed On Centos 7 Nginx Service Is Failed On Centos 7 Introduction Nginx is an open source Web server and a reverse proxy for HTTP, SMTP, POP3 and IMAP protocols. It can also be…
- Install Nginx Di Kali Linux Install Nginx Di Kali Linux Introduction Kali Linux is a well-known operating system specially designed for Penetration Testing and Security Auditing tasks. The operating system is loaded with all the…
- 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…
- 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…
- Openldap Slapd Php Nginx Ldap Centos Openldap Slapd Php Nginx Ldap Centos What is OpenLDAP OpenLDAP is an open-source implementation of the Lightweight Directory Access Protocol (LDAP) and is offered by the OpenLDAP project. OpenLDAP is…