Ubuntu 18.04 LAMP(Linux+Apache+Mysql+PHP)環境建立

若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

If you like this post, please click the ads on the blog or buy me a coffee. Thank you very much.

底下紀錄如何在 Ubuntu 18.04 上建立 LAMP 的環境。
This note demonstrates how to create a LAMP environment on an Ubuntu 18.04 server.

步驟一:安裝 Apache Web Server (Step One: Installing apache web server)
Open a console and input the following commands to install apache.
  1. sudo apt-get update
  2. sudo apt-get install apache2

接著查詢主機IP
You can find your server's public IP address by the following command:
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
    在瀏覽器鍵入 local host ip。
    Type the address in your web browser(Google chrome or firefox .etc).
    http://server_domain_name_or_IP

    若在瀏覽器上看到下圖,表示 apache已安裝成功。If you see the below message, your apache installation is completed.

    可看到上圖時,apache便已經可跑靜態網頁了,預設的html檔案存放位置為 /var/www/html


    步驟二:安裝MySql(Step Two: Installing mysql
    Open a console and input the following commands to install mysql.
    sudo apt-get install mysql-server
    安裝完後輸入以下指令進行安全性設定
    Type the following command to secure the MySQL installation:
    sudo mysql_secure_installation







    步驟三:安裝php與設定 php.ini(Step Three: Installing php and configuring the php.ini)
    Installing php:
    sudo apt-get install php-fpm php-mysql php libapache2-mod-php
    Modifying dir.conf file:
    sudo nano /etc/apache2/mods-enabled/dir.conf
    From
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
    To
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm 

    Save and restart apache service:
    sudo service apache2 restart


    步驟四:建立php測試檔案(Step Five: Create a php file to test)
    # Creating the test php file
    sudo nano /var/www/html/info.php
    Input the following php code into the new file(info.php).
    <?php
    phpinfo();
    
    
    Open your browser to visit this page:
    http://your_server_domain_or_IP/info.php

    You should see some information about your server:


    參考資料:

    沒有留言:

    張貼留言