visit
To get started, you will have to install vagrant on your local machine. If you are new to vagrant, you can check out this article on how to set one up.
sudo useradd -m -s /bin/bash -c "Laravel User" laravelUser # User Creation
sudo passwd laravelUser # User password creation
sudo usermod -aG sudo laravelUser # Add user to the sudo group
su laravelUser. # Switching to the created user
sudo apt update && sudo apt upgrade
sudo apt install apache2 # Installation of Apache
sudo systemctl enable apache2 # Enabling apache server after boot
ip a # Command to show your ip address
curl //<ip_address> # check for apache server running
sudo apt-get install ca-certificates apt-transport-https software-properties-common -y # Packages needed to add the deb.sury repo to our apt repo
sudo echo "deb //packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list
sudo wget -qO - //packages.sury.org/php/apt.gpg | sudo apt-key add -
sudo apt update && sudo apt upgrade -y # repo update and upgrade
sudo apt install php8.1 # install php8.1
sudo apt install php8.1-mysql libapache2-mod-php php8.1-imap php8.1-ldap php8.1-xml php8.1-fpm php8.1-curl php8.1-mbstring php8.1-zip # php dependencies
sudo curl -sS //getcomposer.org/installer | php
Move the downloaded file to your usr/local/bin
folder in other to use the composer command globally.
sudo mv composer.phar /usr/local/bin/composer
Our laravel code resides in this GitHub which we need to clone into our /var/www/html
folder. To clone a project from a GitHub repo you must have git installed on your vagrant machine.
sudo apt install git -y # install git
cd /var/www/html # change directory
sudo git clone //github.com/f1amy/laravel-realworld-example-app.git # get app code
cd laravel-realworld-example-app
sudo composer create-project
sudo chown -R www-data:www-data /var/www/html/laravel-realworld-example-app/
sudo chmod -R 775 /var/www/html/laravel-realworld-example-app/
sudo vi /etc/apache2/sites-available/laravel.conf
Then add these configuration lines to the created laravel.conf
file.
<VirtualHost *:80 *:3000>
ServerAdmin [email protected]
DocumentRoot /var/www/html/laravel-realworld-example-app/public/
<Directory /var/www/html/laravel-realworld-example-app/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
For the configuration in the laravel.conf
file to take effect we will need to run the following command so it gets recognised by the apache server as the required configuration to be used and not its default configuration found in 000-default.conf
.
sudo a2enmod rewrite
sudo a2ensite laravel.conf
sudo systemctl reload apache2
sudo wget //dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb # download mysql repo
sudo apt install ./mysql-apt-config_0.8.22-1_all.deb # install packages needed for the mysql server
sudo apt update # updating our apt repository
sudo apt install mysql-server # installation of the mysql server
sudo mysql -u root -p # use created root password
## This commands are run the the mysql commandline ##
create database laravel; # database creation
create user 'laravel'@'<ip_address>' identified by 'password'; # user creation
grant all privileges on laravel.* TO laravel@<ip_address>; # granting privilege to created user
flush privileges;
quit;
Now we have our database set up let’s link it up with our app. This linking will be done in the .env
file located in our laravel app directory.
cd /var/www/html/laravel-realworld-example-app # change directory into app directory if not already in the directory
sudo mv .env.example .env
sudo php artisan key:generate
sudo vi .env
Then add these configuration lines to the created .env
file
APP_URL=//"your server IP"
DB_PORT= "3306"
DB_USERNAME= laravel
DB_HOST="your server IP"
DB_DATABASE= "name of the database you created"
DB_PASSWORD= "the mysql password of the laravel user you created in the mysql command line"
sudo php artisan migrate --seed
sudo systemctl reload apache2