Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Quickly establish LNMP (CentOS8+Nginx+MariaDB+PHP+WordPress) blog environment

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

I. Environmental configuration

Install and configure a clean CentOS7 or CentOS8 operating system, preferably CentOS8. If you install it yourself, use a minimized installation. If you use a CVM, check its configuration.

2. Configure CentOS system, including network, hostname, selinux, etc.

1. Configure the network: install NetworkManager, use nmtui for network configuration (NetworkManager needs to be installed on the CVM), first configure the yum source, and then run the following command to install

Yum install NetworkManager-y

After installation, run the "nmtui" command for network configuration or check network configuration.

If you minimize the installation of your own server, you do not need to install NetworkManager manually. You can run "nmtui" directly

2. Configure hostname

Hostnamectl set-hostname hostname

3. Close selinux

Vi / etc/selinux/config, changed to disabled.

Then restart the server.

Third, install Nginx

Nginx is a high-performance network server that can also be used as a reverse proxy and caching server, enter the following command to install the Nginx Web server:

Yum install nginx-y

After the installation is complete, you can start Nginx using the following command:

Systemctl start nginx

Make Nginx start automatically when the system boots by running the following command:

Systemctl enable nginx

Now check its status:

Systemctl status nginx

Open the firewall port

Open port 80 and run the following command to open port 80:

Firewall-cmd-permanent-zone=public-add-service=http

If you want to enable HTTPS on Nginx later, you also need to open port 443:

Firewall-cmd-permanent-zone=public-add-service=https

Visit this URL from the browsers of other computers: http:// server IP. If you see the following page, nginx is installed successfully.

Configuration file for nginx: / etc/nginx/nginx.conf, etc.

The default root directory of the nginx website: / usr/share/nginx/html

There is no need to manually modify any configuration files.

Change the owner of the site root:

Chown nginx:nginx / usr/share/nginx/html-R

Fourth, install the mysql database

Yum install mariadb-server mariadb- y

When the installation is complete, start it:

Systemctl start mariadb

Enable automatic startup when the system boots:

Systemctl enable mariadb

To check the status, run the following command:

Systemctl status mariadb

After you see that MariaDB is running, you need to run the security script:

Mysql_secure_installation

When it asks for a MariaDB root password, press enter because the root password has not been set, and then enter y to set the root password for the MariaDB server:

After setting the root password, press Y 4 times in a row to complete the installation of mariadb.

Run the following command:

Mysql-u root-p

Enter the root password to log in to MariaDB shell

Enter exit to exit.

The database files for mariadb are located in the following directory:

Find /-name mysql

/ usr/share/selinux/targeted/default/active/modules/100/mysql

/ usr/share/bash-completion/completions/mysql

/ usr/bin/mysql

/ usr/lib64/mysql

/ usr/lib64/perl5/vendor_perl/DBD/mysql

/ usr/lib64/perl5/vendor_perl/auto/DBD/mysql

/ var/lib/mysql

/ var/lib/mysql/mysql

/ var/lib/selinux/targeted/active/modules/100/mysql

The data files are placed in the / var/lib/mysql directory

5. Install php

Install PHP and related modules using the following command:

Yum install php php-mysqlnd php-fpm php-opcache php-gd php-xml php-mbstring php-json-y

Php-json must be installed, or there will be an error in installing wordpress below.

Centos8 yum installs the php7.2 version, and can also support the wordpress5.3 version.

Note: if you need to install the latest version of php7.3, do not run the above command, refer to the article at this address to install and configure php7.3: https://ywnz.com/linuxjc/4109.html

After the installation is complete, we need to start it:

Systemctl start php-fpm

Enable automatic startup when the system boots:

Systemctl enable php-fpm

Check status:

Systemctl status php-fpm

After running normally, edit the PHP-FPM configuration file:

Vi / etc/php-fpm.d/www.conf

By default, PHP-FPM runs as the apache user, and since we are using the Nginx Web server, we need to change it to find the following two lines:

User = apache

Group = apache

Change them to:

User = nginx

Group = nginx

In this file, you can find the following lines:

Listen = / run/php-fpm/www.sock

This indicates that PHP-FPM is listening for Unix sockets instead of TCP/IP sockets, save and close the file, and reload PHP-FPM for the changes to take effect:

Systemctl reload php-fpm

By default, php is already supported without any configuration nginx.

Test php by creating a php file with the following contents in the home directory of nginx's website

Cd / usr/share/nginx/html

Echo "" > > info.php

Type the http:// server IP/info.php in the browser address bar to test the php. If the php version information appears, the installation is successful.

6. Install and configure wordpress

First delete all the files in the root directory of the nginx website

Cd / usr/share/nginx/html

Rm-fr *

Then download the latest Chinese version of wordpress5.3. The following is the direct download address:

Https://cn.wordpress.org/latest-zh_CN.tar.gz

It is best to use Xunlei download, do not directly open this link or the official page of wordpress, it will prompt too many requests to open.

After downloading, transfer it to the server's / usr/share/nginx/html directory

Cd / usr/share/nginx/html

Decompress

Tar-zxvf latest-zh_CN.tar.gz

Get a wordpress directory

Move the file to the root of the site

Cd / usr/share/nginx/html

Mv-r. / wordpress/*. /

Delete the wordpress directory and installation files

Rmdir wordpress

Rm-f latest-zh_CN.tar.gz

So the contents of the html directory are as follows

Modify the permissions of the uploads directory, otherwise the website cannot upload files

Cd cd / usr/share/nginx/html/wp-content

Chown nginx:nginx uploads-R

Chmod 755-R uploads

Establish wordpress database

Mysql-uroot-p

Enter root password to log in to mysql database

Enter the following command in mariadb shell to create the wordpress database:

Mariadb [none] > create database wordpress

Exit

Quit

Finally, enter the http:// server ip in the browser, and if nothing happens, you can see the wordpress installation wizard and follow the wizard.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report