Ubuntu 安装php+mysql 环境
新系统安装完毕后,首先运行apt-get update 更新apt库。
然后安装ssh,输入apt-get install openssh-server,安装ssh是为了可以远程操作,不然坐在机房实在太冷了。
ok,ssh远程连接成功。
第一步 安装mysql
输入sudo apt-get install mysql-server
提示是否安装输入Y,接着输入root默认密码,需要输入2次,完成安装。
第二步 安装apache2
输入sudo apt-get install apache2
提示是否安装输入Y,完成安装
第三步 安装php5
输入sudo apt-get install php5,发现没有源,将apt的默认源改为163
前往apt sources的目录cd /etc/apt/,目录有个文件叫做sources.list 把他备份一下 cp sources.list sources.list.bak。
然后前往http://mirrors.163.com/.help/ubuntu.html,复制163的源--已改为阿里云源
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial universe deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/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://mirrors.aliyun.com/ubuntu/ xenial-security main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
将以上内容复制到,sources.list中,然后运行 apt-get update
更新完毕后,在试试装php5,ok有了 输入y继续安装。
第四步 安装php5和apache2的对应关系。
sudo apt-get install libapache2-mod-php5,不过我这个版本好像默认就装好了,可以试一下。
到/var/www/html/下创建一个info.php
<?php phpinfo();
然后访问一下,如果有信息那就ok了。
第五步 安装php的mysql库
输入 sudo apt-get install php5-mysql,一样按Y就完成了。
第五步 安装php的GD库,一些功能需要用到
输入 sudo apt-get install php5-gd
好像也已经安装了,那就不需要了。
第六步 安装php连接sqlserver(我的特殊需求)
网上搜下来是需要安装
apt-get install libsybdb5 freetds-common php5-sybase
我自己只安装了apt-get install php5-sybase
老样子输入Y,完成安装。
这样apache2+php+mysql的环境基本搭建完成。
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial mainrestricted deb-src http://archive.ubuntu.com/ubuntu xenial mainrestricted #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial mainrestricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial mainrestricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-updates mainrestricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates mainrestricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial universe deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports mainrestricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports mainrestricted 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://mirrors.aliyun.com/ubuntu/ xenial-securitymainrestricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-securitymainrestricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse