LNMP environment configuration under openSUSE

Last Updated At: 2025-10-21 09:10:00

Overview

The LNMP environment represents the Nginx + MySQL + PHP web server architecture on a Linux system. This document provides instructions for setting up the LNMP environment on openSUSE 42.3.

This document includes software installation steps. Make sure you are familiar with the software installation methods. For more information, see Installing Software on openSUSE Using Zypper.

LNMP Components and Versions:

  • Linux: Operating system, using openSUSE 42.3 in this document.
  • Nginx: Web server program for parsing web programs, using Nginx 1.14.2.
  • MySQL: Database management system, using MySQL 5.6.43.
  • PHP: Program for generating web pages on the web server, using PHP 7.0.7.

Directions

Configure Image Sources

  1. Log in to the CVM.

  2. Execute the following commands to add mirror sources.

    zypper ar https://mirrors.convergecloud.com/opensuse/distribution/leap/42.3/repo/oss suseOss
    zypper ar https://mirrors.convergecloud.com/opensuse/distribution/leap/42.3/repo/non-oss suseNonOss
    
  3. Execute the following commands to update mirror sources.

    zypper ref
    

Install and configure Nginx

  1. Execute the following command to install Nginx.

    zypper install -y nginx
    
  2. Execute the following commands in sequence to start the Nginx service and set it to start automatically on boot.

    systemctl start nginx
    systemctl enable nginx
    
  3. Run the following command to modify the Nginx configuration file.

    vim /etc/nginx/nginx.conf
    
  4. Press "i ” to switch to edit mode.

  5. Locate the server{...} and replace it with the following content.

    server {
        listen       80;
        server_name  localhost;
    
        #access_log  /var/log/nginx/host.access.log  main;
        location / {
                root           /srv/www/htdocs/;
                index  index.php index.html index.htm;
        }
    
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                root           /srv/www/htdocs/;
        }
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
                root           /srv/www/htdocs/;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }
    }
    
  6. After inputting, press Esc, input ":wq" to save the file and return.

  7. Execute the following command to restart the Nginx service.

    systemctl restart nginx
    
  8. Execute the following command to create index.html Homepage.

    vi /srv/www/htdocs/index.html
    
  9. Press "i to switch to edit mode and enter the following content:

    <p> hello world!</p>
    
  10. After inputting, press Esc, input ":wq" to save the file and return.

  11. In the browser, access the public IP address of the openSUSE CVM instance to check whether the Nginx service is running normally.
    As shown in the figure below, it indicates that Nginx has been successfully installed and configured.

Install and configure MySQL

  1. Execute the following command to install MySQL.

    zypper install -y mysql-community-server mysql-community-server-tools
    
  2. Execute the following commands in sequence to start the MySQL service and set it to start automatically on boot.

    systemctl start mysql 
    systemctl enable mysql
    
  3. Execute the following command to log in to MySQL for the first time. > Note: When you log in to MySQL for the first time, the system will prompt you to enter a password. If you do not want to enter a password, you can directly press "Enter" to log in to MySQL.

    mysql -u root -p
    

    Successfully entering MySQL will a screen similar to the image below.


4. Execute the following command to change the root password.

update mysql.user set password = PASSWORD('Enter your new password here') where user='root';
  1. Execute the following command to apply the configuration.

    flush privileges;
    
  2. Execute the following command to exit MySQL.

    \q
    

Install and configure PHP

Execute the following command to install.

zypper install -y php7 php7-fpm php7-mysql

Integrate Nginx with PHP-FPM

  1. Execute the following commands in sequence to enter /etc/php7/fpm Directory, copy the file php-fpm.conf.default and rename it to php-fpm.conf.

    cd /etc/php7/fpm
    cp php-fpm.conf.default php-fpm.conf
    
  2. Execute the following commands in sequence to enter /etc/php7/fpm/php-fpm.d Directory, copy the file www.conf.default and rename it to www.conf.

    cd /etc/php7/fpm/php-fpm.d
    cp www.conf.default www.conf
    
  3. Execute the following commands in sequence to start the service and set it to start automatically on boot.

    systemctl start php-fpm
    systemctl enable php-fpm
    

Validate the Environment Configuration

  1. Execute the following command to create a test file "index.php".

    vim /srv/www/htdocs/index.php
    
  2. Press "i to switch to edit mode and input the following content:

    <?php
        echo "hello new world!";
    ?>
    
  3. Press "Esc", input ":wq" to save the file and return.

  4. Open a web browser and access the public IP of your openSUSE CVM.
    If you see a page similar to the one below, it indicates that the LNMP environment has been successfully set up.