lnlidawei

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

web:  lamp  -  ubuntu2310 

 

 

 

 

一、基础说明

 


  1、lamp说明:   L = linux,    A = apache2,    M = mariadb(mysql),   P = php

 

 

 

 

二、安装包安装

 


  1、安装命令: [wit@ubuntu:null]$ sudo apt install mariadb-server apache2 php php-fpm php-mysqlnd

 

 

 


三、apache2 配置:

 


  1、查看状态: [wit@ubuntu:null]$ sudo systemctl status apache2.service

 

 

  2、开启服务: [wit@ubuntu:null]$ sudo systemctl start apache2.service

 


  3、 【apache2.service】 开机自启动设置: [wit@ubuntu:null]$ sudo systemctl enable apache2.service

 

 

 

 

四、mariadb 配置:

 


  1、查看状态: [wit@ubuntu:null]$ sudo systemctl status mariadb.service

 

 

  2、开启服务: [wit@ubuntu:null]$ sudo systemctl start mariadb.service

 

 

  3、 【mariadb.service】 开机自启动设置: [wit@ubuntu:null]$ sudo systemctl enable mariadb.service

 

 

  4、登录mariadb: [wit@ubuntu:null]$ sudo mysql -uroot -p

 

 

  5、创建账户: MariaDB [(none)]> create user 'YOUR_NAME'@'%' identified by 'YOUR_PASSWD';

 

 

  6、账户授权: MariaDB [(none)]> grant all privileges on *.* to 'YOUR_NAME'@'%';

 

 

  7、mariadb配置(重启服务修改配置生效: sudo systemctl restart mariadb.service ):  


    7.1 文件位置: /etc/mysql/mariadb.conf.d/50-server.cnf (bind-address = 127.0.0.1 => bind-address = 0.0.0.0)

    7.2、修改内容: 50-server.cnf 25~30行: “bind-address = 127.0.0.1” 改为 “bind-address = 0.0.0.0”

    7.4、重启服务,更改配置生效: [wit@ubuntu:null]$ sudo systemctl restart mariadb.service

    7.3、实际操作:

  1 [wit@ubuntu:mariadb.conf.d]$ pwd
  2 /etc/mysql/mariadb.conf.d
  3 [wit@ubuntu:mariadb.conf.d]$ 
  4 [wit@ubuntu:mariadb.conf.d]$ ls
  5 50-client.cnf         50-mysqld_safe.cnf  60-galera.cnf       provider_lz4.cnf   provider_lzo.cnf
  6 50-mysql-clients.cnf  50-server.cnf       provider_bzip2.cnf  provider_lzma.cnf  provider_snappy.cnf
  7 [wit@ubuntu:mariadb.conf.d]$ 
  8 [wit@ubuntu:mariadb.conf.d]$ sodu vim  50-server.cnf 
  9 50-server.cnf  25~30行:  “bind-address  = 127.0.0.1”  改为  “bind-address = 0.0.0.0 10 [wit@ubuntu:mariadb.conf.d]$ cat  50-server.cnf 
 11 #
 12 # These groups are read by MariaDB server.
 13 # Use it for options that only the server (but not clients) should see
 14 
 15 # this is read by the standalone daemon and embedded servers
 16 [server]
 17 
 18 # this is only for the mysqld standalone daemon
 19 [mysqld]
 20 
 21 #
 22 # * Basic Settings
 23 #
 24 
 25 #user                    = mysql
 26 pid-file                = /run/mysqld/mysqld.pid
 27 basedir                 = /usr
 28 #datadir                 = /var/lib/mysql
 29 #tmpdir                  = /tmp
 30 
 31 # Broken reverse DNS slows down connections considerably and name resolve is
 32 # safe to skip if there are no "host by domain name" access grants
 33 #skip-name-resolve
 34 
 35 # Instead of skip-networking the default is now to listen only on
 36 # localhost which is more compatible and is not less secure.
 37 
 38 #bind-address            = 127.0.0.1
 39 bind-address            = 0.0.0.0
 40 
 41 
 42 
 43 
 44 #
 45 # * Fine Tuning
 46 #
 47 
 48 #key_buffer_size        = 128M
 49 #max_allowed_packet     = 1G
 50 #thread_stack           = 192K
 51 #thread_cache_size      = 8
 52 # This replaces the startup script and checks MyISAM tables if needed
 53 # the first time they are touched
 54 #myisam_recover_options = BACKUP
 55 #max_connections        = 100
 56 #table_cache            = 64
 57 
 58 #
 59 # * Logging and Replication
 60 #
 61 
 62 # Note: The configured log file or its directory need to be created
 63 # and be writable by the mysql user, e.g.:
 64 # $ sudo mkdir -m 2750 /var/log/mysql
 65 # $ sudo chown mysql /var/log/mysql
 66 
 67 # Both location gets rotated by the cronjob.
 68 # Be aware that this log type is a performance killer.
 69 # Recommend only changing this at runtime for short testing periods if needed!
 70 #general_log_file       = /var/log/mysql/mysql.log
 71 #general_log            = 1
 72 
 73 # When running under systemd, error logging goes via stdout/stderr to journald
 74 # and when running legacy init error logging goes to syslog due to
 75 # /etc/mysql/conf.d/mariadb.conf.d/50-mysqld_safe.cnf
 76 # Enable this if you want to have error logging into a separate file
 77 #log_error = /var/log/mysql/error.log
 78 # Enable the slow query log to see queries with especially long duration
 79 #log_slow_query_file    = /var/log/mysql/mariadb-slow.log
 80 #log_slow_query_time    = 10
 81 #log_slow_verbosity     = query_plan,explain
 82 #log-queries-not-using-indexes
 83 #log_slow_min_examined_row_limit = 1000
 84 
 85 # The following can be used as easy to replay backup logs or for replication.
 86 # note: if you are setting up a replication slave, see README.Debian about
 87 #       other settings you may need to change.
 88 #server-id              = 1
 89 #log_bin                = /var/log/mysql/mysql-bin.log
 90 expire_logs_days        = 10
 91 #max_binlog_size        = 100M
 92 
 93 #
 94 # * SSL/TLS
 95 #
 96 
 97 # For documentation, please read
 98 # https://mariadb.com/kb/en/securing-connections-for-client-and-server/
 99 #ssl-ca = /etc/mysql/cacert.pem
100 #ssl-cert = /etc/mysql/server-cert.pem
101 #ssl-key = /etc/mysql/server-key.pem
102 #require-secure-transport = on
103 
104 #
105 # * Character sets
106 #
107 
108 # MySQL/MariaDB default is Latin1, but in Debian we rather default to the full
109 # utf8 4-byte character set. See also client.cnf
110 character-set-server  = utf8mb4
111 collation-server      = utf8mb4_general_ci
112 
113 #
114 # * InnoDB
115 #
116 
117 # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
118 # Read the manual for more InnoDB related options. There are many!
119 # Most important is to give InnoDB 80 % of the system RAM for buffer use:
120 # https://mariadb.com/kb/en/innodb-system-variables/#innodb_buffer_pool_size
121 #innodb_buffer_pool_size = 8G
122 
123 # this is only for embedded server
124 [embedded]
125 
126 # This group is only read by MariaDB servers, not by MySQL.
127 # If you use the same .cnf file for MySQL and MariaDB,
128 # you can put MariaDB-only options here
129 [mariadb]
130 
131 # This group is only read by MariaDB-10.11 servers.
132 # If you use the same .cnf file for MariaDB of different versions,
133 # use this group for options that older servers don't understand
134 [mariadb-10.11]
135 [wit@ubuntu:mariadb.conf.d]$ 
136 [wit@ubuntu:mariadb.conf.d]$

 

 

 


五、php-fpm 配置(此处有问题):

 


  1、说明: 在软件环境(ubuntu2310 + php8.2)中, 命令 【sudo systemctl status php-fpm.service】 提示找不到“php-fpm.service”。


  2、重启操作系统以后,进行查看的结果如下:

 1 [wit@ubuntu:null]$ php -v
 2 PHP 8.2.10-2ubuntu1 (cli) (built: Sep 5 2023 14:37:47) (NTS)
 3 Copyright (c) The PHP Group
 4 Zend Engine v4.2.10, Copyright (c) Zend Technologies
 5 with Zend OPcache v8.2.10-2ubuntu1, Copyright (c), by Zend Technologies
 6 [wit@ubuntu:null]$
 7 [wit@ubuntu:null]$ ps -ef | grep php-fpm
 8 root 957 1 0 00:21 ? 00:00:00 php-fpm: master process (/etc/php/8.2/fpm/php-fpm.conf)
 9 www-data 1055 957 0 00:21 ? 00:00:00 php-fpm: pool www
10 www-data 1056 957 0 00:21 ? 00:00:00 php-fpm: pool www
11 wit 2077 1839 0 00:37 pts/0 00:00:00 grep --color=auto php-fpm
12 [wit@ubuntu:null]$

 

 

 

 

六、selinux 配置:

 


  1、selinux 配置位置: ubuntu23.10.01 没有 【selinux】 机制。

 

 

 

 

七、firewalld 配置(ubuntu2310 默认没有安装firewalld):

 


  1、 【firewalld】 安装: [wit@ubuntu:null]$ sudo apt install firewalld

 

 

  2、 【firewalld】 开启服务: [wit@ubuntu:null]$ sudo systemctl start firewalld.service

 


  3、 【firewalld】 开机自启动设置: [wit@ubuntu:null]$ sudo systemctl enable firewalld.service

 


  4、查看firewall默认的【 zone 】: public

1 [wit@ubuntu:null]$ sudo firewall-cmd --get-default-zone
2 public

 

 

  5、apache2 开放端口【80/433】: [wit@ubuntu:null]$ sudo firewall-cmd --add-port=80/tcp --permanent

 

 

  6、mariadb 开放端口【3306】: [wit@ubuntu:null]$ sudo firewall-cmd --add-port=3306/tcp --permanent


  7、重启服务,更改配置生效: [wit@ubuntu:null]$ sudo firewall-cmd --reload

 

 

  8、查看已经开放的端口: [wit@ubuntu:null]$ sudo firewall-cmd --list-ports

1 [wit@ubuntu:null]$ sudo firewall-cmd --list-ports
2 80/tcp 3306/tcp
3 [wit@ubuntu:null]$

 

 

 

 

八、参考资料

 


  1、部署LAMP环境(Ubuntu) https://help.aliyun.com/zh/ecs/use-cases/build-a-lamp-stack-on-ubuntu-instances?spm=a2c4g.11186623.0.i2

 

 

posted on 2023-11-29 01:08  lnlidawei  阅读(10)  评论(0编辑  收藏  举报