Ubuntu 20.04 安装 Apache2 PHP7.4 MySQL 8.0

发布于 2020-07-30  685 次阅读


Ubuntu 20.04 安装 Apache2 PHP7.4 MySQL 8.0

1.安装php7.4

安装php7.4

sudo apt-get update
sudo apt install libapache2-mod-php7.4 libphp7.4-embed php7.4 php7.4-bcmath php7.4-bz2 php7.4-cgi php7.4-cli php7.4-common php7.4-curl php7.4-dba php7.4-dev php7.4-enchant php7.4-fpm php7.4-gd php7.4-gmp php7.4-imap php7.4-interbase php7.4-intl php7.4-json php7.4-ldap php7.4-mbstring php7.4-mysql php7.4-odbc php7.4-opcache php7.4-pgsql php7.4-phpdbg php7.4-pspell php7.4-readline php7.4-snmp php7.4-soap php7.4-sqlite3 php7.4-sybase php7.4-tidy php7.4-xml php7.4-xmlrpc php7.4-xsl php7.4-zip -y 

管理php

启动、关闭、重启、查看状态

systemctl restart php7.4-fpm #重启
systemctl start php7.4-fpm #启动
systemctl stop php7.4-fpm #关闭
systemctl status php7.4-fpm #检查状态

更新php

sudo apt-get update
sudo apt-get upgrade -y

2.安装Apache2

安装apache

sudo apt-get update
sudo apt-get install apache2

让apache能识别php文件

sudo apt-get install libapache2-mod-php7.4

启用mod_rewrite模块

sudo a2enmod rewrite
sudo service apache2 restart

修改配置,使Apache启用.htaccess

sudo vim /etc/apache2/apache2.conf
sudo service apache2 restart

找到

<Directory /var/www/>
    Options Indexes FollowSymLinks # 删掉Indexes防止索引
    AllowOverride None # None改为All启用.htaccess
    Require all granted
</Directory>

将这部分修改为

<Directory /var/www/>
    Options FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

3.安装MySQL

安装mysql-server

sudo apt-get install mysql-server

配置mysql

Ubuntu 20.04安装MySQL的时候,不会像18.04那样让我们输入root用户的密码,所以安装之后,需要用MySQL 安装文件附带的一个名为mysql_secure_installation的脚本设置密码。

设置root用户的默认密码

sudo mysql_secure_installation

你将会被要求配置VALIDATE PASSWORD PLUGIN,它被用来测试 MySQL 用户密码的强度,并且提高安全性:

Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT 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 component?
Press y|Y for Yes, any other key for No: y

有三个级别的密码验证策略,低级,中级,高级。如果你想设置验证密码插件,按y或者其他任何按键,移动到下一个步骤:

There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2

下一次被提示时,你将被要求为 MySQL root 用户设置一个密码:

Please set the password for root here.
New password:
Re-enter new password:

如果你设置了验证密码插件,这个脚本将会显示你的新密码强度。输入y确认密码:

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

下一步,你将被要求移除任何匿名用户,限制 root 用户访问本地机器,移除测试数据库并且重新加载权限表。你应该对所有的问题回答y。

登录mysql

sudo mysql

修改密码

修改密码策略

set global validate_password.policy=0;
set global validate_password.length=1;

修改密码

将下面代码中password换成你的密码,使用脚本里说的强密码(大于8位,且有字母、数字、和符号)

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

修改之后退出mysql

exit;

重新登录mysql

修改之后不能直接使用sudo mysql访问控制台,需要以密码访问

mysql -u root -p

Satxm,一个正在肝地球Online的人。