A, LAMP environment:
Install Apache, MySQL and PHP three software environment in Linux, but also need to install some intermediate plug
Linux is a free open-source software, which means the source code available operating system
Apache is the most popular use of an open source WEB server software
MySQL is multi-threaded, multi-user SQL database management system
PHP is a programming language originally designed to produce dynamic websites, PHP is mainly used for server-side application software
Second, build a LAMP environment in Ubuntu
(Installation Reference https://www.cnblogs.com/opsprobe/p/9126411.html great detail, thanks!)
1. Install Apache2
apt install apache2 安装apache
- Intermediate process is omitted
systemctl status apache2 check the Apache service is turned on
netstat -ntulp Apache check whether to open ports
- Apache2 default configuration file: vim /etc/apache2/sites-enabled/000-default.conf
- Default installation source location: / var / www / html
After the service starts, browse the server's IP address, display default page that comes with Apache, the installation was successful.
2. Install MySQL
1 dpkg -l | grep mysql to see if the installed MySQL, if no response is that there is no installation 2 apt install mysql-server install MySQL
netstat -tap | grep mysql mysql to see whether to open ports
mysql_secure_installation security configuration, according to the requirements to do the appropriate settings
mysql -uroot -p login mysql database
- The installation was successful shown in FIG.
- Mysql commonly used commands
1 show dtatbases; 查看所有的数据库 2 select user(); 查看当前用户
- Mysql配置文件的位置 /etc/mysql/mysql.conf.d/mysqld.cnf 或 /etc/mysql/my.cnf 链接文件
3.安装php
1 apt install php 安装PHP 2 或 apt install php7.2 php-pear libapache2-mod-php7.2 php7.2-mysql 安装PHP7以及扩展 3 apt install php7.2-curl php7.2-json php7.2-cgi 安装php的组件
- 省略中间过程 测试 php -v 显示php版本表示安装好了
- 设置首先提供PHP页面
修改默认主页文档,将其更改为首先列出index.php
vi /etc/apache2/mods-enabled/dir.conf 打开默认主页文档
默认:
- 如果没装vim,vi又不是很会用,这里建议用替换来改:
:%s/index.php/index.html
:%s/index.html/index.php
更改为:
systemctl restart apache2 重新启动Apache服务器
在/var/www/html/新建index.php文件,写入以下内容
1 vi /var/www/html/index.php 2 <?php 3 phpinfo(); 4 ?>
在火狐浏览器里输入IP地址,可以访问到PHP的默认信息页面
- 并且输入http://192.168.214.128/index.html 也可以访问到apache的默认信息页面
四、安装phpMyAdmin
phpMyAdmin基于web形式的管理mysql数据库的平台
1 apt install phpmyadmin 安装phpMyAdmin 2 ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin 软链接,将/usr/share/phpmyadmin/ 放在/var/www/html下
- 安装过程中根据向导和自己的需求
在浏览器中输入你的IP/phpmyadmin
- 注:可能会出现以下情况,虽然已经在安装过程中设置了用户名和密码
- 解决方法:
方法1:可以试试将root改为phpmysql
方法2:
1 sudo mysql -u root -p 连接mysql数据库 2 CREATE USER 'root_sql'@'localhost' IDENTIFIED BY 'yourpasswd'; 创建一个用来赋予权限的账户(例如 root_sql) 3 GRANT ALL PRIVILEGES ON *.* TO 'root_sql'@'localhost' WITH GRANT OPTION; 4 FLUSH PRIVILEGES;
然后用这个用户和密码登录phpmyadmin,就可以看到如下图所示界面
五、使用Navicat连接数据库
1.修改配置文件
vi /etc/mysql/mysql.conf.d/mysqld.cnf 打开配置文件
- 将bind-address = 127.0.0.1 注释掉,前面加上#
- 修改后如图所示
2.mysql数据库设置远程连接权限
1 mysql -uroot -p 登录mysql数据库 2 grant all on *.* to root@'%' identified by '你的密码' with grant option; 开启远程连接权限 3 /etc/init.d/mysql restart 重启mysql
3.打开Navicat,做如下图所示操作后,点击确认 注:IP地址为Ubuntu虚拟机的地址
4.显示如图所示,表示连接成功