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:
- Apache and Installing the firewall
- Install Mysql
- Install Php
- Install Composer
Install Apache and firewall
Install Apache using Ubuntu’s package manager, apt, the commands used to install apache is:
- sudo apt update: This command will update all your existing updates that are needed to be updated
- 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.
- sudo ufw app list: This command will list down all your UFW profiles. Output will be like:
- sudo ufw allow in “Apache”: This command will allow traffic on port 80 for the Apache profile.
- sudo ufw status: Use this command to verify the status of your HTTP UFW profiles. Output will be like:
- 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:
- 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.
- 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.
- 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.
- 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:
- sudo apt install curl php-cli php-mbstring git unzip: The php-mbstring package is necessary to provide functions for a library.
- php -r “copy(‘https://getcomposer.org/installer’, ‘composer-setup.php’);”: This command will download the composer installer.
- Visit the Composer Public Keys page. Copy the Installer Signature (SHA-384). Use this link for composer keys page:
https://composer.github.io/pubkeys.html - Set the code shell variable:
COMPOSER=48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5
- 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.
- sudo php composer-setup.php –install-dir=/usr/local/bin –filename=composer: This command will install the composer. Output will be like:
- 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: