吴先森
为退烧而生
吴先森的笔记
Ubuntu通过apt-get安装LNMP环境
Ubuntu通过apt-get安装LNMP环境

因为CentOS的gcc版本太低,升级新版本的gcc太麻烦,懒得升级了,所以直接换了Ubuntu。以前都用LNMP一键安装脚本,这次,打算练练手,就打算用apt-get手动安装(不要问我为什么不编译安装,因为太慢了..上一次编译了一天)

1.安装MySQL

直接运行以下命令即可安装

 apt-get install mysql-server 

输入以下命令配置

 mysql_secure_installation 

我的设置我贴出来,如下

#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (我的选项)

#2
Please set the password for root here...
New password: (输入密码)
Re-enter new password: (重复输入)

#3
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...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项)

#4
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) : Y (我的选项)

#5
By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项)

#6
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 (我的选项)

2.安装Nginx

输入以下命令安装最新版的Nginx

  sudo apt-get install nginx 

3.安装php和php常用扩展

输入以下命令安装php7.3

 sudo apt-get install php7.3-fpm php7.3-cli php7.3-cgi php7.3-mysql 

4.修改配置文件

 sudo nano /etc/nginx/sites-enabled/default 

取消注释掉以下部分,注意:不要同时取消注释两个fastcgi_pass,否则会报错

输入以下命令启动Web环境

nginx sudo /etc/init.d/nginx restart
php sudo /etc/init.d/php start

5.完成!

在/var/www/html/下创建php文件,并且在里面输入

[/bash]

如果不出所料的话,打开你的IP即可看到phpinfo

6.一些问题

1.MySQL

我在用phpMyAdmin时候出现无法登陆错误,报错(HY000/1698):Access denied for user ‘root’@’localhost’

我也不清楚为什么会出现这个错误,于是我网上查了一下,把网上的内容贴出来

sudo mysql -u root -p #登陆MySQL
use mysql;
UPDATE user SET plugin='mysql_native_password' WHERE User='root';
FLUSH PRIVILEGES;
exit;

然后,密码会清空,再次输入 mysql_secure_installation 配置一下密码就可以正常用MySQL登陆了

吴先森

文章作者

为退烧而生!

发表评论

textsms
account_circle
email

  • 我np都是用oneinstac一键搭建的,mysql从apt源装的,同样的错误,不过我每次试图修复这个错误都忘记带分号了,噗,今天早上终于修好了

    5月前 回复

吴先森的笔记

Ubuntu通过apt-get安装LNMP环境
因为CentOS的gcc版本太低,升级新版本的gcc太麻烦,懒得升级了,所以直接换了Ubuntu。以前都用LNMP一键安装脚本,这次,打算练练手,就打算用apt-get手动安装(不要问我为什么不编译安装…
扫描二维码继续阅读
2020-02-09