Ubuntu14.4下搭配WEB伺服器(apache + php + mysql)

來源:互聯網
上載者:User

標籤:

今天,趁著自己動手安裝web伺服器的餘熱,將Ubuntu14.4搭配WEB伺服器的過程記錄下來。

“一切皆檔案”。

說明:網上關於類似搭配web伺服器的教程,案例不計其數,但自己親自動手“試試”,一定會有不一樣的所獲。

1.使用者

預設為普通使用者。也就是預設的使用者:user.  當然這個user是你登入系統的名稱。如:wuheng

wuheng@wuheng-virtual-machine:~$

1-1,從user使用者切到root使用者

命令:

wuheng@wuheng-virtual-machine:~$ sudo su
root@wuheng-virtual-machine:/home/wuheng#

或者:

wuheng@wuheng-virtual-machine:~$ sudo su
[sudo] password for wuheng:
root@wuheng-virtual-machine:/home/wuheng#

此時,我們進入了root使用者了。

1-2,從root使用者切到user使用者

方法有3種:

1-2-1:  su user (user為預設的使用者名稱稱,如 wuheng)

root@wuheng-virtual-machine:/home/wuheng# su wuheng
wuheng@wuheng-virtual-machine:~$

1-2-2: 直接輸入:exit

root@wuheng-virtual-machine:/home/wuheng# exit
exit
wuheng@wuheng-virtual-machine:~$

1-2-3: 使用按鍵組合  CTRL + D

root@wuheng-virtual-machine:/home/wuheng# exit
wuheng@wuheng-virtual-machine:~$

此用法與法2類似。

拓展:http://www.cnblogs.com/weiweiqiao99/archive/2010/11/10/1873761.html

當然,安裝是在“root”使用者下進行的!

 

2.安裝apache

 

apache2的是作為一個ubuntu的軟體包,因此我們可以直接用下面命令安裝它:

 

apt-get install apache2

現在,您的瀏覽器到http://localhost,你應該看到apache2的測試頁,如下:

Apache2 Ubuntu Default Page
It works!
。。。

 

3.安裝mysql5

apt-get install mysql-server mysql-client

注意:在安裝的過程中,會出現一些提示,需要設定mysql的帳號,密碼等,根據提示一步一步完成。

 

4.安裝php5

我們可以直接安裝php5和apache的php5的模組,如下:

apt-get install php5 libapache2-mod-php5

 

5.目錄

Apache:

配置儲存在的子目錄:   /etc/apache2

設定檔是 :  /etc/apache2/apache2.conf

重啟apache命令: /etc/init.d/apache2 restart

php :

配置儲存在的子目錄:  /etc/php5

設定檔:/etc/php5/apache2/php.ini

檔案根目錄: /var/www

mysq:

配置儲存在的子目錄:  /etc/mysql

設定檔: /etc/mysql/my.cnf

重啟mysql命令: /etc/init.d/mysql reset

 

6.測試。info.php

6-1,準備檔案。  

<?phpecho phpinfo();?>

6-2,檔案許可權處理

chmod 777 /var/www/   -R

注意:/var/www ,是檔案的路徑  ,-R(可以選擇性的添加。如果添加,表示遞迴到檔案的子目錄下的檔案等擁有相同的檔案許可權)

6-3. 瀏覽器訪問

http://localhost/info.php

如:

PHP Version 5.5.9-1ubuntu4.14

。。。。。。。。。。

。。。。。。。。。。

訪問成功。

注意:開始訪問會報:404錯誤。

如:

httpd: Could not reliably determine the server‘s fully qualified domain name

httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName

解決辦法:

6-3-1,編輯apache2.conf檔案

6-3-2,添加如下:

#ServerRoot "/etc/apache2"
ServerName localhost:80

6-3-3,重啟伺服器:/etc/init.d/apache2 restart

 


 

 

 

Ubuntu14.4下搭配WEB伺服器(apache + php + mysql)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.