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:
- Setup Centos 7 Nginx With Php Setup Centos 7 Nginx With Php Overview of Centos7 Nginx and PHP Centos 7 is one of the most popular operating systems for web servers. Many businesses use Centos 7…
- Docker Compose Nginx Reverse Proxy Docker Compose Nginx Reverse Proxy Introduction to Docker Compose and Nginx Docker Compose is a powerful tool used for automating the deployment of application services using multiple Docker containers. It…
- 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…
- Centos 6 Nginx Phpmyadmin Forbideen Centos 6 Nginx Phpmyadmin Forbidden Introduction CentOS 6, an open-source Linux operating system, is one of the most popular web server operating systems. It is considered to be a reliable…
- 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…
- How To Configure Virtual Host In Nginx On Centos 7 How To Configure Virtual Host In Nginx On Centos 7 Introduction We all need to configure virtual host on Nginx webserver on CentOS 7 in order to place multiple websites…
- 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…
- 502 Bad Gateway Nginx Fix Centos 502 Bad Gateway Nginx Fix Centos Introduction 502 Bad Gateway Nginx is an HTTP status code that indicates that the server transmitted an invalid response due to an error. This…
- Setting Up Passenger And Nginx Ubuntu 18.04 Setting Up Passenger And Nginx Ubuntu 18.04 Installing the Passenger Gem Passenger is an open source framework created by Phusion which allows easy integration of Nginx with Ruby applications such…
- Nginx Multi Domain Centos 7 Nginx Multi Domain Centos 7 Introduction to Nginx Nginx is an open source, high performance web server software written in C language, designed to be deployed on Linux and Unix-like…
- 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…
- 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…
- Start Nginx Service Centos 7 Start Nginx Service Centos 7 Before You Start: Server and Requirements If you are running a website or a web application on Centos 7, chances are you will be using…
- 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…
- 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 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…
- Create Virtual Host Nginx Centos 7 Create Virtual Host Nginx Centos 7 What is a Virtual Host? A virtual host is a server hosting multiple domain names on the same web server. This type of hosting…
- 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…
- 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…
- 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…
- Installing Nginx On Centos 7 Installing Nginx On Centos 7 What is Nginx? Nginx is an open source, high performance web server software. It is commonly used for caching static web pages to speed up…
- 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…
- 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…
- 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…
- Speed Up Vestacp On Centos 7 Nginx Apache Speed Up VestaCP On Centos 7 Nginx Apache Overview of the Setup VestaCP is a popular hosting control panel that uses a set of open source servers and applications to…
- Centos 6 Nginx Multiple Php Version Centos 6 Nginx Multiple PHP Versions What is CentOS 6? CentOS 6 is a Linux-based operating system. It is a free, open-source operating system that is based on Red Hat…
- 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 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…
- 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…
- 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…