How to Install Nginx With PHP-FPM And MySQL On openSUSE 12.1

Nginx is a free, open-source, high-performance HTTP server. Nginx is known for its stability, rich feature set, simple configuration, and low resource consumption. This tutorial shows how to install Nginx on an openSUSE 12.1 with PHP5 support (through PHP-FPM) and MySQL support. PHP-FPM  is an alternative PHP FastCGI implementation, it has some additional features useful for sites of any size, especially busier sites).
The first thing you need to do is to login as root. You can login as root in openSUSE by typing in the terminal:

[email protected]:~ $ su

Installing MySQL 5:

First we will install the MySQL by issuing the following command.

[email protected]:~# zypper in mysql-community-server mysql-community-server-client php5-mysql

Start MySQL server.

[email protected]:~ # systemctl start mysql.service

Step 3: To make the MySQL to start during the every boot, Type the following on terminal and hit Enter.

[email protected]:~ # systemctl enable mysql.service

Next is to make the MySQL secure by using the mysql_secure_installation command.

This program enables you to improve the security of your MySQL installation in the following ways:

  • You can set a password for root accounts.
  • You can remove root accounts that are accessible from outside the local host.
  • You can remove anonymous-user accounts.
  • You can remove the test database (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with test_.

[email protected]:~ # mysql_secure_installation


In order to log into MySQL to secure it, we’ll need the current
password for the root user.  If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): <– ENTER
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] <– ENTER
New password: <– yourrootsqlpassword
Re-enter new password: <– yourrootsqlpassword
Password updated successfully!
Reloading privilege tables..
 … Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] <– ENTER
 … Success!

Normally, root should only be allowed to connect from ‘localhost’.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] <– ENTER
 … Success!

By default, MySQL comes with a database named ‘test’ that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] <– ENTER
 – Dropping test database…
 … Success!
 – Removing privileges on test database…
 … Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] <– ENTER
 … Success!

Cleaning up…

All done!  If you’ve completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Installing Nginx:

Nginx is already available in the openSUSE Package, so issue the following command to install Nginx.

[email protected]:~ # zypper in nginx-1.0

Start the Nginx after the installation.

[email protected]:~ # systemctl start nginx.service

Test your Nginx installation by opening your web browser and Navigate to You will get the following web page saying 403 Forbidden, this is due to no index.html file in /srv/www/htdocs directory.

The default nginx document root on openSUSE 12.1 is /srv/www/htdocs. The configuration files are under /etc/nginx directory.

Auto-Start the Nginx.

[email protected]:~ # systemctl enable nginx.service

Installing PHP5-FPM:

Next is to install PHP5  through PHP-FPM (PHP-FPM (FastCGI Process Manager),  it  is an alternative PHP FastCGI implementation. it  has some additional features useful for sites of any size, especially busier sites). Install it by issuing the following command.

[email protected]:~ # yum install php5-fpm 

Before starting PHP-FPM; we need to have the configuration file, copy the sample configuration file to /etc/php5/fp/php-fpn.conf.

[email protected]:~ # cp /etc/php5/fpm/php-fpm.conf.default /etc/php5/fpm/php-fpm.conf

Edit the /etc/php5/fpm/php-fpm.conf file, change the error_log to /var/log/php-fpm.log and uncomment pm.min_spare_servers  and pm.max_spare_servers.

error_log = /var/log/php-fpm.log
pm.min_spare_servers = 5
pm.max_spare_servers = 35

Start or restart the PHP-FPM service.

[email protected]:~ # systemctl restart php-fpm.service

Rrestart the Nginx server.

[email protected]:~ # systemctl restart nginx.service

Enabling and Testing PHP-FPM Support on Virtual Host:

Lets create name based virtual host on Nginx server for the following details.

Server Name       :    geeksite.local

Document Root :   /srv/www/htdocs/geeksite.local

We can place the configuration file under the /etc/nginx/vhosts.d directory which doesn’t exists, so create the directory.

[email protected]:~ # mkdir /etc/nginx/vhosts.d

Create the configuration file called virtual.conf and Edit /etc/nginx/conf.d/virtual.conf.

[email protected]:~ # vi /etc/nginx/vhosts.d/virtual.conf

Add the following content.

server {
server_name geeksite.local;
root /srv/www/htdocs/geeksite.local;

location / {
index index.html index.htm index.php;

location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/htdocs/geeksite.local$fastcgi_script_name;

Create host entry for geeksite.local domain in /etc/hosts file.

[email protected]:~ # vi /etc/hosts

add the entry for geeksite.local, the line should look like below.               localhost.localdomain localhost geeeksite.local

Create the document root directory

[email protected]:~ # mkdir /srv/www/htdocs/geeksite.local

For testing the PHP, Place one PHP file on to the document root of the created virtual host.

Restart Nginx and PHP-FPM services.

[email protected]:~ # systemctl restart nginx.service
[email protected]:~ # systemctl restart php-fpm.service

In the terminal copy/paste the following line:

[email protected]:~ # vi /srv/www/htdocs/geeksite.local/index.php

This will open up a file called index.php.

Copy/Paste this line into the index.php file:

<?php phpinfo(); ?>

Save and close the file. use Esc + ;wq for saving the file.

Now open you’re web browser and type the following into the web address:


The page look like below:

From the above screen shot , PHP5 is working, and it’s working through FPM/FastCGI, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5.

Scroll down the browser and look for the MySQL support information.

That’s all!


Share This Post