阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Ubuntu 16.04搭建LAMP开发环境

121次阅读
没有评论

共计 3651 个字符,预计需要花费 10 分钟才能阅读完成。

安装好 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 用户 susu -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 -tunplnetstat -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

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 库名

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-10/136327.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计3651字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中