LNMP

发布时间 2023-12-20 11:30:43作者: q_7

LNMP
含义:就是搭建一个博客系统

分别的含义

linux::一个操作系统

nginx:一个网站服务器

mysql:一个数据库服务

php:一个编程语言

 

大概的流程:

1:解压压缩包,安装4软件 nginx mariadb-server php php-mysql php-fpm

2:配置nginx

3:配置mariadb

4:nginx网页文件的移动

5:防火墙和selinux的权限

6:访问

 

1:解压压缩包,yum源,安装软件

[root@server ~]# unzip lnmp.zip 
[root@server ~]# unzip wordpress-4.7.3-zh_CN.zip 

#编写一个lnmp的yum源,就是里面有一些所需要的安装的软件
[lnmp]
name=lnmp
baseurl=file:///root/lnmp/lnmp
gpgcheck=0
enable=1

[root@server ~]# yum -y install mariadb-server nginx php php-mysql php-fpm

  

2:配置nginx的配置文件

[root@server ~]# systemctl start nginx
[root@server ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@server ~]# systemctl start mariadb
[root@server ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@server ~]# systemctl start php-fpm
[root@server ~]# systemctl enable php-fpm


#编写配置文件
#添加网站允许的网页文件的格式
location / {
  9         root   /usr/share/nginx/html;
 10         index index.php index.html index.htm;
 11     }

# 修改脚本路径
location ~ \.php$ {
 31         root           /usr/share/nginx/html;
 32         fastcgi_pass   127.0.0.1:9000;
 33         fastcgi_index  index.php;
 34         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 35         include        fastcgi_params;
 36     }

#重启nginx服务
[root@server ~]# systemctl restart nginx

 

3:配置mysql数据库

[root@server ~]# mysql_secure_installation 

Set root password? [Y/n]    是否设置root密码
Disallow root login remotely? [Y/n]  是否禁止root远程登录
Remove test database and access to it? [Y/n]  是否删除test数据库
Reload privilege tables now? [Y/n]  是否重新加载权限

MariaDB [(none)]> create  database wordpress;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| wordpress          |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> 

exit

 

4:nginx网页文件的移动

[root@server ~]# cp -ar wordpress/* /usr/share/nginx/html/
[root@server ~]# cd /usr/share/nginx/html/
[root@server html]# ls
50x.html    license.txt      wp-admin              wp-config-sample.php  wp-includes        wp-login.php     wp-signup.php
index.html  readme.html      wp-blog-header.php    wp-content            wp-links-opml.php  wp-mail.php      wp-trackback.php
index.php   wp-activate.php  wp-comments-post.php  wp-cron.php           wp-load.php        wp-settings.php  xmlrpc.php

#设置可执行的权限,网页文件
[root@server html]# chmod 777 -R ./

  

 

5:防火墙和selinux的权限的设置

#防火墙的放行
[root@server html]# firewall-cmd --permanent --add-service=http
success
[root@server html]# firewall-cmd --permanent --add-service=mysql
success
[root@server html]# firewall-cmd --reload 
success
[root@server html]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens32 ens33
  sources: 
  services: dhcpv6-client http mysql ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  sourceports: 
  icmp-blocks: 
  rich rules: 
	

#nginx网页文件selinux的上下文类型
[root@server html]# semanage fcontext -a -t 'httpd_sys_content_t' '/usr/share/nginx/html/(/.*)?'
[root@server html]# restorecon -RFv /usr/share/nginx/html/
[root@server html]# ll -Z
-rwxrwxrwx. root root system_u:object_r:httpd_sys_content_t:s0 50x.html
-rwxrwxrwx. root root system_u:object_r:httpd_sys_content_t:s0 index.html
-rwxrwxrwx. root root system_u:object_r:httpd_sys_content_t:s0 index.php
-rwxrwxrwx. root root system_u:object_r:httpd_sys_content_t:s0 license.txt
-rwxrwxrwx. root root system_u:object_r:httpd_sys_content_t:s0 readme.html

 

6:访问

就是会出现少了一个文件,所以创建那个文件,就可以

http://192.168.10.100  

 

总结:

当然也可以使用apache来搭建