阿里云主机Ubuntu 14.04下安装php5.5.9+mysql+Apache配置多主机

平时用Ubuntu 14.04系统用的非常多,经常配置环境,但是因为自己的记性不太好,每次配置都还需要百度,所以整理好配置过程发到自己博客,下次需要的时候,直接拿出来看。

首先可以使用命令更新一下软件源

apt-get update

更新完成之后开始安装apache2

apt-get  install apache2

安装完成之后可以使用下面的命令查看是否安装成功

apache2 -v

如果apache正确安装的话,会返回apache的版本信息,如下
apache版本信息

通过浏览器访问服务器IP,如果出现Apache欢迎界面,表示安装成功,如下所示
apache安装成功界面

apache安装成功之后,开始安装php5

apt-get install php5

安装成功之后,可以使用一下命令查看php的版本

php5 -v

查看php版本
返回如上图的版本信息,表示php5安装成功

查看apache是否已经加载libphp5.so模块,该模块是Apache用来指挥PHP解析器来执行PHP代码的模块

cat /etc/apache2/mods-enabled/php5.load

这里写图片描述
表示该模块已经加载

安装mysql ,安装过程中会让输入数据库的root用户密码,两次输入后即可继续安装至完成,注意这个密码不是系统root账户的密码,而是你安装的数据库默认用户root的密码

apt-get install mysql-server

检查是否加载了mysql.so的扩展,PHP通过该扩展链接mysql执行CURD操作,如果提示no such file or directory 表示PHP默认没有安装该操作数据库的扩展,需要自行安装

cat /etc/php5/mods-available/mysql.ini

如果上步不成功,则执行这步,给PHP安装mysql扩展

apt-get install php5-mysql

查看扩展是否安装成功,不同的版本存放的位置可能不同

cat /etc/php5/mods-available/mysql.ini

这里写图片描述
表示mysql.so扩展已经安装成功。

重启mysql和Apache

service mysql restart
service apache2 restart

给php安装常用扩展

apt-get install php5-gd curl libcurl3 libcurl3-dev php5-curl

安装完成之后,重启Apache

service apache2 restart

配置多主机如下

1.创建虚拟目录

现在,让我们继续安装虚拟主机。正如我先前所述,我要新建2台虚拟主机分别命名为“unixmen1.local”和“unixmen2.local”.

创建一个公用的文件夹来存放这两台虚拟主机的数据。

首先,让我们为unixmen1.local这个站点创建一个目录:

mkdir -p /var/www/unixmen1.local/public_html

接着,为for unixmen2.local站点创建一个目录:

mkdir -p /var/www/unixmen2.local/public_html

2.设置所有者和权限

上面目录现在只有root拥有权限。我们需要修改这2个目录的拥有权给普通用户,而不仅仅是root用户。

chown -R $USER:$USER /var/www/unixmen1.local/public_html/
chown -R $USER:$USER /var/www/unixmen2.local/public_html/

“$USER”变量指向了当前的登录用户。
设置读写权限给apache网页根目录(/var/www)及其子目录,这样每个人都可以从目录中读取文件。

chmod -R 755 /var/www/

这样,我们就创建好了一些文件夹来保存网络相关数据并分配必要的权限和所属用户。

3.为虚拟主机创建示例页

现在,我们给网站增加示例页。第一步,让我们给虚拟主机unixmen1.local创建一个示例页。

给unixmen1.local虚拟主机创建一个示例页,

vi /var/www/unixmen1.local/public_html/index.html

添加以下内容:

<html>
<head>
<title>www.unixmen1.local</title>
</head>
<body>
<h1>Welcome To Unixmen1.local website</h1>
</body>
</html>

保存并关闭文件。

同样的,添加示例页到第二台虚拟主机。

sudo vi /var/www/unixmen2.local/public_html/index.html

添加以下内容:

<html>
<head>
<title>www.unixmen2.local</title>
</head>
<body>
<h1>Welcome To Unixmen2.local website</h1>
</body>
</html>

保存并关闭文件。

4.创建虚拟主机配置文件

默认情况下,apache有一个默认的虚拟主机文件叫000-default.conf。我们将会复制000-default.conf文件内容到我们新的虚拟主机配置文件中。

cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/unixmen1.local.conf
cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/unixmen2.local.conf

确保虚拟主机配置文件末尾包含.conf扩展名。

现在,修改unximen1.local.conf文件以符合需求。

vi /etc/apache2/sites-available/unixmen1.local.conf

使相关的变化直接呈现在unixmen1站点中(译注:以“#”开头的注释行可以忽略。)。

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@unixmen1.local
ServerName unixmen1.local
ServerAlias www.unixmen1.local
DocumentRoot /var/www/unixmen1.local/public_html

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

同理,修改第二台主机文件。

vi /etc/apache2/sites-available/unixmen2.local.conf

使相关的修改在unixmen2 站点呈现出来。

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@unixmen2.local
ServerName unixmen2.local
ServerAlias www.unixmen2.local
DocumentRoot /var/www/unixmen2.local/public_html

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

修改虚拟主机文件后,禁用默认的虚拟主机配置(000.default.conf),然后启用新的虚拟主机配置,如下所示。

sudo a2dissite 000-default.conf
sudo a2ensite unixmen1.local.conf
sudo a2ensite unixmen2.local.conf

最后,重启apache服务器。
就是这样。现在,我们成功地配置了apach虚拟主机在我们的Ubuntu服务器上

文章出处:
Ubuntu Server 14.04 安装 LAMP
在Ubuntu 14.04 LTS系统中设置Apache虚拟主机

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值