There are several ways to install and configure complete production server using Ubuntu I have figure out one of them which is easy to me. So I don’t want to talk more just want to jump to the steps of installation.

I need comments to improve this document if you think this is helpful to you.

Install MariaDB as Database server

You can easily install mariadb by running the commands below:

sudo apt-get update
sudo apt-get install mariadb-server mariadb-client

Don’t forget to secure your sql server

sudo mysql_secure_installation

INSTALL APACHE2

First, run the commands below to install Apache2.

sudo apt-get install apache2

CONFIGURE APACHE2

Next, run the commands below to configure Apache2 basic settings. These are the basics.. and more advanced configurations can be done later.

Change your Apache2 server token to Prod

sudo nano /etc/apache2/conf-enabled/security.conf
# Set to one of:  Full | OS | Minimal | Minor | Major | Prod
# where Full conveys the most information, and Prod the least.
#ServerTokens Minimal
ServerTokens Prod
#ServerTokens Full

Change the highlighted line below and save the file.

Next, configure the default DirectoryIndex directives.

sudo nano /etc/apache2/mods-enabled/dir.conf
<IfModule mod_dir.c>
   DirectoryIndex index.html index.php index.htm
</IfModule>

Then change the highlighted line below and save.

Lets configure virtual host to accept multiple domain in a single server.

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.test.conf

Edit the configuration file you have just copied

sudo nano /etc/apache2/sites-available/example.test.conf 

Change the highlighted lines and save the file.

<VirtualHost *:80>
     ServerAdmin admin@example.com
     DocumentRoot /var/www/html/example/public
     ServerName example.test
     ServerAlias www.example.test

     #configuration for laravel
     <Directory /var/www/html/example/public>
             Options Indexes FollowSymLinks
             AllowOverride All
             Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Enable the newly created configuration

sudo a2ensite example.test.conf

Now restart Apache2

sudo service apache2 restart

INSTALL PHP 7.2

sudo apt-get install php7.2 php7.2-cgi libapache2-mod-php7.2 php7.2-common php-pear php7.2-mbstring

CONFIGURE APACHE2 TO USE PHP

After install PHP and other related scripts, run the commands below to enable Apache2 to use PHP.

sudo a2enconf php7.2-cgi

Enable rewrite module for laravel url support

sudo a2enmod rewrite

Now restart Apache2

sudo service apache2 restart

Add domain to host file

sudo nano /etc/hosts

Add one line

127.0.0.1 example.test
9 thoughts on “How to Install Apache2, PHP, MariaDB ON Ubuntu 18.04 specially for Laravel (5.*)”
  1. Thanks for your Guideline. It will be more helpful if you provide some screenshots of configurations like Virtual hosting and MariaDB configuration.

  2. Thank you so much, sir, for sharing your knowledge with us. It helps me a lot. Waiting for more blog on this kind of topic. Best of luck.

Leave a Reply