lamp-ubuntuLAMP is the most famous web service solution stack. LAMP means Linux, Apache HTTP Server, MySQL or MariaDB database engines, and the PHP language. All these components are open-soucre software and totally free.

In this tutorial, I’ll show you how to install this most famous production environment on Ubuntu. Firstly, I suppose you have deployed Ubuntu on your VPS and connect to your server as root. By entering sudo su,  you can run commands as root user. In this how-to, I’ll use the nano command for editing documents. You can uses vim also.

1. Update the system

As always, make sure your Ubuntu is up-to-date before install any modules.

apt-get update
apt-get upgrade

2. Creating a Firewall

Now it’s time to set up a firewall on your server to block unwanted inbound traffic. This step helps you keep away from intruders. If it makes any trouble in your future usage, you can modify or disable the firewall later. Here’s how to create a firewall on your Linode.

Create a file to hold your firewall rules by entering the following command

nano /etc/iptables.firewall.rules

Then copy and paste the rules shown below in to the iptables.firewall.rules

*filter

#  Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 -j REJECT

#  Accept all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#  Allow all outbound traffic - you can modify this to only allow certain traffic
-A OUTPUT -j ACCEPT

#  Allow HTTP and HTTPS connections from anywhere (the normal ports for websites and SSL).
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT

#  Allow SSH connections
#
#  The -dport number should be the same port number you set in sshd_config
#
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT

#  Allow ping
-A INPUT -p icmp --icmp-type echo-request -j ACCEPT

#  Log iptables denied calls
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7

#  Drop all other inbound - default deny unless explicitly allowed policy
-A INPUT -j DROP
-A FORWARD -j DROP

COMMIT

Save the changes by pressing Control-X, and then Y. Then you need to ensure that the firewall rules are activated every time you restart your server by creating a new script with the following command:

#!/bin/sh
/sbin/iptables-restore < /etc/iptables.firewall.rules

Set the script’s permissions by entering the following command:

sudo chmod +x /etc/network/if-pre-up.d/firewall

3.Installing Apache

Install Apache by entering the following command:

apt-get install apache2

4. Installing MySQL

It time to install a database for your websites. We usually uses MySQL, the most popular database platform. Install MySQL by entering the following command. You will be prompted to set a password for the MySQL root user.

apt-get install mysql-server

Then secure MySQL by  entering the following command to open mysql_secure_installation utility. Follow the instructions to finish the security process.

sudo mysql_secure_installation

5.Installing PHP

PHP is the basic scripting language allows you to build dynamic webpages. WordPress is written PHP. To host a WordPress site, you must first install the base PHP packages and a couple of modules.

apt-get install php5 php-pear php5-mysql

Then restart Apache to load the PHP module:

service apache2 restart

6. Test your VPS

You’ve installed Apache, MySQL, and PHP. It’s time to test your installation before you add the DNS records and upload a website to your VPS.

First, enter your WordPress VPS hosting IP address in the web browser. You will see a Apache2 Ubuntu Default Page shows that the Apache works.

Second, create a page to get PHP installation information.

nano /var/www/html/info.php

Then copy the following function to the info.php file just created.
<?php phpinfo(); ?>

Open http://yourIP/info.php in a web browser. You will see all PHP default settings.

Leave a Reply

Your email address will not be published. Required fields are marked *

/