ubuntu18.04+php7.0+mysql5.6+mosquitto安装部署

本文详细介绍了在Ubuntu环境下进行网络配置、安装PHP/Apache/Mysql、配置Apache服务、安装Mosquitto消息中间件的过程,并设置了各项服务的开机自启动。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


一、网络配置
1.修改配置文件(注意yaml文件里的格式)
sudo vim /etc/netplan/00-installer-config.yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
     dhcp4: no
     addresses: [10.10.3.55/24]
     gateway4: 10.10.3.254
     nameservers:
       addresses: [8.8.8.8,8.8.4.4]
       
2.启用
sudo netplan apply


二、安装php、Apache

1.安装php7.0低版本(ubuntu18.04默认安装的是php7.2)
sudo vim /etc/apt/sources.list
deb http://cn.archive.ubuntu.com/ubuntu xenial main
sudo apt-get update


2.安装apache\php\mysql
sudo apt-get install apache2
sudo apt-get install php7.0
sudo apt-get install mysql-server

3.安装php扩展

sudo add-apt-repository ppa:ondrej/php && sudo apt-get update


sudo apt-get install php7.0-zip && sudo apt-get install php7.0-curl && sudo apt-get install php7.0-mysql && sudo apt-get install libapache2-mod-php7.0

4.apache开启rewrite重写
sudo a2enmod rewrite

5.配置网站目录端口
sudo vim /etc/apache2/sites-available/000-default.conf
<VirtualHost *:8091>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/my
    Header set Access-Control-Allow-Origin *
    <Directory "/var/www/html/my">
        RewriteEngine on
        Options -Indexes 
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . index.php
        AllowOverride All
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

sudo vim /etc/apache2/ports.conf
Listen 8091

5.重启apache服务
sudo service apache2 restart

查看apache日志
tail -f /var/log/apache2/error.log

二、mysql数据库

1.登陆mysql

sudo mysql


2.新建用户
use mysql;
select host,user from user;
CREATE USER '用户名'@'localhost' IDENTIFIED BY '密码';
select host,user from user;

3.赋权限
GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO '用户名'@'localhost' IDENTIFIED BY '密码' WITH GRANT OPTION;
flush privileges;


4.修改配置文件.可远程访问
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
找到bind-address = 127.0.0.1 改为 bind-address = 0.0.0.0

sql_mode = "ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

max_allowed_packet  = 256M
max_connections = 2100
innodb_buffer_pool_size=4G
innodb_file_per_table=1
innodb_autoextend_increment=128
innodb_max_dirty_pages_pct=90
enforce-gtid-consistency=true

5.重启mysql
sudo service mysql restart

三、安装mosquitto

1.安装mosquitto,引入mosquitto仓库并更新
sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update
2. 执行以下命令安装mosquitto包
sudo apt-get install mosquitto
3. 安装mosquitto开发包
sudo apt-get install mosquitto-dev
4. 安装mosquitto客户端
sudo apt-get install mosquitto-clients
5.配置文件
sudo vim /etc/mosquitto/mosquitto.conf

port 1883
listener 1884
protocol websockets

6.创建用户名
mosquitto_passwd -c pwfile.example test
123456

7.测试
mosquitto_pub -h localhost -p 1883 -u test -P 123456 -t /nic/sync/res -m "666"
mosquitto_sub -h localhost -p 1883 -u test -P 123456  -t /#

五、设置开机自启
sudo update-rc.d apache2 defaults

sudo update-rc.d mysql defaults

sudo update-rc.d mosquitto defaults


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

somgl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值