Ubuntu16.04 搭建LAMP环境

更新

sudo apt-get update
  • 1

完成

Fetched 35.8 MB in 8s (4,233 kB/s)                                                                                        
Reading package lists... Done
  • 1
  • 2
  • 3

安装Apache2

sudo apt-get install apache2
  • 1

完成

Processing triggers for libc-bin (2.23-0ubuntu9) ...
Processing triggers for systemd (229-4ubuntu18) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
  • 1
  • 2
  • 3
  • 4
  • 5

输入命令 apachectl -v
可以看到当前apache版本

Server version: Apache/2.4.18 (Ubuntu)
Server built:   2017-07-27T14:34:01
  • 1
  • 2

访问服务器IP , 出现It works! 则表示安装成功

这里写图片描述

安装MySql

sudo apt-get install mysql-server mysql-client
  • 1

安装完成

Processing triggers for libc-bin (2.23-0ubuntu9) ...
Processing triggers for systemd (229-4ubuntu18) ...
Processing triggers for ureadahead (0.100.0-19) ...
  • 1
  • 2
  • 3
  • 4

尝试登陆下数据库 输入命令mysql -u root -p
输入密码之后按回车

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.19-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

安装PHP

sudo apt-get install php
  • 1

安装完成

Creating config file /etc/php/7.0/fpm/php.ini with new version
Setting up php7.0 (7.0.22-0ubuntu0.16.04.1) ...
Setting up php (1:7.0+35ubuntu6) ...
Processing triggers for systemd (229-4ubuntu18) ...
Processing triggers for ureadahead (0.100.0-19) ...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

输入命令 php -v
可以看到PHP的版本

PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.22-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies
  • 1
  • 2
  • 3
  • 4

安装其他模块

sudo apt-get install libapache2-mode-php
sudo apt-get install php-mysql
  • 1
  • 2

重启服务

sudo service mysql restart
sudo service apache2 restart
  • 1
  • 2

测试

创建一个文件

vim /var/www/html/phpinfo.php
  • 1

内容为

<?php echo phpinfo(); ?>
  • 1

浏览器访问http://ip地址/phpinfo.php

这里写图片描述

修改权限

/var/www sudo chomod 777 /var/www
  • 1

安装phpMyAdmin

sudo apt-get install phpmyadmin
  • 1
Processing triggers for libc-bin (2.23-0ubuntu9) ...
Processing triggers for libapache2-mod-php7.0 (7.0.22-0ubuntu0.16.04.1) ...
Processing triggers for php7.0-fpm (7.0.22-0ubuntu0.16.04.1) ...
  • 1
  • 2
  • 3
  • 4

创建快捷方式

sudo ln -s /usr/share/phpmyadmin /var/www/html
  • 1

启用Apache mod_rewrite模块

sudo a2enmod rewrite
  • 1

重启服务

sudo service php7.0-fpm restart
sudo service apache2 restart
  • 1
  • 2

访问浏览器 http://ip地址/phpmyadmin

sudo时出现sudo: unable to resolve host xxxx

执行sudo时发现会出警告

sudo: unable to resolve host
  • 1

解决办法

vim /etc/hosts
  • 1
  • 2

原始内容为

127.0.0.1       localhost

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

在127.0.0.1 localhost后加上当前主机名称即可 , 如127.0.0.1 localhost xxxx


猜你喜欢

转载自blog.csdn.net/flycappuccino/article/details/80804641
今日推荐