0%

Ubuntu+LAMP服务器搭建

安装Apache

1 安装

1
sudo apt-get install apache2

安装完成后打开http://localhost 如果能访问说明服务器已经能够运行

2 设置index.php优先

1
sudo gedit /etc/apache2/mods-enabled/dir.conf

更改为首先列出index.php,修改配置文件以后,我们需要重新启动一下Apache服务器。

1
sudo systemctl restart apache2

3 为了方便后续使用,修改/var/www/html的权限

1
sudo chmod 777 /var/www/html

安装MySQL

1 安装

1
sudo apt-get install mysql-server

2 修改mysql root密码

1
sudo gedit /etc/mysql/debian.cnf

复制debian-sys-maint的密码,等一会登陆的时候粘贴

1
2
3
4
5
6
7
mysql -u debian-sys-maint -p

use mysql;
update user set authentication_string=password('Pwd@1234') where user='root';
update user set plugin="mysql_native_password";
flush privileges;
quit;

安装PHP

1 安装

1
sudo apt-get install php

2 打开mysqli扩展

1
2
sudo apt-get install php-mysql
sudo gedit /etc/php/7.2/apache2/php.ini

去掉注释:extension=mysqli,保存后重启Apache即可
3 在/var/www/html下建立index.php,内容如下:

1
2
3
<?php
phpinfo();
?>

之后再打开http://localhost 可以查看PHP配置情况

安装phpMyAdmin

https://www.phpmyadmin.net/downloads/ 下载最新版程序并解压到/var/www/html目录下
然后登陆http://localhost/phpmyadmin 进入数据库管理网站