tencent cloud

All product documents
Cloud Virtual Machine
Manual Setup of LNMP (openSUSE)
Last updated: 2024-01-06 17:43:10
Manual Setup of LNMP (openSUSE)
Last updated: 2024-01-06 17:43:10

Introduction

LNMP refers to a common web server architecture consisting of Nginx, MySQL or MariaDB, and PHP running on Linux. This article describes how to deploy LNMP on a Tencent Cloud Virtual Machine (CVM). You need to install several software packages on Linux. If you do not know how to perform software installation on Linux, refer to this article.

Software

This article uses the following software to build the LNMP environment:
OS: openSUSE 42.3
Web server: Nginx 1.14.2
Database: MySQL 5.6.43
Hypertext processor: PHP 7.0.7

Prerequisites

You have purchased a Linux CVM. If you have not yet, see Getting started with Linux CVMs.

Directions

Step 1: Logging in to a Linux instance

Log in to a Linux instance in standard login mode (recommended). You can also use other login methods as needed:

Step 2: Adding image source

1. Log in to your CVM.
2. Run the following commands to add image source:
zypper ar https://mirrors.cloud.tencent.com/opensuse/distribution/leap/42.3/repo/oss suseOss
zypper ar https://mirrors.cloud.tencent.com/opensuse/distribution/leap/42.3/repo/non-oss suseNonOss
3. Run the following command to update the source you just added.
zypper ref

Step 3: Installing and configuring Nginx

1. Run the following command to install Nginx.
zypper install -y nginx
2. Run the following command to start the Ngnix server and set it to auto start when the CVM starts up.
systemctl start nginx
systemctl enable nginx
3. Run the following to edit the Nginx configuration file.
Vi /etc/nginx/nginx.conf
4. Press i to toggle edit mode.
5. Find server{...} and replace it with the following content:
server {
listen 80;
server_name localhost;
#access_log /var/log/nginx/log/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. When you finish, press Esc to exit edit mode. Then enter :wq to save the file and exit Vi.
7. Run the following command to restart the Nginx service.
systemctl restart nginx
8. Run the following command to create an index page called index.html.
vi /srv/www/htdocs/index.html
9. Press i to switch to edit mode and Enter the following.
<p> hello world!</p>
10. After you finish, press Esc to exit edit mode. Then enter :wq to save the file and exit Vi.
11. Access the public IP of your CVM on the browser to check if your Nginx is running properly. If the following appears, Nginx has been successfully installed and configured.



Step 4: Installing and configuring MySQL

1. Run the following command to install MySQL.
zypper install -y mysql-community-server mysql-community-server-tools
2. Run the following command to start the MySQL service and set it to auto start when your CVM starts up.
systemctl start mysql
systemctl enable mysql
3. Run the following command to log in to MySQL.
Note:
When you login for the first time, MySQL will ask you to setup a password. If you do not wish to do so, press Enter to skip the step.
mysql -u root -p
If the following appears, you have successfully logged in.


4. Run the following command to change the root password.
update mysql.user set password = PASSWORD('NEW_PASSWORD') where user='root';
5. Run the following command to apply the configuration:
flush privileges;
6. Run the following command to exit MySQL.
\\q

Step 5: Installing PHP

Run the following command to install PHP:
zypper install -y php7 php7-fpm php7-mysql

Step 6: Configuring Nginx with PHP-FPM

1. Run the following commands to navigate to /etc/php7/fpm and rename php-fpm.conf.default to php-fpm.conf.
cd /etc/php7/fpm
cp php-fpm.conf.default php-fpm.conf
2. Run the following commands to navigate to /etc/php7/fpm/php-fpm.d and rename www.conf.default to www.conf.
cd /etc/php7/fpm/php-fpm.d
cp www.conf.default www.conf
3. Run the following commands to start PHP-FPM and set it to auto start when your CVM starts up.
systemctl start php-fpm
systemctl enable php-fpm

Verifying Your Setup

1. Run the following command to create a file named index.php.
Vi /srv/www/htdocs/index.php
2. Press i to switch to edit mode and enter the following:
<?php
echo "hello new world!";
?>
3. Press Esc to exit edit mode. Then enter :wq to save the file and exit.
4. Access the public IP of your CVM on the browser. If the following appears, then your LNMP setup has been installed and configured successfully.



See Also

After the LNMP environment is built, you can use it to set up a WordPress website to familiarize yourself with your CVM and what it can do.

FAQ

If you encounter issues when using CVM, refer to the following documents for troubleshooting: For issues regarding CVM login, see Password Login and SSH Key Login and Login and Remote Access. For issues regarding the CVM’s network, see IP Addresses and Ports and Security Groups. For issues regarding CVM disks, see System and Data Disks.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
中国香港
+852 800 906 020 (免费)
美国
+1 844 606 0804 (免费)
英国
+44 808 196 4551 (免费)
加拿大
+1 888 605 7930 (免费)
澳大利亚
+61 1300 986 386 (免费)
EdgeOne 热线
+852 300 80699
更多本地服务热线陆续新增中