linux ubuntu 搭建lamp、虚拟主机配置等

sudo apt-get update  //更新

sudo apt-get install apache2  //安装apache2

apache2 -v  //查看apache2版本

sudo apt-get install php5  //安装php5
 
php5 -v   //查看php5版本

cat /etc/apache2/mods-enabled/php5.load   //查看apache是否加载php5

apt-get install mysql-server    //安装mysql数据库


cat /etc/php5/mods-available/mysql.ini   //查看php5是否加载数据库

apt-get install php5-mysql   //安装php5与mysql关联插件

service mysql restart

service apache2 restart

apt-get install mysql php5 apache2 php5-mysql    //这个就是方便一次性安装 

</pre><pre code_snippet_id="1774652" snippet_file_name="blog_20160721_3_8195301" name="code" class="html">chmod 777 /var/www    //更改www目录的读写权限


在ww目录下写php探针文件

?php
echo mysql_connect('localhost','root','password')?'connected success':'bye-bye';

phpinfo();
?>

然后访问一下,成功就ok了

遇到一个问题哈:

ubuntu下 vi输入方向键会变成ABCD,这是ubuntu预装的是vim tiny版本,安装vim full版本即可解决。

先卸载vim-tiny:

$ sudo apt-get remove vim-common

再安装vim full:

$ sudo apt-get install vim

这样就o了。

apt-get install php5-gd curl libcurl3 libcurl3-dev php5-curl
安装php扩展包


lamp环境配置


1.Ubuntu系统配置文件目录:  /etc

2.各组件配置文件位置  

-Apache    /etc/apache2

-MySQL    /etc/mysql

-PHP  /etc/php5


Apache虚拟主机配置

配置二级域名



修改hosts文件  ,模拟dns解析。


为三个项目创建不同的目录

apache默认目录是/var

mkdir -p /wwwroot/{video,bbs,oa}

然后在不同的目录下,创建不同字符串的index.html

重要一步:

apache配置虚拟主机最核心的几个参数

cd /etc/apache2/sites-available/

default文件

<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@localhost
        DocumentRoot /var/www/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>


复制三份,分别命名为 video,bbs,oa ,然后按照实际情况进行配置。


1.加ServerName参数    域名

2.修改DocumentRoot参数   路径

有的是有Directory参数的 也是 路径  使apache有访问权限


以video为例:

<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 video.imooc.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/wwwroot/video

        # 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>

在/etc/apache2/sites-enabled    目录下还要创建三个软连接。

ln -s ../sites-available/video
ln -s ../sites-available/bbs

ln -s ../sites-available/oa


完成之后,重启apache

 现在到浏览器中访问配置好的域名就OK了。


有时候会发生磁盘空间不足,据需要迁移数据存储目录,这里说一下,MysSQL数据存储目录迁移

迁移之前,停止mysql服务

service mysql stop


cd /var/lib/        切换到数据存储目录


创建一个目录作为目标位置

在迁移之前,要更改所属用户组和所属用户更改为mysql

chown -vR mysql:mysql


修改目标目录的权限,要与原数据目录保持一致。

chmod -vR 700 /mysqldata/          
<pre name="code" class="html">cp -av /vr/lib/mysql/* /mysqldata/      //复制的时候保持所有目录的权限一致

 复制要在root超级权限 


修改配置文件:

vi /etc/mysql/my.cnf


修改apparmor的配置文件

vi /etc/apparmor.d/usr.sbin.mysqld

重启spparmor

service apparmor restart

测试迁移数据是否迁移成功。

建立一个数据库,如果创建一个相关的文件夹,就表示迁移成功



安装phpmyadmin

apt-get install phpmyadmin
ln -s /usr/share/phpmyadmin/ /var/www/pma














评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值