ubuntu16.04搭建LAMP(独立安装)
修改APT源
-
备份原文件source.list
sudo cp /etc/source.list /etc/source.list.bak
-
修改source.list
sudo vi /etc/source.list
阿里
deb http://mirrors.aliyun.com/ubuntu/ xenial main deb-src http://mirrors.aliyun.com/ubuntu/ xenial main deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main deb http://mirrors.aliyun.com/ubuntu/ xenial universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb http://mirrors.aliyun.com/ubuntu/ xenial-security main deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe
东北大学
deb-src http://mirror.neu.edu.cn/ubuntu/ xenial main restricted #Added by software-properties deb http://mirror.neu.edu.cn/ubuntu/ xenial main restricted deb-src http://mirror.neu.edu.cn/ubuntu/ xenial restricted multiverse universe #Added by software-properties deb http://mirror.neu.edu.cn/ubuntu/ xenial-updates main restricted deb-src http://mirror.neu.edu.cn/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties deb http://mirror.neu.edu.cn/ubuntu/ xenial universe deb http://mirror.neu.edu.cn/ubuntu/ xenial-updates universe deb http://mirror.neu.edu.cn/ubuntu/ xenial multiverse deb http://mirror.neu.edu.cn/ubuntu/ xenial-updates multiverse deb http://mirror.neu.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse deb-src http://mirror.neu.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties deb http://archive.canonical.com/ubuntu xenial partner deb-src http://archive.canonical.com/ubuntu xenial partner deb http://mirror.neu.edu.cn/ubuntu/ xenial-security main restricted deb-src http://mirror.neu.edu.cn/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties deb http://mirror.neu.edu.cn/ubuntu/ xenial-security universe deb http://mirror.neu.edu.cn/ubuntu/ xenial-security multiverse
清华大学
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse
-
更新源
sudo apt-get update -y
安装apache
通过apt-get直接进行安装
sudo apt-get install apache2 -y
通过这种方式安装后:
web根目录位于/var/www/html
配置文件位于/etc/apache2/apache2.conf
启动/停止命令为sudo service apache2 start/stop/restart
安装mysql
通过apt-get直接安装
sudo apt-get install mysql-server -y
根据提示输入MYSQL的root用户的密码,共计输入两次
通过这种方式安装完成后:
MYSQL配置文件位于/etc/mysql/mysql.conf.d/mysqld.cnf
启动/停止命令为sudo service mysql start/stop/restart
安装php
这里安装的是php5.6,同理可安装php7.x
-
删除所有php包
sudo apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`
-
添加PPA源
sudo add-apt-repository ppa:ondrej/php
如果先
add-apt-repository: command not found
运行以下命令:sudo apt-get install software-properties-common -y
-
安装PHP对应版本
sudo apt-get update -y sudo apt-get install php5.6 -y
-
安装PHP模块
sudo apt-get -y install php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl php5.6-zip
-
查看PHP版本
sudo php -v
验证
sudo vi /var/www/html/index.php
写入一下内容
<?php phpinfo(); ?>
最后访问网址进行验证(网址中的ip为ubuntu的ip)
http://ip/index.php