Linux 18.04 下搭建lamp环境
一、 安装服务器
a) 在配置好sources.list文件后,apt-get updata&upgrade更新软件;
二、 安装apache2
a) Apt install apache2
b) systemctl status apache2 开启apache2服务 如图:
c) # 开启 、关闭和重启Apache服务器
i. systemctl start apache2 # 开启
ii. systemctl stop apache2 # 关闭
iii. systemctl restart apache2 # 重启
d)测试访问你的 Web 服务器,打开浏览器并输入Ubuntu18.04的IP地址
三、 数据库的安装:
a) 安装mysql:
i. apt install mysql-server
ii. 安装成功
iii. 登陆mysql设置:mysql -u root -p
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!
iv. 配置mysql允许远程访问,首先编辑 /etc/mysql/mysql.conf.d/mysqld.cnf 配置文件:
vim /etc/mysql/mysql.conf.d/mysqld.cnf
注释掉bind-address = 127.0.0.1
v. 保存退出,然后进入mysql数据库,执行授权命令:
mysql -u root -p
mysql> grant all on *.* to root@'%' identified by '你的密码' with grant option;
mysql> flush privileges; # 刷新权限
mysql> exit
然后执行exit命令退出mysql服务,再执行如下命令重启mysql:
systemctl restart mysql
成功连接
四、 PHP的安装
a) apt install php
b) 让apache首先提供php界面
打开 /etc/apache2/mods-enabled/dir.conf 文件并将其更改为首先列出index.php
systemctl restart apache2 重启一下apache2
在/var/www/html中创建一个名为index.php的新文件。
vim /var/www/html/index.php
输入以下内容
<?php
phpinfo();
?>
保存并退出该文件
c) 测试,访问ubuntu的ip,可通过ipconfig查到,IP地址后面输入/index.html也能访问到Apache的默认信息页面
五、 Php模块安装:
a) apt install php-curl
六、 Phpmyadmin安装:
a) apt install phpmyadmin
b) 安装完成后,创建phpMyAdmin的软链接到Apache的根目录下(我的是/var/www/html/)
ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
现在开始尝试访问phpMyAdmin,打开浏览器并输入:IP地址/phpmyadmin
至此,成功在Linux 18.04中搭建lamp环境。
总结:
遇到三个问题:
第一个是在mysql授权的时候,没有敲‘;’,导致命令无效,花了不少时间找问题。
第二个是第二次访问192.168.234.130时,浏览器始终停在apache的index.html界面,并未跳转到php的界面,折腾了一会儿才发现是浏览器缓存没清理,清理后就访问成功;
第三个是#1698 - Access denied for user 'root'@'localhost'(phpmyadmin的登陆界面报错),查看mysql的user表,发现root的plugin并不是本地密码,因此需要修改它,update mysql.user set authentication_string=PASSWORD('你的密码'), plugin='mysql_native_password' where user='root';再刷新一下flush privileges;重启终端就可以登陆了。
参考资料:
https://blog.csdn.net/qq_35846773/article/details/80992155