fedora nginx php fpm
Installing Nginx Web Server with MariaDB and PHP/PHP-FPM on Fedora 23
Fedora 23 has been released just a few days ago and we have been closely following ever since. We have already covered the installation of Fedora 23 Workstation and Server. If you haven’t checked those articles yet, you can find them on the links below:
In this article, we are going to show you how to install LEMP stack. LEMP is a combination of web tools designed for web projects. LEMP includes the – Linux, Nginx (pronounced Engine X), MariaDB and PHP.
Install Nginx, MariaDB and PHP (PHP-FPM) in Fedora 23
The installation of Fedora has already been completed so we are ready to proceed with the next part. If you haven’t, you can refer to the links above, to help you with the installation process. To make it easier to follow up and understand, I will separate the article in three parts. One for each package.
Before we start, it is recommend that you update your system packages. This can be easily achieved with command such as:
Update Fedora 23 Packages
1. Install Nginx Web Server
1. Nginx is a light weight web server designed for high performance with low resource consumption on servers. It is often the preferred choice in enterprise environment due to its stability and flexibility.
Nginx can be easily installed fedora with single command:
Install Nginx in Fedora 23
2. Once nginx has been installed, there are few more important steps to do. First we will setup Nginx to automatically enable upon system boot and then we will start and confirm the status of Nginx.
Enable Start Verify Nginx
3. Next we will add a firewall rule, that will allow us to access the standard http and https ports:
Open Nginx HTTP Port on FirewallD
4. Now let’s verify if nginx is running as expected. Find your IP address by issuing the following command:
Find Fedora 23 Server IP Address
5. Now copy/paste that IP address into your browser. You should see the following result:
6. Next, we need to configure Nginx Sever Name, open the following configuration file with vi editor.
Find the directive “server_name”. It’s current status will be set to:
Change the underline with the IP address of your server:
Note: Make sure to change this with the IP address of your own server!
2. Install MariaDB
7. MariaDB is a relational database server that is slowly becoming the top choice for new releases of different Linux distributions.
MariaDB is a community fork of the famous MySQL database server. MariaDB is meant to remain free under the GNU GPL, which is one of the reasons it is the preferred choice over MySQL.
To install MariaDB on your Fedora 23 server, run the following command:
Install MariaDB in Fedora 23
8. Once the install is complete, we can set MariaDB to automatically start upon system boot and start the MariaDB server with the following commands:
Enable and Start MariaDB
9. The next step is optional, but recommended. You can secure your MariaDB installation and set new password for the root user. To secure the installation run the following command:
Th is will start a series of questions that you will need to answer in order to secure your installation. The question are really easy and don’t require any additional explanations. Here is a sample configuration that you can use:
Enter MariaDB Root Password
MySQL Secure Installation
3. Install PHP and Its Modules
10. The final step of our setup is the installation of PHP. PHP is a programming language used for developing dynamic web applications. Many websites over the internet are built using this language.
To install PHP in Fedora 23 is quite easy. Start by running the command below:
Install PHP and PHP FPM
11. To be able to run PHP files, minor changes to the PHP configuration are required. By default the user meant to use php-fpm is Apache.
This would need to be changed to nginx. Open the www.conf file with your favorite text editor such as nano or vim:
Find the following lines:
Change «apache» with «nginx» like shown below:
Configure Nginx PHP-FPM
12. Now save the file We will need to restart php-fpm and Nginx to apply the changes. The restart can be completed with:
And check it’s status:
Start and Verify Php-Fpm
13. The time has come to put our setup to the test. We will create a test file called info.php in Nginx’s web root directory /usr/share/nginx/html/:
In that file insert the following code:
Save the file and access your system’s IP address in browser. You should see the following page:
Verify PHP and PHP-FPM
Conclusion
Congratulations, your LEMP stack setup on Fedora 23 server is now complete. You can start testing your new projects and play around with PHP and MariaDB. If you have any questions or found any difficulties while setting up LEMP on your system, please share your experience in the comment section below.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Setting Up Nginx with MariaDB and PHP/PHP-FPM on Fedora 24 Server and Workstation
You must have probably installed Fedora 24 server edition on your machine and you are eager and looking forward to setting up a web server to run websites and web applications. Look no further, because we shall do all that here, with simple and easy steps that you will appreciate at the end.
Install Nginx, MariaDB, PHP and PHP-FPM on Fedora 24
In this how to guide, we shall run through the different steps of how you can install LEMP stack on your Fedora 24 web server. Similar to LAMP, but under LEMP, we use Nginx web server.
Step 1: Updating System Packages
You can get started by updating your system packages as follows:
Update Fedora 24 Server
When that is done, proceed to install the composite LEMP packages.
Step 2: Install Nginx Web Server
Nginx is an alternative to Apache web server, it is light weight and consumes less system resource hence its high performance, stability and flexibility in enterprise productions environments.
To install Nginx on Fedora 24, issue the command below:
Install Nginx on Fedora 24 Server
Once the installation is complete, you need to manage the Nginx service on your system. First you need to set it to start automatically at boot time by running the command below:
Then start the service as follows:
# systemctl start nginx.service
Next, check to see that Nginx server is running, you can issue the command below to do that:
Start and Verify Nginx Web Server
In order to view your Nginx web server over HTTP/HTTPS protocol, you need to allow access to it through the system firewall. To do so, run the following commands:
Then reload the system firewall configurations to effect the above changes as follows:
Open Apache Ports on Firewalld
Now move on to set your Nginx server_name directive, using your favorite editor, open the file /etc/nginx/nginx.conf and find the configuration directive as shown:
Configure Nginx Web Server
One more important thing to do under Nginx installation is to check whether the Nginx installation index page can load in your web browser, therefore open your web browser and enter the URL:
You should be able to view this page below:
Check Nginx Web Page
Step 3: Install MariaDB Server
MariaDB is a fork of the most famous MySQL relational database server, to install MariaDB on Fedora 24 server, issue the command below:
Install MariaDB on Fedora 24 Server
After completing the MariaDB installation, you need to enable, start and verify the service by running following series of commands.
Start and Verify MariaDB Service
Now it’s time to secure your MariaDB installation using following command:
After executing above command, you will be asked a few questions as follows:
Secure MariaDB Installation
Step 4: Install PHP and Modules
To install PHP on Fedora 24 along with its modules, use the command below:
Install PHP and PHP-FPM Module
Now that PHP and some PHP modules have completed installing, you need to configure PHP so that you can run PHP files.
By default, PHP-FPM is configured to be used with Apache web server, but for our case here, we are using Nginx web server. Therefore we need to change that setting in the steps below:
Using your favorite editor, open the file /etc/php-fpm.d/www.conf as follows:
Then change the values of user and group from apache to nginx in the following lines:
Configure PHP-FPM for Nginx
Then restart PHP-FPM and Nginx web server to effect the changes above:
After that, confirm that they are running be issuing the commands below:
Now you can test it all, using your favorite editor, create a file called info.php in your Nginx root directory as follows:
Add the following lines in the file, save it and exit.
Then open your web browser and enter the following URL to verify the PHP information:
Verify PHP Details
At this point, you must have successfully installed and configured LEMP stack on your Fedora 24 server. In a few cases, some of you must have encountered errors or want more explanation concerning an issue of concern, you can leave a comment in the comment section below and we shall find solutions together.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Install Nginx with PHP 7.2.10 and PHP-FPM on Fedora 29 and RHEL/Centos 7.6
In this tutorial we will show you how to install Nginx in Combination with last php stable version and included PHP-FPM (FastCGI Process Manager)
i will not explain about nginx, i assume that everyone knows that very perfect web server and even better than apache
My Servers is Centos 7 with IP : 192.168.2.98
Client is Debian 9 with IP : 192.168.2.98
A.1 Change to root user.
A.2 Install Needed repositories
CentOS 7.5/6.10 and Red Hat (RHEL) 7.5/6.10 Remi repository
CentOS 7.6/6.10 and Red Hat (RHEL) 7.6/6.10 add Nginx repository
Create repo file /etc/yum.repos.d/nginx.repo :
For CentOS
Red Hat (RHEL)
A.3 Install Nginx, PHP 7.2.11 and PHP-FPM
Fedora 28
Fedora 27/26
CentOS 7.6/6.10 and Red Hat (RHEL) 7.6/6.10
1.4 Install PHP 7.2.11 modules
OPcache (php-opcache) – The Zend OPcache provides faster PHP execution through opcode caching and optimization.
APCu (php-pecl-apcu) – APCu userland caching
CLI (php-cli) – Command-line interface for PHP
PEAR (php-pear) – PHP Extension and Application Repository framework
PDO (php-pdo) – A database access abstraction module for PHP applications
MySQL (php-mysqlnd) – A module for PHP applications that use MySQL databases
PostgreSQL (php-pgsql) – A PostgreSQL database module for PHP
MongoDB (php-pecl-mongodb) – PHP MongoDB database driver
Redis (php-pecl-redis) – Extension for communicating with the Redis key-value store
Memcache (php-pecl-memcache) – Extension to work with the Memcached caching daemon
Memcached (php-pecl-memcached) – Extension to work with the Memcached caching daemon
GD (php-gd) – A module for PHP applications for using the gd graphics library
XML (php-xml) – A module for PHP applications which use XML
MBString (php-mbstring) – A module for PHP applications which need multi-byte string handling
MCrypt (php-mcrypt) – Standard PHP module provides mcrypt library support
Select what you need: OPcache, APCu, CLI, PEAR, PDO, MySQL, PostgreSQL, MongoDB, Memcache, Memcached, GD, MBString, MCrypt, XML
Install PHP with all Included Modules
Fedora 29
Fedora 28
CentOS 7.5/6.10 and Red Hat (RHEL) 7.5/6.10
Check PHP version Installed :
Stop httpd (Apache)
Start Nginx
Start PHP-FPM
## Fedora 28/29 and CentOS/RHEL 7.5 ##
systemctl start php-fpm.service
## CentOS/RHEL 6.10 ##
/etc/init.d/php-fpm start ## use restart after update
## OR ##
service php-fpm start ## use restart after update
1.6 Autostart Nginx and PHP-FPM on boot, also prevent httpd (Apache) autostarting on boot
Prevent httpd (Apache) autostarting on boot
Autostart Nginx on boot
Autostart PHP-FPM on boot
A.7 Configure Nginx and PHP-FPM
Latest Fedora Nginx + PHP-FPM builds use custom config, first restore default config
Restore nginx configs to default
This is how my nginx conf file look like
Modify PHP-FPM to listen ip instead of socket ##
vi /etc/php-fpm.d/www.conf
public_html directory for site Osradar.local
add logs under /var/log directory.
my Vhost Configuration File
cat /etc/nginx/conf.d/osradar.local.conf
Start Nginx
Add your testsite.local “domain” to /etc/hosts file
/etc/hosts file Nginx on same machine
A.8 Test your Nginx and PHP-FPM setup
Create /var/www/osradar.local/test.php file with following content:
Note:
If you get 403 forbidden error, then you probably have problem with SELinux, then run simply following command:
## Or some apps might need httpd_sys_rw_content_t ##
B.0 (Open Port 80 on Iptables Firewall)
Add following INPUT rule:
B.1 Restart Iptables Firewall:
B.2. Fedora 28/29 and CentOS/Red Hat (RHEL) 7.6
B.2.1 Add New http Rule to Firewalld
B.2.2 Restart firewalld.service
3. Test remote connection
Access following address, with your browser. http://osradar.local/
note: i have already crated index.html with the text showing bellow on /var/www/osradar.local/index.html
Test PHP conf file http://osradar.local/test.php
Please let us know if you still have any issues so that we can solve it together. Enjoy
How to install and configure NGINX on Fedora
So you’ve just gotten your new self-managed server and want to install and configure NGINX. Congratulations on a wise decision. As a savvy web professional, you likely already know some of the advantages of the NGINX web server as opposed to the traditional Apache configuration. This guide will help you with replacing Apache with NGINX on a new server. It assumes a certain level of previous server administration knowledge, or at least a willingness to learn. This guide is not for everyone, but if you’re ready to grab the bull by the horns and deploy a web stack using NGINX, then you may use this guide as a first step to building common web stacks such as Node.js, LEMP, and popular web frameworks such as Django.
What is NGINX?
NGINX (pronounced Engine ex) was released for production in 2004 and is rapidly becoming a popular alternative to the traditional Apache web server suite. It features an event-driven design, which can make better use of today’s computer hardware than Apache’s process-driven design. Because of this, NGINX is often seen as the “faster” alternative to Apache, being able to handle a higher load of concurrent connections while using less resources. There are many comparisons out there between Apache and NGINX; we’ll leave the debate up to the community. But here are a few pointers that outline the key reasons to choose Apache versus NGINX. At the end of the day, the choice of the web server platform is entirely dependent on what you’re doing with the server.
NGINX vs. Apache
… then NGINX might be a good fit for you.
… then you probably want to stick with Apache.
Here’s a good rule of thumb: If you want to run ONE site at lightning speed on an advanced configuration, NGINX is probably the server for you. If you want to run MANY sites with easy configuration and flexibility, Apache is still your bread and butter.
At the end of the day, both are a good fit for most sites. Apache is included with all major Linux distributions and requires much less configuration. However, most benchmarks have clocked NGINX at serving websites faster. You can also see some configurations that run both — it’s all up to you as the admin.
Pre-flight check
Before we begin, let’s make sure we have everything we need.In order to perform this task, you’ll need an active Fedora server, as well as an SSH client such as PuTTY (for Windows) or Terminal (Mac). We recommend a GoDaddy VPS if you’re just getting started, or a full dedicated server if you’re ready to take total control.
A domain. We will, of course, need to tie a domain to your NGINX web server, so we’ll need a domain to use. All of our examples will use the domain nginxsite.com. When going through the article, replace any instance of nginxsite.com with the domain you want to use for your site.
Make sure you can connect to the server through SSH. You can find instructions here. If this is step is a challenge, then I’ll level with you — this article might not be for you.
A browser window open to your search engine of choice. Unlike Apache, NGINX has a lot of custom tinkering that you might need to do according to your needs as webmaster, and other variables that this article not account for. But this shouldn’t phase you — you’re a sysadmin, and search engines are your ally.
If all of these elements are in place, we’re ready for take-off. Let’s set up NGINX.
Installing and configuring NGINX on Fedora
Step 1: Turn Apache off
Every major Linux distribution comes packages with Apache by default; its literally integrated into the OS by now (similar to how Windows comes packaged with IIS natively). However, since we are setting up a dedicated space for NGINX, its possible that the existing Apache configuration can cause problems when NGINX is put in its place. What we are going to do is turn Apache off, then configure Apache so that it does not start upon server reboot.
Turning Apache off on a server with live sites will bring those sites down. Act accordingly.
Log into your server via SSH, then get to the root user by running:
Note: We will remain as the root user for the remainder of the guide.
Shut Apache Down. This will bring down any current websites that are hosted on the server.
Remove Apache from the boot cycle, so that it doesn’t try to start up during server boot.
Note: If you have buyer’s remorse later on about NGINX, and want Apache to start on boot again, you can easily correct this previous command by running:
Apache is now fully shut down, and won’t be starting up again until we say so.
Step 2: Install NGINX
Now that Apache is riding off into the sunset, we can start to install NGINX.
Use yum to install NGINX.
Start NGINX.
Tell the server to start NGINX upon reboot.
Easy! You should now be able to see an NGINX test page by going to http://1.2.3.4, using your IP address for your server.
Step 3: Configure NGINX to serve for your domain
Alrighty, we’ve switched from the Apache schooner to the NGINX steamboat. Now it’s time to get it working for your domain.
Create a new user for the webspace
Before doing anything, we need to create a UNIX user for your webspace.
Type the following command to create your user:
To demonstrate, I’ll add my user nginxsite:
Give this user a password with the following:
You will then be prompted to set the password for this user.
Your characters won’t register in the terminal when you type — it’s just Linux protecting you by not logging the password entry. Follow safe password practices.
Your user should now be properly set up.
Create a new directory for the site DocumentRoot
Next, we need to create the directory that will act as the DocumentRoot for this website. It is a good idea to follow a standard naming convention if you are hosting multiple websites.
We’ll follow the standard used by cPanel, and make our DocumentRoot based on the name public_html, like so:
Let’s create a test index.html in this directory so that we have something to look at when we test the configuration later:
Use the HTML below the fold for this test index file:
Success! Nginx is properly serving on this domain!
Now that our directory and test index is created, we must give ownership of that directory over to the user in question. So following our previous example:
Now set permissions for this folder so that it can be viewed by the outside world:
Our directory is now set up, and we have a test index.html file to use.
Configure NGINX to recognize new VirtualHosts (Server Blocks)
Now for the fun part. Configuring a VirtualHost for NGINX is very similar to Apache, though the layout of the configuration file is a bit different. Also, in NGINX, they are referred to as ‘server blocks,’ and not the Apache VirtualHost label. It is worth noting that when editing an Apache configuration file we are editing XML. With NGINX, we are actually editing the C code.
First, we need to set up our directories where the server blocks will live:
Note: In theory, instead of doing this by having a directory tree, you could simply edit the global configuration file. However, by setting up a directory tree (which is what Debian-based Linux distros, such as Ubuntu will do), it allows for an easier configuration down the line as more website are added.
Tell NGINX to use look at those directories for the server blocks. Open the global NGINX configuration file in the text editor of your choice; we will use vim:
Add these lines to the end of the http <> block, then save the file:
Great. Now NGINX can recognize the server block.
Configure the actual NGINX server blocks
Create a new file specifically for the server block for your site. The line below will do this and open it in vim:
Paste a new NGINX server block in here. It should look like this:
Example NGINX server block
Let’s break down a few important parts of this:
server_name: This is the domain you will be using for your site. Instead of localhost, we will use the public facing domain and www version of the domain you want to use, like so:
server_name nginxsite.com www.nginxsite.com;
root: This should be set to the directory where the files live. In our example this can be changed to /var/www/nginxsite.com/public_html
try_files: This is something we need to add in the location block. What we are doing here is telling the server to display a 404 error when a given file is not found. So you’ll place this right under the index definition, before the closing > bracket:
Create your server block using these parameters, then save and close the file.
Create a symbolic link between sites-available and sites-enabled:
Restart NGINX:
You’re done! Provided your DNS and/or hosts file is pointed for your domain, you should now be able to go to the domain in a web browser and see the test HTML page we created earlier.
In with the new
Out with the old, and in with the new. You have successfully disabled Apache on your system, and substituted it with the sleek and sexy NGINX web server. You’re now ready to start tinkering and deploying sites of all different kinds on top of the NGINX server. Common web stacks using NGINX include LEMP, Django/Bottle/Flask, Ruby/Rails/Passenger —whatever your heart desires! As always, there will likely be more advanced configuration you want to do with NGINX to optimize the web server for your site. We highly suggest reviewing the documentation with NGINX for any additional configuration you may want to do on the web server. Otherwise, happy developing!