Laravel and PHP Setup from Scratch

Laravel and PHP Setup from Scratch

19 October 2021

To Install the updates you need to have a ubuntu 16.04, 18.04 or 20.04 server with a non-root sudo-enabled user account and a basic firewall. For a complete setup of php and Laravel we need to install the following:

  1. Apache and Installing the firewall
  2. Install Mysql
  3. Install Php
  4. Install Composer

Install Apache and firewall

Install Apache using Ubuntu’s package manager, apt, the commands used to install apache is:

  1. sudo apt update: This command will update all your existing updates that are needed to be updated
  2. sudo apt install apache2: This will install the apache server. You need to accept the permission by typing Y and then Enter. After completely installing apache2, you need to adjust your firewall settings to allow HTTP traffic.
  3. sudo ufw app list: This command will list down all your UFW profiles. Output will be like:
  4. sudo ufw allow in “Apache”: This command will allow traffic on port 80 for the Apache profile.
  5. sudo ufw status: Use this command to verify the status of your HTTP UFW profiles. Output will be like:
  6. To check apache is installed on your system or not, Go to browser and type localhost, Output will be like:

Install Mysql

To Install Mysql on your system use the following command:

  1. sudo apt install mysql-server: This will install the latest version of mysql server on your system.You will be prompted to confirm the installation. Press Y and then Enter.
  2. sudo mysql:  When finished  with the mysql installation, use this command to check whether mysql is installed in your system or not. Output will be like:

Install PHP

Now after installing the server i.e. apache and database as mysql you need to install PHP. You need to install the php packages along with php.

  1. sudo apt install php libapache2-mod-php php-mysql: This command will install the latest version of php in your system along with the apache2 and mysql package for php. Apart from this you can also install the other php packages which will be required in your project. The other php packages includes: Php-gd, php-mbstring, php-fpm, php-zip, php-json, php-common, php-bcmath etc.
  2. php -v: To check the php version installed on your system, you can use this command. Output will be like:

Install Composer

To Install composer you need to download the php dependencies used to install the composer.Run the following command:

  1. sudo apt install curl php-cli php-mbstring git unzip: The php-mbstring package is necessary to provide functions for a library.
  2. php -r “copy(‘’, ‘composer-setup.php’);”: This command will download the composer installer.
  3. Visit the Composer Public Keys page. Copy the Installer Signature (SHA-384). Use this link for composer keys page:
  4. Set the code shell variable:
  5. Compare the hash that you have download with the following command in order to verify:
    php -r "if (hash_file('SHA384', 'composer-setup.php') === '$COMPOSER') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;”

    Once this command is executed you should be able to see the output like below. If you do not see the output like this then redownload the SHA.

  6. sudo php composer-setup.php –install-dir=/usr/local/bin –filename=composer: This command will install the composer. Output will be like:
  7. composer: To test if composer is installed or not on your system use this command: You will see the output like below. If you get this output then your compose is properly installed:

Request a quote