132

I set up a new VPS instance of Ubuntu and am wondering what the easiest way is to get up and running with a basic LAMP stack (i.e. which packages are required, which configuration options need to be tweaked, if any, etc.).

0

17 Answers 17

124
sudo apt-get update
sudo apt-get install tasksel
sudo tasksel install lamp-server

It will install all the basic LAMP stack for you, prompt for MySQL root password, etc.

More specifically it will install the following packages, and their dependencies.

mysql-client-core-5.1 libwrap0 apache2  
libaprutil1-dbd-sqlite3 tcpd  
libapache2-mod-php5 apache2.2-common  
apache2-utils php5-common  
libaprutil1-ldap libaprutil1  
php5-mysql mysql-server-core-5.1  
libdbi-perl libplrpc-perl mysql-server  
apache2.2-bin libdbd-mysql-perl  
libhtml-template-perl  
libnet-daemon-perl libapr1  
mysql-server-5.1 libmysqlclient16  
ssl-cert apache2-mpm-prefork  
mysql-common mysql-client-5.1  

You might also want to take a peek at the Ubuntu Server Guide.

5
31

Install Apache

sudo apt-get install apache2

Install PHP

sudo apt-get install php5 libapache2-mod-php5

As fo 16.04, the number is dropped:

sudo apt-get install php libapache2-mod-php

Install MySQL

sudo apt-get install mysql-server

Install phpMyAdmin

sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

As with the PHP installation, in 16.04, the number is dropped:

sudo apt-get install libapache2-mod-auth-mysql php-mysql phpmyadmin

Combined installation

16.04:

sudo apt-get install apache2 php libapache2-mod-php mysql-server libapache2-mod-auth-mysql php-mysql phpmyadmin

Before 16.04:

sudo apt-get install apache2 php5 libapache2-mod-php5 mysql-server libapache2-mod-auth-mysql php5-mysql phpmyadmin
2
29

The easiest way to install LAMP with PHPMyAdmin is using:

sudo apt-get  install lamp-server^ phpmyadmin 

You don't even need to install taskel. More details can be found here, which gives this:

To access PHPMyAdmin, open terminal & type:

sudo -H gedit /etc/apache2/apache2.conf

Add this line somewhere in that file:

Include /etc/phpmyadmin/apache.conf 

Finally restart Apache using:

/etc/init.d/apache2 restart

or

sudo service apache2 restart
3
  • 5
    I'd recommend APT Tasks too. Note that the caret (^) is not a typo in this answer. See also: Should I use tasksel, tasks in APT or install regular metapackages?
    – gertvdijk
    Jul 21, 2013 at 15:14
  • Whilst the usage of tasksel seems to be "easier", this should be the very easy way to do this task. This answer doesn't need other steps to do the job. Thank you! Feb 28, 2016 at 15:24
  • Your link is dead. This is a good reason why we should always include a brief summary of what is in a link. Dec 25, 2016 at 22:48
15

In Synaptic, click edit and mark by task. Then select LAMP Server and hit apply. Done.

1
  • +1 for providing a slightly more GUI:ish solution, even if it's not necessarily available on a VPS.
    – andol
    Jul 31, 2010 at 6:25
11

I personally always find that installing the MySQL server and then PHPMyAdmin will install all the parts I need

sudo apt-get install mysql-server

(doing this first means it asks for the root account password to be set in advance)

then

sudo apt-get install phpmyadmin

It also gives you all the tools you'll need to administrate your MySQL server once it's installed :)

10

On commandline the simplest way is probably to use tasksel:

sudo tasksel install lamp-server
4

The packages are apache2 and libapache2-mod-php5. php5 has a number of additional modules, you may need some. List them with apt-cache search php5

Try revising your search or

sudo apt-get install apache2 libapache2-mod-php5

Enable php5 with

sudo a2enmod php5

Restart apache

sudo service apache2 restart

The following wiki pages can be very helpful if you are starting with apache.

https://help.ubuntu.com/community/ApacheMySQLPHP

https://help.ubuntu.com/11.10/serverguide/C/httpd.html

Note- This answer was migrated from elsewhere. To add mysql install

sudo apt-get install mysql-server php5-mysql
2

http://www.apachefriends.org/en/xampp-linux.html

It has LAMP as well as phpmyadmin integrated along with perl modules. Installs in /opt/lampp so can be installed/removed easily...

2

PHP7.0 is standard on Ubuntu 16+

Heres the rundown:

1 As Always

 sudo apt-get update

2 Install Apache2

 sudo apt-get install apache2

3 Install mysql-server

 sudo apt-get install mysql-server

4 Install PHP 7.0

 sudo apt-get install php7.0 libapache2-mod-php7.0 php7.0-mysql php7.0-curl php-mbstring php7.0-mbstring php-gettext php7.0-json php-xml
 sudo a2enmod php7.0

5 Install phpmyadmin

 sudo apt-get install mcrypt
 sudo apt-get install phpmyadmin

Note, you'll need to add Include /etc/phpmyadmin/apache.conf to the file you'll open with the following command. (credit)

 sudo gedit /etc/apache2/apache2.conf 

Optional

 sudo a2enmod rewrite
2

My Swiss Army knife command:

sudo apt-get install apache2 mysql-server mysql-client libapache2-mod-auth-mysql php5 php5-mysql libapache2-mod-php5 php5-mcrypt php5-curl php5-cli php5-gd phpmyadmin
1

Open terminal

Ctrl + Alt + T

Type

sudo apt install synaptic

This will install synaptic on your system

Type

sudo synaptic 

to open it.

enter image description here

Go to search box

enter image description here

enter image description here

In the search field type apache and click on Search button

enter image description here

The following field appears

enter image description here

Scroll down to Apache2 and select the box left to it.

enter image description here

Click on apply

enter image description here

Select all dependencies and follow on screen instructions to install.

In a similar way install

php7.0 and mysql-server one by one

During installation of mysql-server system asks for root password. Provide it.

After everything is complete, close synaptic.

Now open your browser and in the address bar type localhost and press Enter

If the following page appears

enter image description here

then Apache2 installation is successfull

In terminal type

apt install vim
cd /var/www/html
vim testphp.php

Press

i

Type

<?php phpinfo(); ?>

Press

Esc : x Enter

Go to your browser and in the address bar type localhost/testphp.php

If the following page appears

enter image description here

Then php7.0 installation is successfull

Go to terminal and type

mysql --version

If you get the following prompt (version numbers for you system may be different):

mysql Ver 14.14 Distrib 5.7.18, for Linux (x86_64) using EditLine wrapper

Then your mysql-server installation is successful.

Type

mysql -u root -p

You will get:

Enter password:

Give the password.

If you get the following prompt

enter image description here

Then you are now successfully able to login

Type

mysql> quit

to logout.

Congratulations, you now have a full working LAMP Stack

Optional:

You can also install phpmyadmin using synaptic. During installation it will ask for default server to use. Select apache2. Follow other on screen instructions.

Then open your browser and in the address bar type localhost/phpmyadmin

The following page appears

enter image description here

In the username field type root and in the password field type the password for root user you have selected during mysql-server installation.

Click on Go button.

The following page appears

enter image description here

Now you have successfully installed phpmyadmin on your system.

0

You can install Bitnami lampstack.(Package containing all necessary sub packages of LAMP).

First of all create an account in bitnami website to download the bitnami-lampstack-5.5.30-1-linux-x64-installer.run file. Then copy the file to your desktop (for convenience ). To provide read and exicution permission, Open terminal (Ctrl + Alt + T). and type

chmod 755 chmod  755 'location of bitnami-lampstack-5.5.30-1-linux-x64-installer.run

Better drag and drop the .run file from your desktop after typing chmod 755, press enter.

Now double click on the .run file. It will guide you through the installation process.

Thank you.

0

I have a script for this task: lampi

Usage:

sudo lampi -i -s -n example.com.local -dr ~/example-site

What does it do:

  1. Install the LAMP stack (-i flag)
  2. Setup and configure apache2, mysql, php, phpmyadmin
  3. Then set up a custom site named example.com.local (-n option)
  4. Set ~/example-site directory as it's document root (-dr option)
  5. Enable SSL (https) for this site (-s flag)

Now, the site can be accessed with http://example.com.local or https://example.com.local

4
  • Unless you post the script here i can't see any use of this answer..
    – heemayl
    Jun 26, 2016 at 18:49
  • @heemayl : seriously? you want me to dump a ~350 line code here... If you are really interested, you should follow through the link and go to the github project page.
    – Jahid
    Jun 26, 2016 at 18:53
  • Can you guarantee that the script won't be removed in the future? Again its link only answer AFAICS. Also you should give the link to github directly, any subtle advertising is highly discouraged..Perhaps you should go through the related meta posts first..
    – heemayl
    Jun 26, 2016 at 18:56
  • @heemayl : I agree on giving a direct link to github but not on it being a link only answer. I have put the code that needs to be run and explained well enough to follow through for anyone...
    – Jahid
    Jun 26, 2016 at 19:00
0

Follow All Steps

sudo apt-get update
sudo apt-get install apache2
sudo apt-get install mysql-server
sudo apt install php7.0-cli
sudo apt-get install phpmyadmin php-mbstring php-gettext
sudo phpenmod mcrypt
sudo phpenmod mbstring
sudo systemctl restart apache2
sudo apt-get update

(Note If phpmyadmin is not working after Than Try this last three line code)

gksu gedit /etc/apache2/apache2.conf
/etc/init.d/apache2 restart
sudo apt-get install gksu^C
0

I have a made an easy to use, simple bash script that installs LAMP stack on your system automatically.

Just run this command in your terminal to use the bash script:

wget --no-cache -O - https://gist.github.com/EmpireWorld/737fbb9f403d4dd66dee1364d866ba7e/raw/install-lamp.sh | bash

Also phpMyAdmin installation included in the gist.

Check out the Gist

0

If you are on Ubuntu 16, it is simple with one command:

sudo apt-get install apache2 mysql-server php libapache2-mod-php php-mcrypt php-mysql phpmyadmin

And just follow the instruction on screen to enter password for mysql, phpmyadmin configuration

You can see more details on my blog http://tvivu.com/install-lamp-stack-ubuntu-16-04/

-7

Try EHCP (easy hosting control panel) ...

ehcp installation on a clean server will do the dirty job for you ...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .