Ubuntu16.04搭建LAMP开发环境

虚拟机上安装好Ubuntu16.04后,是一台空白的Ubuntu。我的目的是搭建LAMP环境,顺便搭一个Python Django环境。


基本设置

1.配置网络环境

管理员给分配了一个静态IP,所以还需要进一步配置网络环境

  • 配置DNS:右上角网络连接->编辑链接->有线连接1->IPv4设置->DNS服务器:202.112.80.106->保存

  • 登陆网关:对于校园网用户来说,登陆网关才能访问外网

  • 测试: ping www.baidu.com

2.设置root密码

sudo passwd

  • 切换到root用户:su 或 su - 或 su root

  • 切换到普通用户:su 用户名 或 logout

3.更新源

sudo apt-get update

源保存的文件为:/etc/apt/sources.list


安装常用软件

1.SSH

sudo apt-get install openssh-server

  • 查看状态:service ssh status/start/stop/restart

  • 或:/etc/init.d/ssh status/start/stop/retsrt

  • 实际上,service命令就是执行/etc/init.d脚本,二者功能是一样的

2.Vim

sudo apt-get install vim

3.Tree

sudo apt-get install tree

4.Git

sudo apt-get install git


搭建LAMP

1.安装Apache

sudo apt-get install apache2

  • 测试: 浏览器访问http://Ubuntu的IP,出现It Works!网页。

  • 查看状态: service apache2 status/start/stop/restart

  • Web目录: /var/www

  • 安装目录: /etc/apache2/

  • 全局配置: /etc/apache2/apache2.conf

  • 监听端口: /etc/apache2/ports.conf

  • 虚拟主机: /etc/apache2/sites-enabled/000-default.conf

2.安装MySQL

sudo apt-get install mysql-server mysql-client

  • 测试:mysql -u root -p

  • 查看状态:service mysql status/start/stop/retart

  • 查看监听端口的情况:netstat -tunpl 或 netstat -tap

3.安装PHP

sudo apt-get install php7.0

  • 测试:php7.0 -v

4.安装其他模块

sudo apt-get install libapache2-mod-php7.0

sudo apt-get install php7.0-mysql

  • 重启服务

    • service apache2 restart

    • service mysql restart

  • 测试Apache能否解析PHP

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

    • 文件中写:<?php echo phpinfo();?>

    • 浏览器访问:http://ubuntu地址/phpinfo.php,出现PHP Version网页

5.修改权限

sudo chmod 777 /var/www

6.安装phpMyAdmin

sudo apt-get install phpmyadmin

  • 安装:选择apache2,点击确定。下一步选择是要配置数据库,并输入密码。

  • 创建phpMyAdmin快捷方式:sudo ln -s /usr/share/phpmyadmin /var/www/html

  • 启用Apache mod_rewrite模块:sudo a2enmod rewrite

  • 重启服务:

    • service php7.0-fpm restart

    • service apache2 restart

  • 测试:浏览器访问:http://ubuntu地址/phpmyadmin

7.配置Apache

vim /etc/apache2/apache2.conf

  • 添加:

  • AddType application/x-httpd-php .php .htm .html

  • AddDefaultCharset UTF-8

  • 重启Apache服务


安装python包

1.pip

sudo apt-get install python-pip

2.Django

pip install django

测试:import django

##3.MySQL-python

pip install MySQL-python

测试:import MySQLdb


常见问题

1.Secure SSH Client连接出错

  • 错误:algorithm negotiation failed

  • 解决:

    • 修改sshd的配置文件: vim /etc/ssh/sshd_config

    • 在配置文件中添加:

    Ciphers aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr,3des-cbc,arcfour128,arcfour256,arcfour,blowfish-cbc,cast128-cbc
    MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-sha1-96,hmac-md5-96
    KexAlgorithms diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group1-sha1,curve25519-sha256@libssh.org
    • 重启sshd服务: service ssh restart

2.Xshell或Xftp中文乱码

  • Xshell:文件->属性->终端->编码->UTF-8>

  • Xftp:文件->属性->选项->选中使用UTF-8编码

3.安装MySQL出错

  • 错误:

下列软件包有未满足的依赖关系:

mysql-client : 依赖: mysql-client-5.5 但是它将不会被安装

mysql-server : 依赖: mysql-server-5.5 但是它将不会被安装

E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系。

  • 解决:两种解决方法

    1. 使用Ubuntu自带的下载源,不要使用其他源(如网易)

    2. 手动安装

    • 下载MySQL:http://dev.mysql.com/downloads/mysql/

    • 使用FTP工具上传到Ubuntu

    • 解压: tar -xvf mysql-server_5.7.13-1ubuntu16.04_i386.deb-bundle.tar

    • 安装:

    sudo dpkg -i libmysqlclient20_5.7.15-1ubuntu16.04_amd64.deb libmysqlclient-dev_5.7.15-1ubuntu16.04_amd64.deb libmysqld-dev_5.7.15-1ubuntu16.04_amd64.deb mysql-common_5.7.15-1ubuntu16.04_amd64.deb mysql-community-source_5.7.15-1ubuntu16.04_amd64.deb mysql-community-client_5.7.15-1ubuntu16.04_amd64.deb mysql-client_5.7.15-1ubuntu16.04_amd64.deb mysql-community-server_5.7.15-1ubuntu16.04_amd64.deb mysql-server_5.7.15-1ubuntu16.04_amd64.deb

4.安装pip出错

解决:可改用如下命令:

sudo apt-get install python-pip python-dev build-essential

sudo pip install --upgrade pip

sudo pip install --upgrade virtualenv

5.安装Django超时报错

  • 解决

  • 设置超时时间:sudo pip install django --default-timeout 100

  • 或者使用其他下载源:pip install web.py -i http://pypi.douban.com/simple

6.安装MySQL-python报错

  • 错误:EnvironmentError: mysql_config not found

  • 解决:

  • sudo apt-get install libmysqld-dev

  • 安装MySQL-python:pip install MySQL-python

7.更新Python库

pip install --upgrade 库名

Ubuntu16.04搭建LAMP开发环境的更多相关文章

  1. Ubuntu16.04搭建各种开发环境的IDE: QT5 , CodeBlocks ,eclipse-cdt, PyCharm

    搭建Ubuntu下C/C++以及Python的集成开发环境,采用双系统(Win7+Ubuntu)的Ubuntu16.04-LTS系统, 关于双系统的搭建可以参考下面博客(图文十分详细):https:/ ...

  2. Ubuntu 16.04搭建LAMP开发环境

    基本设置 1.配置网络环境 管理员给分配了一个静态IP,所以还需要进一步配置网络环境 配置DNS:右上角网络连接->编辑链接->有线连接1->IPv4设置->DNS服务器:20 ...

  3. 阿里云学生服务器搭建网站-Ubuntu16.04安装php开发环境

    阿里云学生服务器搭建网站(2)-Ubuntu16.04安装php开发环境  优秀博文:https://www.linuxidc.com/Linux/2016-10/136327.htm https:/ ...

  4. Ubuntu 12.04 搭建Android开发环境

    Ubuntu 12.04 搭建Android开发环境 2013/7/29 Linux环境下搭建Android开发环境 大部分开发人员可能都在Windows下做开发,可能是感觉在Windows下比较方便 ...

  5. 【转】一步一步教你在Ubuntu12.04搭建gstreamer开发环境

    原文网址:http://blog.csdn.net/xsl1990/article/details/8333062 闲得蛋疼    无聊寂寞冷    随便写写弄弄 看到网上蛮多搭建gstreamer开 ...

  6. ubuntu16.04 Golang语言开发环境搭建

    golang即go语言是跨平台的语言,适用于windows 和linux平台,下面介绍linux平台下ubuntu16.04系统下的开发环境搭建过程. 一.安装开发必备环境 执行下面命令分别安装git ...

  7. Ubuntu16.04安装后开发环境配置和常用软件安装

    Ubuntu16.04安装后1.安装常用软件搜狗输入法+编辑器Atom+浏览器Chome+视频播放器vlc+图像编辑器GIMP Image Editor安装+视频录制软件RcordMyDesktop安 ...

  8. Fedora下搭建LAMP开发环境

    LAMP是Linux + Apache + MySQL +PHP/Python的缩写,是一组常用来搭建动态网站服务器的开源软件.它们本身都是各自独立的程序,但是因为开源并且常放在一起使用,所以拥有了越 ...

  9. Ubuntu16.04的PHP开发环境配置

    \3c a { text-decoration: none } 自从换了php开发之后发现还是开源语言才是长久之道,开发环境搭建方便,支持的平台也多,性能也好,考虑到这些,其他一些不如意也就不足为虑了 ...

随机推荐

  1. Git-补丁文件交互

    版本库间的交互是通过git push和/或git pull命令实现的,这是Git最主要的交互模式,但并不是全部.使用补丁文件是另外一种交互方式,适用于参与者众多的大型项目进行分布式开发. 创建补丁 G ...

  2. MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':ge

    数据库表里命名有这个字段,可怎么就是报错呢,大神的解释: 加上之后立马好用!!!

  3. 20145202马超 《Java程序设计》 实验一 实验报告

    一.实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Java程序. 二.实验内容 1.完成在Windows环境下对IDEA的配置: 2.实现求正整 ...

  4. 《Cracking the Coding Interview》——第4章:树和图——题目7

    2014-03-19 04:48 题目:最近公共父节点问题. 解法1:Naive算法,先对其高度,然后一层一层往上直到找到结果. 代码: // 4.7 Least Common Ancestor // ...

  5. 自动化测试(二)如何用python写一个用户登陆功能

    需求信息: 写一个判断登录的程序: 输入: username password 最大错误次数是3次,输入3次都没有登录成功,提示错误次数达到上限 需要判断输入是否为空,什么也不输入,输入一个空格.n个 ...

  6. appium-手势密码实现-automationName 是Appium的情况

    1. 红色区域的范围为:[66,575][1014,1523], 由于这块是一个整块,所以无法使用每个点的数据:因此只能使用LockPatternView对象拿到左上角的坐标值 2.  原理, 将九宫 ...

  7. jmeter察看结果树响应数据中文乱码解决办法

    1.到jmeter目录文件中bin文件夹下找到jmeter.properties文件,该文件为jmeter配置文件.使用编辑工具打开它. 2.找到    #sampleresult.default.e ...

  8. [译]15-spring 自动装配

    前面的章节我们已经学习了如何使用bean元素在xml配置文件中声明一个bean.也学习了如何使用bean的子元素contructor-arg 和property进行bean的依赖项的注入. 之前bea ...

  9. 【2017】KK English

    2017/11/24 Regardless of the enormous amount of photos shared on Wechat or Face book, modern city dw ...

  10. 1090 Highest Price in Supply Chain (25 分)(树的遍历)

    求所有叶节点中的最高价以及这个价格的叶节点个数 #include<bits/stdc++.h> using namespace std; ; vector<int>mp[N]; ...