Ubuntu16.04 搭建LAMP环境

来源:互联网 发布:unity3d寻路 提示路线 编辑:程序博客网 时间:2024/05/16 08:55

更新

sudo apt-get update

完成

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

安装Apache2

sudo apt-get install apache2

完成

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) ...

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

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

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

这里写图片描述

安装MySql

sudo apt-get install mysql-server mysql-client

安装完成

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

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

Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 5Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 

安装PHP

sudo apt-get install php

安装完成

Creating config file /etc/php/7.0/fpm/php.ini with new versionSetting 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) ...

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

PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )Copyright (c) 1997-2017 The PHP GroupZend 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

安装其他模块

sudo apt-get install libapache2-mode-phpsudo apt-get install php-mysql

重启服务

sudo service mysql restartsudo service apache2 restart

测试

创建一个文件

vim /var/www/html/phpinfo.php

内容为

<?php echo phpinfo(); ?>

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

这里写图片描述

修改权限

/var/www sudo chomod 777 /var/www

安装phpMyAdmin

sudo apt-get install phpmyadmin
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) ...

创建快捷方式

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

启用Apache mod_rewrite模块

sudo a2enmod rewrite

重启服务

sudo service php7.0-fpm restartsudo service apache2 restart

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

sudo时出现sudo: unable to resolve host xxxx

执行sudo时发现会出警告

sudo: unable to resolve host

解决办法

vim /etc/hosts

原始内容为

127.0.0.1       localhost# The following lines are desirable for IPv6 capable hosts::1     localhost ip6-localhost ip6-loopbackff02::1 ip6-allnodesff02::2 ip6-allrouters

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

原创粉丝点击