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

Complete construction of LNMP environment + WordPress deployment from scratch

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

0. Description

There will be a lot of content, but the following content is their own complete reproduction in the process of learning to build the LNMP environment, so it is of great reference value!

The following is an example of a CentOS 6.5 operating system installed in Minimal to demonstrate the complete construction process of the LNMP environment, and finally deploy a WordPress blog. The final results are as follows:

1. Description of the experimental environment

The host operating system used in the test environment of this experiment is Windows 7, and CentOS 6.5 is installed on the Vmware virtual machine, as shown below:

Host operating system Windows 7

Operating system CentOS 6.5 installed on the virtual machine

Virtual machine operating system Internet access NAT

When using NAT to surf the Internet, the network connection between the virtual machine and the host can be as follows:

On why the network topology is like this, here is no explanation, you can refer to another blog post by the blogger, "deeply understand the Internet mode NAT mode of the VMware virtual machine in practice". This article deeply analyzes the details of the network structure when the VMware virtual machine uses the NAT mode to surf the Internet. I believe that after reading this article, it will be easy to understand the experimental environment of Nginx here.

So first of all, we should first configure the network environment so that the host can communicate with our virtual machine. In fact, if you understand the principle of VMware virtual machine access to the Internet, and are also very familiar with the network configuration of CentOS, this step can be easily completed, and the process will not be given here. The IP address used here is the same as the figure above.

Finally, we visited the WordPress blog we built on the host computer, which is very good, so we can have a try!

Building 2.LNMP environment: Nginx installation, testing and domain name configuration

In fact, there is a very detailed description of "compiling and installing Nginx+ Experimental Environment on CentOS + testing" in another blog post, but all the steps are still given here for completeness, but the process will be much simpler.

(1) Nginx installation

1. Install Nginx dependent function libraries pcre, openssl-devel

[root@leaf] # yum install-y pcre pcre-devel openssl openssl-devel. [root@leaf ~] # rpm-Q pcre pcre-devel openssl openssl-develpcre-7.8-7.el6.x86_64pcre-devel-7.8-7.el6.x86_64openssl-1.0.1e-48.el6_8.4.x86_64openssl-devel-1.0.1e-48.el6_8.4.x86_64

two。 Download and install Nginx

Nginx1.6.3 is used here, as follows:

# download Nginx [root@leaf ~] # yum install-y wget [root@leaf ~] # mkdir tools [root@leaf ~] # cd tools/ [root@leaf tools] # wget http://nginx.org/download/nginx-1.6.3.tar.gz[root@leaf tools] # ll total usage 788Murray. 1 root root 805253 April 8 2015 nginx-1.6.3.tar.gz # decompress [root@leaf tools] # tar zxf nginx-1.6.3.tar.gz [root@leaf tools] # ll total amount 792drwxr-xr-x. 8 1001 1001 4096 April 7 2015 nginx-1.6.3-rw-r--r--. 1 root root 805253 April 8 2015 nginx-1.6.3.tar.gz# specified compilation parameters [root@leaf tools] # yum install-y gcc # need to install GCC [root @ leaf tools] # mkdir / application # as the Nginx installation directory [root@leaf tools] # useradd nginx- s / sbin/nologin-M [root@leaf tools] # tail-1 / etc/passwdnginx:x:500:500::/home/nginx:/sbin/nologin [root@leaf tools] # cd nginx-1.6.3 [root@leaf nginx-1.6.3] #. / configure-- user=nginx-- group=nginx-- prefix=/application/nginx-1.6.3/-- with-http_stub_status_module-- with-http_ssl_ module [root @ leaf nginx-1.6.3] # echo $? # the result output 0 indicates that the command was successfully executed and compiled [root@leaf nginx-1. 6.3] # make [root@leaf nginx-1.6.3] # echo $? "install [root@leaf nginx-1.6.3] # make install [root@leaf nginx-1.6.3] # echo $?" establish a soft link to the installation directory [root@leaf nginx-1.6.3] # ln-s / application/nginx-1.6.3/ / application/nginx [root@leaf nginx-1.6.3] # ls-l / application/ total usage 4lrwxrwxrwx. 1 root root 25 March 4 04:28 nginx- > / application/nginx-1.6.3/drwxr-xr-x. 6 root root 4096 March 4 04:27 nginx-1.6.3

(2) Nginx test

1. Start Nginx

[root@leaf] # / application/nginx/sbin/nginx-t # check the configuration file nginx: the configuration file / application/nginx-1.6.3//conf/nginx.conf syntax is oknginx: configuration file / application/nginx-1.6.3//conf/nginx.conf test is successful [root@leaf ~] # / application/nginx/sbin/nginx # start the Nginx service

Validate Nginx service on 2.CentOS

[root@leaf ~] # netstat-lntup | grep 80tcp 0 0 0.0 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. LISTEN 3929/nginx [root@leaf ~] # curl localhostWelcome to nginx! Body {width: 35eme; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif;} Welcome to nginx!

If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.

For online documentation and support please refer tonginx.org.Commercial support is available atnginx.com.

Thank you for using nginx.

3. Verify the Nginx service on the host machine

Enter the IP address of the CentOS host 10.0.0.101 on the host browser as follows:

(3) Domain name configuration

This part of the content in another blog post also has a very detailed introduction to "Nginx configuration of multiple domain name-based virtual hosts + experimental environment building + testing", you can refer to, so I will not give a very detailed description here.

To build a blog service, the domain name configured here is blog.xpleaf.org. The operation procedure is as follows:

1. Minimize Profil

[root@leaf ~] # cd / application/nginx/conf/ [root@leaf conf] # wc-l nginx.conf117 nginx.conf [root@leaf conf] # wc-l nginx.conf.default 117nginx.conf.default [root@leaf conf] # egrep-v "# | ^ $" nginx.conf.default > nginx.conf [root@leaf conf] # wc-l nginx.conf22 nginx.conf [root@leaf conf] # cat nginx.confworker_processes 1 events {worker_connections 1024;} http {include mime.types Default_type application/octet-stream; sendfile on; keepalive_timeout 65; server {listen 80; server_name localhost; location / {root html; index index.html index.htm;} error_page 500 502 503 504 / 50x.html; location = / 50x.html {root html }}}

two。 Modify the configuration file

Modify nginx.conf and add the configuration file extra/blog.conf, as follows:

[root@leaf conf] # cat nginx.confworker_processes 1: events {worker_connections 1024;} http {include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; include extra/blog.conf;} [root@leaf conf] # cat extra/blog.conf server {listen 80; server_name blog.xpleaf.org; location / {root html/blog Index index.html index.htm;}}

3. Create the site directory and files corresponding to the domain name

[root@leaf conf] # cd.. / html/ [root@leaf html] # mkdir blog [root@leaf html] # echo "This page is: blog.xpleaf.org" > blog/index.html [root@leaf html] # cat blog/index.html This page is: blog.xpleaf.org

4. Restart the Nginx service

[root@leaf html] # / application/nginx/sbin/nginx-tnginx: the configuration file / application/nginx-1.6.3//conf/nginx.conf syntax is ok [root@leaf html] # / application/nginx/sbin/nginx-s reload # smooth restart

Testing on 5.CentOS 6.5,

Modify the / etc/hosts file first:

[root@leaf html] # echo "127.0.0.1 blog.xpleaf.org" > > / etc/hosts [root@leaf html] # tail-1 / etc/hosts127.0.0.1 blog.xpleaf.org

Then use the command to test:

[root@leaf html] # curl blog.xpleaf.orgThis page is: blog.xpleaf.org [root@leaf html] # wget blog.xpleaf.org--2017-03-04 04Parse host blog.xpleaf.org... 127.0.0.1 blog.xpleaf.org is being connected | 127.0.0.1 |: 80. Connected. A HTTP request has been issued and is waiting for a response. 200 OK length: 30 [text/html] is being saved to: "index.html.1" 100% [= >] 30 -.-Kmax s in 0s 2017-03-04 04:58:42 (2.14 MB/s)-saved "index.html.1" [30 MB/s])

6. Testing on host Windows 7

Also modify the hosts file first. The hosts file of Windows 7 is located at C:\ Windows\ System32\ drivers\ etc, and the following line is also added:

10.0.0.101 blog.xpleaf.org

Use a browser to access blog.xpleaf.org, as follows:

So at this point, in the LNMP environment, the installation of Nginx has been completed, have you successfully installed it?

Building 3.LNMP Environment: MySQL installation and basic Security Optimization

Here is a binary installation to install MySQL, the installed version is: MySQL Server 5.5.54, which can be downloaded from https://dev.mysql.com/downloads/mysql/5.5.html#downloads.

Some basic security optimizations are made after the MySQL installation is complete.

(1) MySQL installation

1. Create an account for a MySQL user

[root@leaf] # groupadd mysql [root@leaf ~] # useradd-s / sbin/nologin-g mysql-M mysql [root@leaf ~] # tail-1 / etc/passwdmysql:x:501:501::/home/mysql:/sbin/nologin

two。 Download MySQL

You can use wget to install, download it to Windows 7, and then use SecureCRT to upload it to our CentOS using the rz command on CentOS (you need to install it using the yum install-y lrzsz command). In fact, either way, as long as there is a way to obtain the installation package, the following is how wget obtains the installation package:

[root@leaf tools] # wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.54-linux2.6-x86_64.tar.gz[root@leaf tools] # ls-l mysql-5.5.54-linux2.6-x86_64.tar.gz-rw-r--r--. 1 root root 185911232 March 3 13:34 mysql-5.5.54-linux2.6-x86_64.tar.gz

3. Extract and move to the specified directory

[root@leaf tools] # tar xf mysql-5.5.54-linux2.6-x86_64.tar.gz [root@leaf tools] # mv mysql-5.5.54-linux2.6-x86_64 / application/mysql-5.5.54 [root@leaf tools] # ln-s / application/mysql-5.5.54/ / application/mysql [root@leaf tools] # ls-l / application/ Total dosage 8lrwxrwxrwx. 1 root root 26 March 4 06:43 mysql- > / application/mysql-5.5.54/drwxr-xr-x. 13 root root 4096 March 4 06:42 mysql-5.5.54lrwxrwxrwx. 1 root root 25 March 4 04:28 nginx- > / application/nginx-1.6.3/drwxr-xr-x. 11 root root 4096 March 4 04:30 nginx-1.6.3

4. Initialize the MySQL configuration file

[root@leaf mysql] # cp support-files/my-small.cnf / etc/my.cnfcp: overwrite "/ etc/my.cnf"? Y

5. Initialize the MySQL database file

[root@leaf mysql] # mkdir-p / application/mysql/data/ [root@leaf mysql] # chown-R mysql.mysql / application/mysql [root@leaf mysql] # yum install-y libaio # install the MySQL dependency library, otherwise the following initialization will fail [root@leaf mysql] # / application/mysql/scripts/mysql_install_db-- basedir=/application/mysql-- datadir=/application/mysql/data-- user=mysql.# output shows two OK That is, the initialization is successful [root@leaf mysql] # echo $? # or through this command, the output is 0, that is, the command of the previous step was successfully executed. After the above, you can see the database files generated under the / application/mysql/data/ directory.

6. Configure and start the MySQL database

# (1) set the MySQL startup script [root@leaf mysql] # cp support-files/mysql.server / etc/init.d/mysqld [root@leaf mysql] # chmod + x / etc/init.d/mysqld [root@leaf mysql] # ls-l / etc/init.d/mysqld-rwxr-xr-x. 1 root root 10875 March 4 06:56 / etc/init.d/mysqld# (2) replace the default installation path of MySQL in the startup script / usr/local/mysql [root@leaf mysql] # sed-I's install the MySQL database [root@leaf mysql] # / etc/init.d/mysqld startStarting MySQL.Logging To'/ application/mysql/data/leaf.err'.... SUCCESS! # (4) check whether the MySQL database starts [root@leaf mysql] # netstat-lntup | grep mysqltcp 00 0.0.0.0root@leaf mysql 3306 0.0.0.0netstat * LISTEN 4400/mysqld # (5) View the log [root@leaf mysql] # tail-10 / application/mysql/data/leaf.err InnoDB: Creating foreign key constraint system tablesInnoDB: Foreign key constraint system tables Created170304 7:00:28 InnoDB: Waiting for the background threads to start170304 7:00:29 InnoDB: 5.5.54 started Log sequence number 0170304 7:00:29 [Note] Server hostname (bind-address): '0.0.0.09; port: 3306170304 7:00:29 [Note] -' 0.0.0.0' resolves to '0.0.0.0' 170304 7:00:29 [Note] Server socket created on IP: '0.0.0.0room.170304 7:00:29 [Note] Event Scheduler: Loaded 0 events170304 7:00:29 [Note] / application/mysql/bin/mysqld: ready for connections.Version:' 5.5.54' socket:'/ tmp/mysql.sock' port: 3306 MySQL Community Server (GPL) # (6) set MySQL boot [root@leaf mysql] # chkconfig-- add mysqld [root @ leaf mysql] # chkconfig mysqld on [root@leaf mysql] # chkconfig-- list mysqldmysqld 0: off 1: close 2: enable 3: enable 4: enable 5: enable 6: close # (7) configure the global usage path of the mysql command (note that the command is configured here The previous configuration is just the startup script) [root@leaf mysql] # echo 'export PATH=/application/mysql/bin:$PATH' > > / etc/profile [root@leaf mysql] # source / etc/profile [root@leaf mysql] # echo $PATH/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin# (8) Log in to MySQL to test [root@leaf mysql] # mysqlWelcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 1Server version: 5.5.54 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'\ c' to clear the current input statement.mysql > show databases;+-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | test | +-+ 4 rows in set (0.05 sec) mysql > select user () # View the currently logged-in users +-+ | user () | +-+ | root@localhost | +-+ 1 row in set (0.00 sec) mysql > select host, user from mysql.user +-+-+ | host | user | +-+-+ | 127.0.0.1 | root |:: 1 | root | | leaf | | leaf | root | | localhost | | localhost | root | +-+-+ 6 rows in set (0.00 sec) mysql > quitBye

(2) basic security optimization of MySQL

1. Set the password for the root user

[root@leaf mysql] # mysqladmin-u root password '123456'

two。 Clean up useless MySQL users and databases

[root@leaf mysql] # mysql-u root-pEnter password: Welcome to the MySQL monitor Commands end with; or\ g.Your MySQL connection id is 3Server version: 5.5.54 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.mysql > select user, host from mysql.user +-+-+ | user | host | +-+-+ | root | 127.0.0.1 | root |: 1 | | leaf | | root | leaf | | localhost | | root | localhost | +-+-+ 6 rows in set (0.00 sec) mysql > drop user "root" @ ":: 1" Query OK, 0 rows affected (0.00 sec) mysql > drop user "" @ "leaf"; Query OK, 0 rows affected (0.00 sec) mysql > drop user "root" @ "leaf"; Query OK, 0 rows affected (0.01 sec) mysql > drop user "@" localhost "; Query OK, 0 rows affected mysql > select user, host from mysql.user +-+-+ | user | host | +-+-+ | root | 127.0.0.1 | | root | localhost | +-+ 2 rows in set (0.00 sec) mysql > flush privileges;Query OK, 0 rows affected (0.00 sec) # Delete useless database mysql > show databases +-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | test | +-+ 4 rows in set (0.00 sec) mysql > drop database test;Query OK, 0 rows affected (0.01 sec) mysql > show databases +-+ | Database | +-+ | information_schema | | mysql | | performance_schema | +-+ 3 rows in set (0.00 sec)

At this point, the installation of MySQL is complete!

4.LNMP environment building: PHP (FastCGI mode) installation, configuration and startup

(1) install the PHP dependent function library

1. Install the lib library

The lib libraries you need to install are as follows:

Zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-develfreetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel

Except for the libiconv library, all of them can be installed through yum. The installation is as follows:

# use yum to install lib libraries other than libiconv-devel [root@leaf mysql] # yum install-y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel# compile and install libiconv-devel [root@leaf tools] # wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz[root@leaf tools] # tar zxf libiconv-1.14.tar. Gz [root@leaf tools] # cd libiconv-1.14 [root@leaf libiconv-1.14] #. / configure-- prefix=/usr/local/libiconv [root@leaf libiconv-1.14] # make [root@leaf libiconv-1.14] # make install

two。 Install the libmcrypt library

[root@leaf ~] # wget-O / etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo[root@leaf ~] # yum install-y libmcrypt-devel

3. Install the mhash encryption extension library

[root@leaf ~] # yum install-y mhash

4. Install the mcrypt encryption extension library

[root@leaf ~] # yum install-y mcrypt

(2) install PHP

The PHP version used is 5.3.27, as follows:

1. Download the PHP installation package

[root@leaf tools] # wget http://cn2.php.net/get/php-5.3.27.tar.gz/from/this/mirror[root@leaf tools] # mv mirror php-5.3.27.tar.gz [root@leaf tools] # ls-l php-5.3.27.tar.gz-rw-r--r--. 1 root root 15008639 January 21 2015 php-5.3.27.tar.gz

two。 Decompress

[root@leaf tools] # tar zxf php-5.3.27.tar.gz [root@leaf tools] # cd php-5.3.27 [root@leaf php-5.3.27] # pwd/root/tools/php-5.3.27

3. Configure installation parameters for PHP

There are many configuration items, as follows:

. / configure\-- prefix=/application/php5.3.27\-- with-mysql=/application/mysql\-- with-iconv-dir=/usr/local/libiconv\-- with-freetype-dir\-- with-jpeg-dir\-- with-png-dir\-- with-zlib\-- with-libxml-dir=/usr\-- enable-xml\-disable-rpath\-- enable-safe-mode\-- enable-bcmath\-- enable-shmop\-- enable-sysvsem\-- Enable-inline-optimization\-- with-curl\-- with-curlwrappers\-- enable-mbregex\-- enable-fpm\-- enable-mbstring\-- with-mcrypt\-- with-gd\-- enable-gd-native-ttf\-- with-openssl\-- with-mhash\-- enable-pcntl\-- enable-sockets\-with-xmlrpc\-enable-zip\-- enable-soap\-- enable-short-tags\-- enable-zend-multibyte\-- enable- Static\-with-xsl\-with-fpm-user=nginx\-with-fpm-group=nginx\-enable-ftp

You can copy it directly to the command line for configuration, which reduces the probability of errors:

[root@leaf php-5.3.27] # / configure\ >-- prefix=/application/php5.3.27\ >-- with-mysql=/application/mysql\ >-- with-iconv-dir=/usr/local/libiconv\ >-- with-freetype-dir\ >-- with-jpeg-dir\ >-- with-png-dir\ >-- with-zlib\ >-- with-libxml-dir=/usr\ >-- enable-xml\ >-- disable-rpath\ >-- enable -safe-mode\ >-- enable-bcmath\ >-- enable-shmop\ >-- enable-sysvsem\ >-- enable-inline-optimization\ >-- with-curl\ >-- with-curlwrappers\ >-- enable-mbregex\ >-- enable-fpm\ >-- enable-mbstring\ >-- with-mcrypt\ >-- with-gd\ >-- enable-gd-native-ttf\ >-- with-openssl\ >-- with-mhash\ >-- enable-pcntl\ >-- enable -sockets >-- with-xmlrpc\ >-- enable-zip\ >-- enable-soap\ >-- enable-short-tags\ >-- enable-zend-multibyte\ >-- enable-static\ >-- with-xsl\ >-- with-fpm-user=nginx\ >-- with-fpm-group=nginx\ >-- enable-ftp.+-- -- + | License: | | This software is subject to the PHP License Available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | | +-+ Thank you for using PHP.

4. Compile PHP

[root@leaf php-5.3.27] # ln-s / application/mysql/lib/libmysqlclient.so.18 / usr/lib64/ [root@leaf php-5.3.27] # touch ext/phar/phar.phar [root@leaf php-5.3.27] # make. [root@leaf php-5.3.27] # echo $? 0

5. Install PHP

[root@leaf php-5.3.27] # make install/root/tools/php-5.3.27/build/shtool install-c ext/phar/phar.phar / application/php5.3.27/binln-s-f / application/php5.3.27/bin/phar.phar / application/php5.3.27/bin/pharInstalling PDO headers: / application/php5.3.27/include/php/ext/pdo/. [root@leaf php-5.3.27] # echo $? 0

(3) configure and start PHP

1. Set the soft link to the PHP installation directory

[root@leaf php-5.3.27] # ln-s / application/php5.3.27/ / application/php [root@leaf php-5.3.27] # ls-l / application/phplrwxrwxrwx. 1 root root 23 March 4 08:59 / application/php-> / application/php5.3.27/

two。 Copy the PHP configuration file to the PHP default directory

[root@leaf php-5.3.27] # cp php.ini-production / application/php/lib/php.ini [root@leaf php-5.3.27] # ls-l / application/php/lib/php.ini-rw-r--r--. 1 root root 69627 March 4 09:00 / application/php/lib/php.ini

3. Configure the php-fpm.conf file

[root@leaf php-5.3.27] # cd / application/php/etc/ [root@leaf etc] # lspear.conf php-fpm.conf.default [root@leaf etc] # cp php-fpm.conf.default php-fpm.conf

4. Start the PHP service php-fpm

[root@leaf etc] # / application/php/sbin/php-fpm

5. Check the startup process and listening port number

[root@leaf etc] # ps-ef | grep php-fpmroot 129256 1 0 09:05? 00:00:00 php-fpm: master process (/ application/php5.3.27/etc/php-fpm.conf) nginx 129257 129256 0 09:05? 00:00:00 php-fpm: pool www nginx 129258 129256 0 09:05? 00:00:00 php-fpm: pool www root 129260 13743 0 09:06 pts/1 00:00:00 grep php-fpm [root@leaf etc] # netstat-lntup | grep 9000tcp 00 127.0.0.1 root@leaf etc 9000 0.0.0.0 * LISTEN 129256/php-fpm

At this point, the installation of PHP is complete! With all the components of LNMP installed, it's time to test the LNMP environment.

5.LNMP environment testing

(1) configure Nginx to support PHP program request access

1. View current Nginx configuration

[root@leaf etc] # cd / application/nginx/conf/ [root@leaf conf] # cat nginx.confworker_processes 1 root@leaf conf events {worker_connections 1024;} http {include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; include extra/blog.conf;} [root@leaf conf] # cat extra/blog.conf server {listen 80; server_name blog.xpleaf.org Location / {root html/blog; index index.html index.htm;}}

two。 Modify extra/blog.conf configuration file

[root@leaf conf] # cat extra/blog.conf server {listen 80; server_name blog.xpleaf.org; location / {root html/blog; index index.html index.htm;} location ~. *\. (php | php5)? ${root html/blog; fastcgi_pass 127.0.0.1 listen 9000 Fastcgi_index index.php; include fastcgi.conf;}}

3. Check and start Nginx

[root@leaf conf] # / application/nginx/sbin/nginx-tnginx: the configuration file / application/nginx-1.6.3//conf/nginx.conf syntax is oknginx: configuration file / application/nginx-1.6.3//conf/nginx.conf test is successful [root@leaf conf] # / application/nginx/sbin/nginx-s reload

(2) Test whether the LNMP environment is effective.

1. Configure domain name site directory

[root@leaf conf] # cd / application/nginx/html/blog/ [root@leaf blog] # echo "" > test_ info.php [root @ leaf blog] # cat test_info.php

two。 Enter the address http://blog.xpleaf.org/test_info.php in the browser on the host computer to access it

(3) Test whether the PHP connection MySQL is normal.

1. Edit text_mysql.php

[root@leaf blog] # cat test_mysql.php

two。 Enter the address http://blog.xpleaf.org/test_mysql.php in the browser on the host computer to access it

Now that the LNMP environment has been built and tested, you are ready to deploy WordPress!

6. Deploy WordPress

(1) MySQL database preparation

1. Log in to mysql

[root@leaf blog] # mysql-u root-pEnter password: Welcome to the MySQL monitor Commands end with; or\ g.Your MySQL connection id is 5Server version: 5.5.54 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.mysql >

two。 Create a database wordpress

Mysql > create database wordpress;Query OK, 1 row affected (0.32 sec) mysql > show databases;+-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | wordpress | +-+ 4 rows in set (0.00 sec)

3. Create a wordpress blog administrative user

Mysql > grant all on wordpress.* to wordpress@'localhost' identified by '123456 query OK, 0 rows affected (0.08 sec) mysql > show grants for wordpress@'localhost' +-+ | Grants for wordpress@ Localhost | + -- + | GRANT USAGE ON *. * TO 'wordpress'@'localhost' IDENTIFIED BY PASSWORD' * 6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' | GRANT ALL PRIVILEGES ON `wordpress`. * TO 'wordpress'@'localhost' | +- -+ 2 rows in set (0.00 sec)

4. Refresh MySQL user rights

Mysql > flush privileges;Query OK, 0 rows affected (0.31 sec)

5. Check MySQL login user

Mysql > select user,host from mysql.user;+-+-+ | user | host | +-+-+ | root | 127.0.0.1 | | root | localhost | | wordpress | localhost | +-+-+ 3 rows in set (0.00 sec)

(2) Nginx configuration preparation

1. Modify blog.conf configuration file

[root@leaf conf] # cat extra/blog.conf server {listen 80; server_name blog.xpleaf.org; location / {root html/blog; index index.php index.html index.htm;} location ~. *\. (php | php5)? ${root html/blog; fastcgi_pass 127.0.0.1 listen 9000 Fastcgi_index index.php; include fastcgi.conf;}} # compared to the previous configuration file, only index.php # has been added under /, but it is important to note that index.php must be placed after the index keyword, so that when you visit blog.xpleaf.org, our WordPress page will be opened

two。 Restart the Nginx service

[root@leaf conf] # / application/nginx/sbin/nginx-s reload

(3) configure WordPress

1. Get the WordPress installation package

[root@leaf tools] # wget https://cn.wordpress.org/wordpress-4.7.3-zh_CN.tar.gz [root@leaf tools] # ls-lh wordpress-4.7.2-zh_CN.tar.gz-rw-r--r--. 1 root root 8.1m January 28 08:53 wordpress-4.7.2-zh_CN.tar.gz

two。 Extract and configure the site directory

[root@leaf tools] # cp wordpress-4.7.2-zh_CN.tar.gz / application/nginx/html/blog/ [root@leaf tools] # cd / application/nginx/html/blog/ [root@leaf blog] # tar zxf wordpress-4.7.2-zh_CN.tar.gz [root@leaf blog] # lsindex.html test_mysql.php wordpress-4.7.2-zh_CN.tar.gztest_info.php wordpress [root@leaf blog] # rm-rf Test_* wordpress-4.7.2-zh_CN.tar.gz # Delete useless files [root@leaf blog] # lsindex.html wordpress [root@leaf blog] # mv wordpress/*. / # move the wordpress program to the current blog directory [root@leaf blog] # lsindex.html wp-admin wp-includes wp-signup.phpindex.php wp-blog-header.php wp-links- The total amount of opml.php wp-trackback.phplicense.txt wp-comments-post.php wp-load.php xmlrpc.phpreadme.html wp-config-sample.php wp-login.phpwordpress wp-content wp-mail.phpwp-activate.php wp-cron.php wp-settings.php [root@leaf blog] # ls-l is 196m / r / r / m / r / r 1 root root 30 March 4 04:54 index.html-rw-r--r--. 1 nobody 65534 418 September 25 2013 index.php-rw-r--r--. 1 nobody 65534 January 3 02:51 license.txt-rw-r--r--. 1 nobody 65534 6956 January 28 08:53 readme.htmldrwxr-xr-x. 2 nobody 65534 4096 March 409: 50 wordpress.

3. Grant permissions to nginx users and groups to all files under blog

[root@leaf blog] # chown-R nginx.nginx.. / blog/ [root@leaf blog] # ls-l total dosage 196m RW, R, etc. 1 nginx nginx 30 March 4 04:54 index.html-rw-r--r--. 1 nginx nginx 418 September 25 2013 index.php-rw-r--r--. 1 nginx nginx 19935 January 3 02:51 license.txt-rw-r--r--. 1 nginx nginx 6956 January 28 08:53 readme.htmldrwxr-xr-x. 2 nginx nginx 4096 March 409: 50 wordpress.

(4) install WordPress

Enter the address: http://blog.xpleaf.org on the host browser, as follows:

The next installation is very user-friendly. Click "start now" and the following page appears:

After filling in the information, click "submit", as follows:

Click "install", and then let us fill in some information, as follows:

Click "install WordPress" and the following page will be displayed:

Displaying the above page shows that our WordPress installation is successful! Then you can manage your own personal WordPress blog site!

7. What's the next step?

You can set up a LNMP environment on a CVM, such as Tencent Cloud or Aliyun, and then deploy a WordPress blog program. In order to achieve the effect of domain name access, you can purchase a domain name and then build your own DNS server. This will be a very good experience!

Next, you can consider optimizing LNMP.

8. references

"learn Linux Operation and maintenance from Old Boys: Web Cluster practice"

MySQL official site: https://www.mysql.com/downloads/

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

Database

Wechat

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

12
Report