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:
- New Version Nginx Stable Centos 7 New Version Nginx Stable Centos 7 Introduction to Nginx Nginx is an open-source, high-performance web server and reverse proxy with a strong focus on scalability, security, and performance. It 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…
- 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…
- Nginx Config Test Centos 7 Nginx Config Test Centos 7 What is Nginx? Nginx is an open-source, high-performance web server that can be used to host static files, and also to serve dynamic requests such…
- Instal Python Web Centos 7 Django Nginx Instal Python Web Centos 7 Django Nginx Introduction to Installing Python Web Centos 7 Django Nginx In this article, we will be covering an installation of Python web framework Django,…
- 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…
- 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,…
- Install Web Server Nginx Centos 7 Install Web Server Nginx Centos 7 Introduction Are you looking for a way to set up a web server on your Linux-based system? If so, then installing Nginx on CentOS…
- 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…
- Remove Apache And Install Nginx Remove Apache And Install Nginx What is Apache and Nginx? Apache and Nginx are both popular web servers used to serve web pages and content to users on the web.…
- 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…
- How To Install Laravel On Centos 7 With Nginx How To Install Laravel On Centos 7 With Nginx What is Laravel? Laravel is an open-source framework for web development built on the model-view-controller (MVC) architectural pattern. Created in 2011…
- Centos 6 Nginx Auto Reject When Upload Files Centos 6 Nginx Auto Reject When Upload Files Introduction to Centos 6 Centos 6 is a powerful, open-source Linux distribution that has been designed for advanced user, administrators, and server…
- Install Nginx Postgres Centos 7 Install Nginx Postgres Centos 7 Introduction to Nginx and Postgres Nginx is an open source web server that has been gaining in popularity in recent years due to its reliability,…
- How To Install Http 3 Nginx How To Install Http 3 Nginx Prerequisites Before Installation When installing the HTTP 3 Nginx server, there are some prerequisites that need to be addressed first. Most notably, you will…
- Remove Apache And Install Nginx Centos 7 Remove Apache And Install Nginx Centos 7 Introduction Apache is an open source HTTP server used for hosting websites and web applications on the web. Although Apache is reliable and…
- Instal Nginx Centos Di Webuzo Instal Nginx Centos Di Webuzo Background Webuzo is a leading web server platform used by individuals and businesses alike. It supports a range of operating systems, including the popular CentOS…
- Config Ssl On Nginx Centos 7 Config SSL On Nginx Centos 7 Overview Secure Sockets Layer (SSL) is a type of cryptographic protocol used for secure communications on the Internet, as well as for secure access…
- 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…
- Access Nginx On Virtual Box Centos 7 Access Nginx On Virtual Box Centos 7 Introduction Nginx is a web server and proxy written in C. It is used to serve webpages and proxy requests. It is fast…
- Compiling Nginx From Source Centos 7 Compiling Nginx From Source Centos 7 Overview Nginx is a web server that is used to host websites, from small personal sites to large web applications. It is open source,…
- Install Nginx Server On Centos 7 Install Nginx Server On Centos 7 What Is Nginx? Nginx is an open source web server and reverse proxy developed by Igor Sysoev in 2004. It is an efficient web…
- 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…
- Install Nginx Ssl On Centos 7 Install Nginx Ssl On Centos 7 1. Overview Of Nginx SSL NGINX SSL (Secure Socket Layer) is an open source web server designed to provide reliable and secure web application…
- Laravel On Nginx Centos 7 Laravel On Nginx Centos 7 Introduction Laravel is an open-source MVC (model-view-controller) web framework for PHP. It is free and has been used by many developers to create great websites…
- Check Nginx Version Centos 7 Check Nginx Version Centos 7 1. What is Nginx? Nginx is an open source web server software created by Igor Sysoev in 2002 and is widely used for powering the…
- 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…
- Nginx Reverse Proxy Centos 7 Nginx Reverse Proxy Setup on Centos 7 What is a Reverse Proxy? A reverse proxy is a type of server that takes a client request, then forwards the request to…
- 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…
- Install Nginx Php Fpm Centos 7 Install Nginx Php Fpm Centos 7 Prerequisites Before you start installing Nginx and Php-Fpm on CentOS 7, make sure the following prerequisites are in place. CentOS 7 must be installed…