Home > Backend Development > PHP Tutorial > How to install LAMP server system on Ubuntu?

How to install LAMP server system on Ubuntu?

WBOY
Release: 2016-08-08 09:20:48
Original
865 people have browsed it

Why should you install LAMP server on Ubuntu? When working in web development, I prefer to develop in a development environment on my own computer without distractions. I'd rather make most of my mistakes invisible to others than have them all visible to everyone on the internet. In order to have such a private development environment, I installed a LAMP system. By the way, if you're not familiar with LAMP, it stands for Linux, Apache, MySQL and PHP (and/or Perl). LAMP is one of the most common web hosting platforms on the Internet, so it is one of the excellent environments for building and testing websites.

Follow these step-by-step instructions below to install and configure LAMP on Ubuntu 12.04 (Precise Pangolin). This process has also been tested on Linux Mint 13/14/15, Ubuntu 12.10 (Quantal Quetzal) and Ubuntu 13.04 Raring Ringtail. If you have a reasonably fast broadband connection, it should take less than half an hour.

Install LAMP on Ubuntu

The developers of Ubuntu have made it easy for people to install and configure LAMP packages with the help of a single terminal command. So, open a terminal window and let’s get started.

  1. sudo apt-get install lamp-server^ 

Yes, you read that right. Don't miss the caret (^) at the end. Without the caret, the command will not run. It's so magical!

Installing LAMP on Ubuntu

apt package manager now displays packages that need to be installed and are waiting for confirmation. Enter the Enter key to confirm and continue the installation.

Install the LAMP package

After it takes a while to download the package, you will be prompted to set a password for the MySQL root user.

Set MySQL Root Password

Enter the password you want to use for MySQL. This cannot be left empty. You will be prompted to enter it a second time to confirm your password.

Confirm MySQL root password

After confirming the password, apt will continue to install the remaining packages.

Installation of remaining LAMP packages

Your LAMP installation is now complete. Wow, it’s that simple! Now there are only a few steps left to configure so that you can use the system easily.

Testing Apache

Open a web browser window and enter the address http://localhost/. You should see a web page that says "It Works!".

Apache is working properly

Test php

You have confirmed that the Apache web server is working properly, so you should make sure that the installed php is working properly. To do this, you need to create a file called testing.php in /var/www. You can use a common text editor as the root user, or you can use the following terminal command:

  1. echo "php phpinfo(); ?>" | sudo tee /var/www/testing.php 

After that, you need to restart the Apache web server.

  1. sudo service apache2 restart 

Go back to your web browser and enter the address http://localhost/testing.php/, you should see a web page showing information about the installed php.

php information

Getting the Apache fully qualified domain name

You may have noticed an error message from Apache that is related to the fully qualified domain name of the server.

  1. apache2: Could not reliably determine the server's fully qualified domain 
  2. name, using 127.0.1.1 for ServerName 

This is not a big problem, but if it annoys you, you can use the following command to fix it.

  1. echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn 

Now, reload the Apache web server.

  1. sudo service apache2 reload 

You should never see this error message again.

Configuring MySQL

Since this tutorial aims to set up a local web development environment, you need to bind MySQL to the local host IP address. By default, this address should be 127.0.0.1 on your system. Just in case, you can use these commands to confirm the address.

  1. cat /etc/hosts | grep localhost 

You should see something like this:

  1. 127.0.0.1 localhost 
  2. ::1     ip6-localhost ip6-loopback 

Now you should confirm that you have the correct bind address in your MySQL my.cnf file.

  1. cat /etc/mysql/my.cnf | grep bind-address 

You should see:

  1. bind-address = 127.0.0.1 

If the bind address does not match the one set for localhost on your system, you will need to edit /etc/mysql/my.cnf as root to correct it .

Install phpMyAdmin

You don’t need to install phpMyAdmin, but unless you are a wizard with SQL, you will need it to handle administrative tasks on your MySQL database.

You can use this terminal command to install phpMyAdmin:

  1. sudo apt-get install libapache2-mod-auth-mysql phpmyadmin 

You will be prompted to confirm that you want to install the package. Press Enter to continue.

Install the phpMyAdmin package

You will then be prompted to select the web server configured for phpMyAdmin. This is important! Using the arrow keys on your keyboard, highlight apache2, then use the space space to select it. Then press Enter to continue. Make sure to click on the image below to zoom in and see what I'm describing.

Configuring phpMyAdmin for Apache

The next screen will ask you if you want to configure a database called dbconfig-common for phpMyAdmin. Select "Yes" and press Enter.

Configure dbconfig-common for phpMyAdmin

Next, you will be prompted to enter the MySQL root password you set before, so that you can create a new database. So, enter your MySQL root password and press Enter.

Enter the MySQL root password

The next tip is to create a MySQL application password for phpMyAdmin. If you want to create a random password, press Enter. I usually use the same password I use for the MySQL root password. This may not be the best approach from a security perspective, but since this is for a closed development environment the risk is likely to be minimal.

phpMyAdmin MySQL Application Password

Finally, you will be prompted to confirm the MySQL application password. Enter the same password as in the previous step and press Enter.

Confirm MySQL application password

At this point, the installation and configuration of phpMyAdmin is complete.

Test phpMyAdmin

The last step is to make sure phpMyAdmin is running normally. Open a web browser and enter the address http://localhost/phpmyadmin/. You should see a page like this.

phpMyAdmin login screen

Now you should be able to log in with the username root and the root password you created earlier.

phpMyAdmin logged in

Congratulations, now you have completed the installation and configuration of LAMP and phpMyAdmin on Ubuntu 12.04. Now, you can start creating your local website. If you are just developing a website, you can put the files into /var/www. Please note: /var/www is owned by user and group root, so you will need to copy the files there as root, or change the ownership and/or permissions of the directory so that you can write files there. Alternatively, you can do some additional Apache configuration that will keep the files somewhere in your home directory. You can even build multiple websites that way.

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces how to install the LAMP server system on Ubuntu? , including relevant content, I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template