How to Install Apache, PHP and MariaDB on Ubuntu 15.04

Saturday, May 16th 2015. | how to

#howto ,#tutorial #VPS – How to Install Apache, PHP and MariaDB on Ubuntu 15.04 – This tutorial explains step by step guide (with pics) about How to Install Apache, PHP and MariaDB on Ubuntu 15.04

lamp-ubuntu-1504-feat

This is a quick and clear version of how to build a working LAMP server to host your websites with it. As a refresh, LAMP stands for Linux, Apache, MySQL and PHP which in this guide we’ll replace it with MariaDB that is faster than traditional MySQL server. As what I can remember, I wrote about LAMP installation on CentOS 7 already but never write the same thing for new Ubuntu version which is now version 15.04 codename Vivid Vervet. So, read on!

Prerequisites

  1. A server / VPS running Ubuntu 15.04 which in this guide I use its x86_64 version from DigitalOcean.
  2. SSH client app like Putty and proper knowledge to use the app.
  3. Some basic knowledge about common unix command.
  4. A cup of tea or coffee as always.

How to Install Apache 2

Step 1 – First thing first, login to your server as root (I assume you knew how to use SSH / Putty). If you are using a droplet from DO like me, you will be asked to change default root password:

Step 2 – Update Ubuntu’s packages to latest version using this command:

apt-get update -y
apt-get upgrade -y

screenshot:

Step 3 – Now here’s the main command to install Apache 2 webserver on Ubuntu 15.04:

apt-get install apache2 -y

You’ll see something similar to this:

How to Install PHP 5

Step 1 – For the first step, you can start installing PHP5 and MySQL PHP modules using this command:

apt-get install php5 php5-mysql -y

the process will be done in few seconds. Pic:

Step 2 – Install other PHP5 modules your app / script may need. There are many modules available and your app/script may need specific ones. However, you can install most common modules many apps usually need it. Here’s the command you can issue:

apt-get install php5-cgi php5-cli php5-common php5-curl php5-dev php5-gd php5-tidy php5-xmlrpc php5-xsl php5-mcrypt php5-imap php5-imagick php5-json php5-intl php5-mcrypt libapache2-mod-php5 -y

screenshot:

install-php-common-modules

Step 3 – That’s it. You can now check which PHP version is installed using this magic command:

php -v

In my example it is PHP 5.6.4

php-version-check

How to Install MariaDB Server

Step 1 – The command to install MariaDB is still the same which is:

apt-get install mariadb-server -y

screenshot:

mariadb-installation-ubuntu

Step 2 – Once the install process is finished, you have to firstly setup your MariaDB install with new root password (default is blank). Issue this command:

/usr/bin/mysql_secure_installation

Simply hit Enter on your keyboard if asked with current password then answer next questions accordingly. Do not forget to create new password and remember it (It is your database password for user root).

Step 3 – Now login to MariaDB to test your newly created root password:

mysql -u root -p

enter your MySQL root password

mariadb-login-root

As you can see from the pic above, it is MariaDB v10.0.17 which is equivalent to MySQL 5.6 & 5.7

Finally, do not forget to restart Apache 2 webserver:

service apache2 restart

that’s it. You can now start hosting your websites / blogs on it which shortly can be done this way:

How to Host A Website on Ubuntu LAMP Server

Step 1 – Create the directory where you put all your site’s files in it (web directory):

mkdir -p /var/www/example.com
mkdir /var/www/example.com/logs

the output simply looks like this:

create-directory

Step 2 – So you have now a directory where you can store all files including scripts and medias of your website. What’s next to do is to make sure Apache will know where to access when a domain name is called. Hence, you have to create a new Virtual Hosts file, a configuration block of Apache for each of your domain / sub-domain.

nano /etc/apache2/sites-available/example.com.conf

The command tells nano editor to create a new file called example.com.conf. Do not forget to change every example.com in this tutorial with your own domain name. Also, if you have no Nano installed yet, you can install it easily with this command:

apt-get install nano -y

Step 3 – Now a blank editor page will show up. Next, copy paste configuration below and adjust few lines accordingly:

<VirtualHost *:80> 
     ServerAdmin webmaster@example.com
     ServerName example.com
     ServerAlias www.example.com
     DocumentRoot /var/www/example.com
     ErrorLog /var/www/example.com/logs/error.log 
     CustomLog /var/www/example.com/logs/access.log combined
     <Directory /var/www/example.com>
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
     </Directory>
</VirtualHost>

here’s an example:

apache-domain-conf-file

Save it and exit Nano editor (Control+O then Control+X).

Step 4 – Reload Apache to be able to read a new configuration file.

service apache2 reload

Step 5 – You can then enable the Virtual Hosts (configuration) file using this command:

a2ensite example.com

a2ensite-command

You can then test it by creating a phpinfo file:

nano /var/www/example.com/info.php

and put this line in there:

<?php phpinfo(); ?>

phpinfo-ubuntu-1504

Save it and exit Nano editor (Control+O then Control+X).

Open up your browser and type:

http://example.com/info.php

then you will now see a bunch of configuration details of your installed PHP.

Step 6 – This is optional but you may need it if you are using WordPress:

chown www-data:www-data -R /var/www/example.com
chmod 755 /var/www/example.com

That’s all. Do not forget to follow me on twitter to get quicker notification of new update.

This post How to Install Apache, PHP and MariaDB on Ubuntu 15.04 is part of ServerMom.

Source link