1.安裝apache
sudo apt-get update
sudo apt-get install apache2
這時http://你機器的ip,就可以訪問了。
2.安裝mysql
sudo apt-get install mysql-server php5-mysql
安裝過程中會要求你輸入root用戶的密碼
安裝完成后執行
sudo mysql_install_db
這句的意思是初始化數據庫目錄結構
安裝完成后 mysql -u root -p
輸入密碼應該是可以進入數據庫的.
指定編碼創建數據庫:
CREATE DATABASE IF NOT EXISTS yourdbname DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
從文件導入數據:
進入指定庫后,source /var/tmp/all.mysql
導出數據:
mysqldump -u$USER -p$PASSWD -h127.0.0.1 -P3306 --routines --default-character-set=utf8 --databases mysql > db.all.sql
3.安裝php及一些必要的擴展
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt php5-curl php5-imagick php5-cli
如果你想找找其它擴展可以用命令:apt-cache search php5-
4.修改默認主頁
修改 /etc/apache2/mods-enabled/dir.conf
把DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm中index.php改到最前面(可以根據自已需要)
如:DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
5.重啟apache2讓修改生效,並測試
重啟apache2:sudo service apache2 restart
ubuntu14.04中apache的網站主目錄是在:/var/www/html
在此目錄新建info.php文件,內容為:
<?php
phpinfo();
?>
訪問:http://你服務器ip/info.php如果顯示php環境信息,測表示安裝成功
6.新建站點
在apache2的配置目錄(/etc/apache2/)中有兩個目錄是與新建站點有關的
sites-availables包含所有站點文件,即有啟用的與非啟用的
sites-enabled包含啟用了的站點,一般來說sites-enabled里的文件是sites-availables鏈接
在/etc/apache2/apache2.conf文件中包含一句:IncludeOptional sites-enabled/*.conf,所以只有在sites-enabled目錄中加了站點文件才會生效
在sites-availables里添加文件test.conf
ln -s /etc/apache2/sites-availables/test.conf /etc/apache2/sites-enabled/test.conf
7.編輯站點文件
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
ServerAlias a.test.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/test
</VirtualHost>
本機測試添加hosts記錄,即可訪問。