Every time I set-up a new Linux PC, I need to install LAMP and Virtual Hosts etc etc. Definitely, there are a lot of resources about how to do all those stuff but I have to spend a lot of time for finding those. Because, most of the time the site which I bookmarked last time does not found. Therefore, I am creating this post with collection of commands which will help for set-up LAMP and Virtual Host very quickly.

Setup LAMP:

Step 1: Install Apache

sudo apt-get update
sudo apt-get install apache2

When apache2 installation is done, try hitting http://localhost URL in the browser. It should show Apache2 Ubuntu default page.

Step 2: Install MySQL

sudo apt-get install mysql-server

sudo mysql_secure_installation

Answer y for yes, or anything else to continue without enabling.

You’ll be asked to select a level of password validation. Keep in mind that if you enter 2, for the strongest level, you will receive errors when attempting to set any password which does not contain numbers, upper and lowercase letters, and special characters, or which is based on common dictionary words.

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1

For the rest of the questions, you should press Y and hit the Enter key at each prompt.

Step 3: Install PHP

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

To do this, type this command to open the dir.conf file in a text editor with root privileges:

sudo nano /etc/apache2/mods-enabled/dir.conf

It will look like this:

/etc/apache2/mods-enabled/dir.conf

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

We want to move the PHP index file highlighted above to the first position after the DirectoryIndexspecification, like this:

/etc/apache2/mods-enabled/dir.conf

DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

sudo systemctl restart apache2

Step 4: Test PHP Processing on your Web Server

sudo nano /var/www/html/info.php

This will open a blank file. We want to put the following text, which is valid PHP code, inside the file:

info.php

<?php phpinfo();
?>

Now visit: http://your_server_IP_address/info.php

sudo rm /var/www/html/info.php

Now the LAMP installation is done!

Now we need to create some virtual hosts. I have found a script which worked great for me, I have forked the script in my GIT, so here is the script: https://github.com/seeamkhan/virtualhost

Download as Zip,  then extract it.

You will find a directory named ‘virtualhost-master’. Open it and add exe permission for the ‘virtualhost.sh’ file:

$ chmod +x /path/to/virtualhost.sh

Now create virtual host by typing this command:

sudo virtualhost.sh create mysite.com

Now browse http://mysite.com

Install phpMyAdmin:

To get started, we can simply install phpMyAdmin from the default Ubuntu repositories.

sudo apt-get update
sudo apt-get install phpmyadmin php-mbstring php-gettext
  • For the server selection, choose apache2.
  • Select yes when asked whether to use dbconfig-common to set up the database
  • You will be prompted for your database administrator’s password
  • You will then be asked to choose and confirm a password for the phpMyAdmin application itself

The installation process actually adds the phpMyAdmin Apache configuration file into the /etc/apache2/conf-enabled/ directory, where it is automatically read.

The only thing we need to do is explicitly enable the PHP mcrypt and mbstring extensions, which we can do by typing:

sudo phpenmod mcrypt

sudo phpenmod mbstring

Afterwards, you’ll need to restart Apache for your changes to be recognized:

sudo systemctl restart apache2

You can now access the web interface by visiting your server’s domain name or public IP address followed by /phpmyadmin:

https://domain_name_or_IP/phpmyadmin

If you get a 404 error upon visiting http://localhost/phpmyadmin:You will need to configure apache2.conf to work with Phpmyadmin.

$ gksudo gedit /etc/apache2/apache2.conf

Include the following line at the bottom of the file, save and quit.

Include /etc/phpmyadmin/apache.conf

Now Restart the apache server and try again to phpmyadmin:

sudo systemctl restart apache2
Advertisements