一、安装 PHP 7.4,配合 Apache

如果你正在使用 Apache 作为你的网络服务器,运行下面的命令来安装 PHP 和 Apache PHP 模块:

sudo apt update

sudo apt install php libapache2-mod-php

软件包安装好之后,重启 Apache,重新加载 PHP 模块。

sudo systemctl restart apache2

二。安装 PHP 扩展

PHP 扩展被编译成库文件,用来扩展 PHP 核心功能。扩展通常作为软件包,并且可以很容易地通过apt来进行安装:

sudo apt install php-[extname]

例如,想要安装 MySQL 和 GD 扩展,你需要运行下面的命令:

sudo apt install php-mysql php-gd

在安装一个新的 PHP 扩展之后,依赖于你的设置,不要忘记去重启 Apache 或者 PHP FPM 服务。

三安装mysql

安装

sudo apt-get install mysql-server mysql-client

常用命令:
mysql -u root -p 登陆mysql

mysql -V 查看版本:
sudo service mysql start 启动 
sudo service mysql status 启动状态 
sudo service mysql enable 开机自动启动
 sudo service mysql disable 禁止开机自动启动
 sudo service mysql stop 停止 
sudo service mysql restart 重启

配置mysql:

用这个命令进入mysql
sudo mysql
在sql命令行输入以下命令回车,你就可以把密码改成mynewpassword
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'mynewpassword';
exit回到终端命令行,输入:sudo mysql_secure_installation
然后接下来的操作步骤:
对于上述数据库初始化的操作步骤,在下面的输出信息旁边我做了简单注释。
root@ubuntu-virtual-machine:~# mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin? # 要安装验证密码插件吗?
Press y|Y for Yes, any other key for No: N # 这里我选择N
Please set the password for root here.
New password: # 输入要为root管理员设置的数据库密码
Re-enter new password: # 再次输入密码
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y # 删除匿名账户
Success.
Normally, root should only be allowed to connect from
‘localhost’. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N # 禁止root管理员从远程登录,这里我没有禁止
… skipping.
By default, MySQL comes with a database named ‘test’ that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y # 删除test数据库并取消对它的访问权限

Dropping test database…
Success.
Removing privileges on test database…
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y # 刷新授权表,让初始化后的设定立即生效
Success.
All done!
检查mysql服务状态:
systemctl status mysql

配置mysql允许远程访问

1首先编辑 /etc/mysql/mysql.conf.d/mysqld.cnf 配置文件:
vim /etc/mysql/mysql.conf.d/mysqld.cnf
注释掉bind-address = 127.0.0.1
2修改 mysql 数据库里面的 user 表里面user =‘root’ 的host为%
一、打开mysql控制台,输入:use mysql;
二、输入:show tables;
三、输入:select host from user;
四、update user set host ='%' where user ='root';
五、重新启动mysql服务,或者输入 flush privileges; 远程服务器就允许程序连接数据库了。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐