Set up an Ubuntu 14.04 64-bit VPS Server using LAMP (Linux Apache, MySQL, and PHP)
Overview
What is a LAMP server?
Essentially, a server equipped with Apache, MySQL, and PHP forms the backbone of websites and web applications for public access. It operates in the background of every website visit, every mobile app opened, every interaction on your laptop, desktop, and even your TV.
This server serves data utilized by your mobile applications, processes information displayed in your desktop applications, and in summary, a web server with LAMP installed can be considered a fundamental component of the internet.
This guide will walk you through the installation of a LAMP server, providing tutorials on configuration and demonstrating how you can leverage this technology for various purposes.
Requirements
This tutorial assumes the following:
1. You have an Ubuntu 14.04 64-bit VPS server from blendhosting.com.
2. You have successfully logged in to your VPS server using an SSH terminal.
3. You possess basic knowledge of Ubuntu or Linux commands.
Apache Installation Guide
The Apache web server is an open-source software that processes information requested by the user. When a user requests a webpage, it searches for the file and displays the webpage to the user. It also manages communication between your computer and the server.
To install Apache, you can begin by executing the following commands. Keep in mind that if you do not have administration rights or root privileges on the server, you will need to prepend sudo to the command.
sudo apt-get update
sudo apt-get install apache2
To confirm that Apache is installed correctly, open your web browser and enter the IP address of your server. You should observe the default Apache webpage as shown below:
Understanding the IP address of your server
If you don’t know the IP address of your server, you can find it by executing the following command:
ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
Executing the command will display the IP address of your VPS server.
Mysql Installation Guide
After confirming that Apache is running successfully, we can proceed with the installation of our MySQL server.
MySQL server plays a crucial role in storing valuable information from your website using a database. This database is organized into tables, each containing rows and columns of data that can be retrieved by our webpage for display to users or for use by an application.
To initiate the MySQL server installation, execute the following commands:
sudo apt-get install mysql-server php5-mysql
Once again, assuming the user does not have root privileges, I’ve added `sudo` at the beginning of the command.
Throughout the installation, the server will prompt you to select and confirm your administrator or root password. This root password will be crucial when you want to add or make changes to the database and MySQL server configuration.
After the installation is complete, you’ll need to create a database structure that will be used to store MySQL server information.
sudo mysql_install_db
After the installation, execute the following script to secure your MySQL server installation. This step is crucial to lock down access to the server and prevent potential security and performance issues.
sudo mysql_secure_installation
During the configuration, you will be prompted for the root password that you entered earlier. It will also ask if you want to change this password or not. If you are content with your password, you can skip this step by simply pressing ENTER for the remaining questions.
Now that your database and Apache server are already up and running, we can proceed with installing PHP.
PHP Installation Guide
PHP is software that processes dynamic content for your webpage. Depending on your needs, it can communicate with our MySQL server to provide real-time, dynamic results and data to our users.
PHP is commonly used to provide information on user accounts, traffic updates, location information, and more. To install PHP, execute the following commands:
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
This will install the basic requirements for running PHP on your webserver. We will test the configuration later on.
In our current configuration, when a user requests a webpage, it directs them to the `index.html` file. However, we would like to provide our users with a PHP page. To achieve this, we will edit the Apache configuration file to include `index.php`.
Type the following command to open our `dir.conf`:
sudo nano /etc/apache2/mods-enabled/dir.conf
Afterward, locate the following line:
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
We’re going to reposition index.php so Apache will search for it first:
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
After making the changes, save the file by pressing `CTRL+X`, confirm the save by pressing `Y`, and then hit Enter.
Next, restart Apache to apply the new configuration.
sudo service apache2 restart
Adding additional PHP components
To enhance the capabilities of PHP further, you can optionally install some modules. Adding modules may be necessary for your application or webpage.
To check for available modules, type the following commands:
apt-cache search php5-
The available modules will be displayed to you as shown below:
php5-dev - Files for PHP5 module development
php5-gd - GD module for php5
php5-common - Common files for packages built from the php5 source
...
To obtain information about what a module does, you can use the following command with the module’s name. Alternatively, you can also search for information on the internet.
apt-cache show php5-gd
To install a module, you can execute the following command:
sudo apt-get install php5-gd
Or you can install multiple modules by including their names in the existing command.
sudo apt-get install php5-gd php5-common
PHP testing
To verify if our PHP installation is working correctly and that all installed modules are properly configured, we need to create a PHP file containing our PHP information.
To do this, create a file in our `/var/www/html` directory named `info.php`.
sudo nano /var/www/html/info.php
Open the file and insert the following PHP script inside:
Save and close the file. Afterward, open your web browser and enter your server’s IP address followed by the filename we just created (`info.php`). This should display the PHP information page, confirming that PHP is installed and properly configured on your server.
http://your_server_IP/info.php
You should encounter a page similar to the one below. Keep in mind that the data in your info page may differ from mine, as some modules I have may not be installed on your server. The crucial aspect at this time is that your page is correctly processing PHP information.
You can refer to this information later to assess the health of your server and understand which modules you may need to install to get your application or webpage up and running.
Now that your LAMP server on Ubuntu 14.04 64-bit is fully set up and configured, you can proceed to install the applications you need. Whether it’s WordPress or creating dynamic PHP files for your users, the server is ready for your requirements.
If you have any questions or suggestions, feel free to comment below.