This is part 3 in “How to set up your own cloud based web server”
3. Install the LAMP stack ← You are here !
OK, so far we are making great progress. We have created a server and completed some basic setup tasks.
To make this magic we are going to use an open source software stack (group of technologies which work together) called LAMP, which stands for:
- Linux: the operating system .
- Apache: the web server software .
- MySQL: the databse .
- PHP: to serve dynamic content.
This will not be an in-depth lesson on each of the above topics, but more on how to get them working together in order to serve our website.
Lets get started:
Once we have logged in to our server we can start issuing some commands, first lets update our server, and then install Apache:
sudo apt-get updatesudo apt-get install apache2
You will see something similar to:
Enter yes, hit return, and Apache will install.
You can at this stage actually verify if Apache has been installed correctly by visiting the IP address of your server, you should see:
A quick way to display your public IP is:
Lets get started:
sudo apt-get install mysql-server
You will see:
You can reply with yes, then hit return. Soon after the packages have been pulled in you will be asked for a MySQL admin password. Enter a password, then confirm:
MySQL will continue through the installer.
Once, it has completed, we will need to create a database directory as follows:
NOTE: on versions 5.7.6 and above, there is no need for this command. If you get an error similar to:
[WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
[ERROR] The data directory needs to be specified.
Then you can run:
In Ubuntu 16.04, PHP is installed by default. However, if it is not/has been removed/has been deleted, you may install it via:
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
Now, we just need to edit one file to ensure that our web server, Apache in this case (NginX is another we will discuss in a future post), will look for .php files by default.
To edit files inside a linux server, there are a couple of options, namely VI/VIM which is a great choice for the more experienced as it take a while to master, or even become productive in ! Today, we shall use Nano, it is beginner friendly and suits our needs just fine out of the box.
So, we are going to edit a file called dir.conf :
sudo nano /etc/apache2/mods-enabled/dir.conf
The file contents will look like:
This is dir.conf opened in the Nano text-editor. What we need to do is to edit the second line so that index.php is first in the list, and reads as follows:
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
To save a file in Nano, press CTRL + X , then at the bottom of the editor you will be asked to confirm the save, type Y :
Then you will be asked to confirm/edit the file name, hit return:
Great, you’ve just edited a file in a server, with the command line and Nano — bad ass!
Now, all that is left to do is to restart the Apache service to make all our changes take effect:
sudo service apache2 restart
… and that is that ! Great progress! We know have the LAMP stack installed and setup, ready to serve web pages.
Next up, we going to briefly look at how to go about connecting your newly purchased domain to your droplet via DigitalOcean’s DNS section so that your visitors can access your site without the IP address !
Lets do this …