Ubuntu 16.04 安装 LAMP Install Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04

Verified and Tested 03/1/16

Introduction

In this How-To, we install LAMP on an Ubuntu 16.04 Server. LAMP is a simple software bundle made of 4 components, Linux, Apache, MySQL, and PHP. Linux the core of the platform, in this case, we are using Ubuntu 16.04. Apache is the web server, majority of the web servers in the world are running Apache MySQL is a database management system, developed by Oracle. PHP is an extremely popular programming language that is widely used in web development. Altogether this forms LAMP or LAMP stack.

Prerequisites

A server with Ubuntu 16.04  installed. Get a reliable server from Atlantic.Net if you do not have one.

Installing LAMP on Ubuntu 16.04

Before we begin the installation, it is important that your system is up to date, you can do so with the following command:

apt update

Once updating, we can get to the first step of making a LAMP stack by installing Apache.

Installing Apache on Ubuntu 16.04 (安装Apache)

Install Apache by running the following command:

apt install apache2

Hit enter to when it asks “Do you want to continue?” during the install.

After the install, you can check to see if Apache is running by running the command:

service apache2 status

Also, you can verify if all is working by opening your browser and going to http://youripaddress

If you do not know your IP address, you can run the following command:

ifconfig

anet-linux-apache-mysql-and-php-lamp-on-ubuntu-14-04-01

An example of ifconfig showing the IP address 172.20.6.154

In our case, we would put http://172.20.6.154 in your browser’s address bar and get the following page:

anet-linux-apache-mysql-and-php-lamp-on-ubuntu-14-04-02

The default page for Apache on Ubuntu 14.04

Installing MySQL on Ubuntu 16.04 (安装MySQL)

Install MySQL with the following command:

sudo apt install mysql-server php7.0-mysql

Hit enter to when it asks “Do you want to continue?” during the install.

During the install, it will prompt you to enter a MySQL root password. Set any password that you would like. It should be a strong password.

anet-linux-apache-mysql-and-php-lamp-on-ubuntu-14-04-03

Enter a strong password of your choice

After you enter your MySQL root password, you will need to re-enter it.

anet-linux-apache-mysql-and-php-lamp-on-ubuntu-14-04-04

Re-enter the password you set before

Continue with the MySQL Security installation with the following command:

mysql_secure_installation

Note: You will be prompted with a series of questions. Just type N for the change root password and Y for yes on all of the rest, see the screen shot below:

anet-linux-apache-mysql-and-php-lamp-on-ubuntu-14-04-05

An example of what mysql_secure_installation looks like

Verify that MySQL is running with the following command:

service mysql status

Installing PHP on Ubuntu 16.04 (安装PHP)

Install PHP with the following command:

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

Hit enter to when it asks “Do you want to continue?” during the install.

Create a test PHP file called info.php in /var/www/html/. In this how-to, we will be using the text editor nano with the following command:

nano /var/www/html/info.php

Insert the following code in the text editor then save and exit:

<?php
    phpinfo();
?>

Since we made changes, we need to restart Apache so that the changes take effect:

service apache2 restart

Test your page in your browser with the following hyperlink changed with your IP address:

http://localhost/info.php

install-linux-anet-apache-mysql-php-lamp-stack-on-ubuntu-16-04-06

The result of the php.info file you made.

Congratulations! You have just installed LAMP on your Ubuntu 16.04 Server. Thank you for following this How-To on installing LAMP, please check back for more updates.

from: https://www.atlantic.net/community/howto/install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04/

如果没有phpMyAdmin, 那么就安装下面步骤:

Installing phpMyAdmin on Ubuntu 16.04 (安装phpMyAdmin)

Step 1: Install phpMyAdmin

First, you’ll follow a simple best practice: ensuring the list of available packages is up to date before installing anything new.

apt-get -y update

Then it’s a matter of just running one command for installation via apt-get:

apt-get -y install phpmyadmin

Step 2: Basic Configuration

As the installation runs you’ll be asked a few simple questions regarding the basic configuration of phpMyAdmin.

At the first screen, select apache2 by using the space bar, then hit enter to continue.

Ubuntu 16.04 安装 LAMP Install Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04
Ubuntu 16.04 安装 LAMP Install Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04

At the second screen, which asks “configure the database for phpmyadmin with dbconfig-common?”, select Yes, then hit enter to continue.

Ubuntu 16.04 安装 LAMP Install Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04
Ubuntu 16.04 安装 LAMP Install Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04

At the third screen enter your MySQL password, then hit enter to continue.

Ubuntu 16.04 安装 LAMP Install Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04
Ubuntu 16.04 安装 LAMP Install Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04

And finally at the fourth screen set the password you’ll use to log into phpmyadmin, hit enter to continue, and confirm your password.

Ubuntu 16.04 安装 LAMP Install Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04
Ubuntu 16.04 安装 LAMP Install Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04

Step 3: Finish the Configuration of Apache

For a refresher on editing files with vim see: New User Tutorial: Overview of the Vim Text Editor

vim /etc/apache2/apache2.conf

 

Add the following to the bottom of the file:

# phpMyAdmin Configuration
Include /etc/phpmyadmin/apache.conf

Then exit and save the file with the command :wq.

And, restart Apache 2 with the following command:

service apache2 restart

Verify that phpMyAdmin is working by visiting the_IP_of_your_server/phpmyadmin. For example: http://127.0.0.1/phpmyadmin

更多参考:

Mysql: 图解 inner join、left join、right join、full outer join、union、union all的区别

PHP5: mysqli 插入, 查询, 更新和删除  Insert Update Delete Using mysqli (CRUD)

命令行导出和导入数据库 How to export and import MySQL database using command line Interface

php将json格式的数据直接存入mysql数据库

 

更多参考:Ubuntu 17.04 / 17.10 安装 LAMP, Linux Apache2 Mysql PHP, 以及phpmyadmin, INSTALLING LAMP ON UBUNTU 17.04 / 17.10

 

本文:Ubuntu 16.04 安装 LAMP Install Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04