Ubuntu 16.04 apt-get搭建LAMP環境

來源:互聯網
上載者:User
本文重點介紹在Ubuntu中使用apt-get安裝LAMP(Ubuntu 16.04,Apache2.4.18,mysql5.7.12,php7.0.4)環境,所以不再介紹如何安裝Ubuntu。

安裝Apache:

weirubo@weirubo-VirtualBox:~$ sudo apt-get install apache2
查看Apache版本:

weirubo@weirubo-VirtualBox:~$ apache2 -vServer version: Apache/2.4.18 (Ubuntu)Server built:   2016-04-15T18:00:57
上面資訊說明Apache安裝成功,通過瀏覽器訪問Apache:

http://192.168.199.232/

安裝PHP7:

weirubo@weirubo-VirtualBox:~$ sudo apt-get install php7.0
查看PHP版本:

weirubo@weirubo-VirtualBox:~$ php7.0 -vPHP 7.0.4-7ubuntu2 (cli) ( NTS )Copyright (c) 1997-2016 The PHP GroupZend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
上面資訊說明PHP7安裝成功。

安裝 libapache2-mod-php7.0:

weirubo@weirubo-VirtualBox:~$ sudo apt-get install libapache2-mod-php7.0

查看 libapache2-mod-php7.0是否安裝成功:

weirubo@weirubo-VirtualBox:~$ cat /etc/apache2/mods-enabled/php7.0.load# Conflicts: php5LoadModule php7_module /usr/lib/apache2/modules/libphp7.0.so
上面資訊說明 libapache2-mod-php7.0安裝成功,並且php7成功載入模組libphp7.0.so

安裝MySQL:

weirubo@weirubo-VirtualBox:~$ sudo apt-get install mysql-server
安裝過程中會要求設定root密碼。

安裝php7.0-mysql:

weirubo@weirubo-VirtualBox:~$ sudo apt-get install php7.0-mysql
重啟MySQL:

weirubo@weirubo-VirtualBox:~$ sudo service mysql restart
重啟Apache:

weirubo@weirubo-VirtualBox:~$ sudo service apache2 restart
到此已完成LAMP環境搭建,我們來寫一個php指令碼測試是否apache可以解析php檔案:

建立一個php檔案,phpinfo.php

weirubo@weirubo-VirtualBox:~$ sudo vim /var/www/html/phpinfo.php

輸入php代碼,儲存並退出:

 使用瀏覽器訪問: 

http://192.168.199.232/phpinfo.php

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.