Ubuntu搭建LAMP环境

来源:互联网 发布:上海大学网络教育平台 编辑:程序博客网 时间:2024/05/17 13:10

原文地址:http://blog.csdn.net/callmeback/article/details/8130190


LAMP搭建环境

安装过程

第一步 安装Apache2

sudo apt-get install apache2
第二步 安装PHP模块
sudo apt-get install php5
第三步 安装Mysql
sudo apt-get install mysql-server
sudo apt-get install mysql-client
第四步 其他模块安装
sudo apt-get install libapache2-mod-php5
sudo apt-get install libapache2-mod-auth-mysql
sudo apt-get install php5-mysql
sudo apt-get install php5-gd
第五步 测试Apache是否正常工作
打开浏览器,输入localhost,看看是否有It Works!网页展示。目录为/var/www
第六步 修改权限/var/www
sudo chomod 777 /var/www
第七步 安装phpmyadmin
sudo apt-get install phpmyadmin
安装过程中选择apache2,点击确定。下一步选择是要配置数据库,并输入密码。
第八步 测试phpmyadmin
sudo ln -s /usr/share/phpmyadmin /var/www
然后直接运行http://localhost/phpmyadmin,看有没有数据库管理软件出现。


配置过程

第一步 启用mod_rewrite模块

sudo a2enmod rewrite
重启Apache服务器:sudo /etc/init.d/apache2 restart或者sudo service apache2 restart
第二步 设置Apache支持.htm .html .php
sudo gedit /etc/apache2/apache2.conf&
添加以下句子:AddType application/x-httpd-php .php .htm .html
第三步 测试php网页
编辑mysql_test.php代码如下:
<?php
$link = mysql_connect("localhost", "root", "password");
if(!$link)
die('Could not connect: ' . mysql_error());
else
echo "Mysql 配置正确!";
mysql_close($link);
?>
访问 http://localhost/mysql_test.php 显示’Mysql 配置正确‘就代表配置正确。
第四步 第三步这里出现了乱码以后解决方法
打开配置文件sudo gedit /etc/apache2/apache2.conf&
添加如下代码:AddDefaultCharset UTF-8
到此为止配置OK。

多站点配置:

<VirtualHost *:80>

 ServerAdmin webbmaster@localhost

 ServerName blog.myfunc.com

 DocumentRoot /var/www/webb

 <Directory />

  Options FollowSymLinks

  DirectoryIndex index.php index.html index.htm

  AllowOverride None

 </Directory>

 <Directory /var/www/webb>

# Options Indexes FollowSymLinks MultiViews

  Options FollowSymLinks

  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-f

  RewriteCond %{REQUEST_FILENAME} !-d

  RewriteRule . index.php

  AllowOverride All

  Order allow,deny

  allow from all

 </Directory>


 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

 <Directory "/usr/lib/cgi-bin">

  AllowOverride None

  Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch

  Order allow,deny

  Allow from all

 </Directory>


 ErrorLog ${APACHE_LOG_DIR}/error.log


 # Possible values include: debug, info, notice, warn, error, crit,

 # alert, emerg.

 LogLevel warn


 CustomLog ${APACHE_LOG_DIR}/access.log combined


    Alias /doc/ "/usr/share/doc/"

    <Directory "/usr/share/doc/">

 Options Indexes MultiViews FollowSymLinks

 AllowOverride None

 Order deny,allow

     Deny from all

    Allow from 127.0.0.0/255.0.0.0 ::1/128

</Directory>

</VirtualHost>


或者



<VirtualHost *:80>

DocumentRoot "/var/www/wwwroot"

ServerName www.myfunc.com

</Virtualhost>







0 0
原创粉丝点击