欢迎使用CSDN-markdown编辑器

来源:互联网 发布:模板支架计算软件 编辑:程序博客网 时间:2024/05/24 05:03

Ubuntu上LAMP环境搭建

以下内容*参考自OSC的这篇文章*

在慕课网上有一个LAMP配置的课程讲的也很好,还讲了一些Ubuntu和Linux的拓展知识

  • 安装

    1. sudo apt-get install apache2(在安装之后会新建一个目录/var/www)
    2. sudo apt-get install mysql-server mysql-client
    3. sudo apt-get install php5 libapache2-mod-php5
      sudo /etc/init.d/apache2 restart重启apache使其加载php模块

  • 配置

    1. sudo vim /etc/apache2/apache2.conf
      文档的最后添加:AddType application/x-httpd-php .php .html .htm
      接着需要添加默认字符集:AddDefaultCharset UTF-8
      根据需要添加首页文件的访问顺序:
      <IfModule dir_module>
          DirectoryIndex index.htm index.html index.php
      </IfModule>
      接着修改Apache的默认路径:sudo vim /etc/apache2/sites-enabled/000-default.conf
      在文档中找到DocumentRoot /var/www/html改成/var/www
      重启apache:service apache2 restart
    2. sudo vim /etc/php5/apache2/php.ini
      根据自己的需要修改默认时区,找到;date.timezone=改为date.timezone=PRC
    3. sudo vim /etc/mysql/my.cnf
      默认是只允许本地访问数据库的,如果要远程访问MySQL,注释掉bind-address 127.0.0.1

  • 测试

    1. 在浏览器中输入localhost来访问/var/www目录下的index.html
    2. sudo netstat -tap | grep mysql
      如果能够看到tcp 0 0 localhost:mysql *.* LISTEN 1060/mysqld等类似的样子就说明能够正常运行,如果不能正常运行的话
      mysql:sudo /etc/init.d/mysql restart
    3. sudo chmod -R 777 /var/www
      在/var/www目录下新建一个文件test.php,写入以下代码<?php phpinfo(); ?>
      访问localhost/test.php如果能够看到php参数的一个页面说明php运行正常.
0 0
原创粉丝点击