How to Install apache on ubuntu with Laravel

By  ShC    59 - 18 August, 21
how-to-install-apache-on-ubuntu-with-laravel

Share article on social media


Setting up AWS Instance Configuration

  1. Sign in to the AWS account.
  2. Create a new Instance, choose any ubuntu server which has free tier eligible.
  3. Choose the t2.micro instance type.
  4. Configure instance or you can skip this and move forward to add storage.
  5. Choose the volume size according to your usage, recommended is 8GiB and volume type General purpose SSD (gp2).
  6. Choose some tags or leave it as it is.
  7. Configure Security Group - A security group is a set of firewall rules that control the traffic for your instance.
  • Assign a security group - create a new security group if you don't have any assigned.
  • Choosing a security name or default would also work.
  • Add some rules which are so important such as HTTPs, HTTP, and SSH.
  • And choose a source anywhere.
  1. 8. Review Instance settings and enter launch.

Connecting Instance by SSH client

  1. Open an SSH client.
  2. Locate your private key file.
  3. Run this command

Chmod 400 key_name.pem

  1. Connect to your instance using it public IP or DNS

Ssh -i “key_name.pem” [email protected]

Installing Apache2 into the server

  1. For Laravel to work, you’ll need an apache web server.

sudo systemctl status apache2

If there is no Apache service installed then install one.

 

sudo apt install apache2

If it produced an output saying some errors, then run this command.

 

sudo apt-get update

 

Now rerun the previous command.

  1. Now open your ip address in  your browser to check Apache is up and running.

Install PHP

      1. Now we’ve to install PHP

 

sudo apt install php libapache2-mod-php php-mbstring php-xmlrpc php-soap php-gd php-xml php-cli php-zip php-bcmath php-tokenizer php-json php-pear

 

      1. If you want to test if php is installed or not then 

sudo nano /var/www/html/file.php

And run this function phpinfo()

 

 

Now open your browser and run your ip or domain, it will show which version of php installed with.

 

Installing Composer

Composer is a PHP package manager which helps to download the php libraries.

 

Download composer

 

curl -sS https://getcomposer.org/installer | php

 

Now we’ve to make sure the composer needs to be run globally.

 

sudo mv composer.phar /usr/local/bin/composer

 

sudo chmod +x /usr/local/bin/composer

 

Install Laravel

 

As we’ve composer installed, it would be easy to install the laravel

 

Composer create-project --prefer-dist laravel/laravel “App_Name”

 

Deploying a Laravel Application

 

If you’ve your project Git repo

 

      1. cd /var/www/html

      2. sudo git clone “your repo web url”.

      3. set the necessary permissions to ensure the project runs smoothly

sudo chgrp -R www-data /var/www/html/project/

sudo chmod -R 775 /var/www/html/project/storage

      1. It is necessary to create a new virtual host for the project. It can be done easily with the commands below:

cd /etc/apache2/sites-available

sudo nano laravel_project.conf

      1. Run Composer install

      2. Create the new Virtual host. Remember to replace proect.com with your server’s IP address.

ServerName project.com

ServerAdmin [email protected]

DocumentRoot /var/www/html/project/public

AllowOverride All

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

 

      1. Disable the default configuration file of the virtual hosts in apache

sudo a2dissite 000-default.conf

      1. Now enable the new virtual host

sudo a2ensite laravel_project

      1. Restart the Apache service:

sudo systemctl restart apache2

 

Now, check your server ip or url (project.com) tada!