How to install Apache into Ubuntu for Laravel

How to install Apache into Ubuntu for Laravel

In this tutorial, I am going to show you how to install and configure the Apache web server inside Ubuntu OS.

Step 1:  Run the following command to install the Apache web server.

sudo apt install apache2

Step 2:  If the “apache2” services are not already enabled, run following command to do so.

sudo systemctl start apache2

Step 3:  To check the apache2 server status run below command 

sudo systemctl status apache2




Apache configuration of Laravel web application:

Default apache web application folder location is /var/www/html. Here we will
delete html folder and create a folder named laravel_app. All of our laravel
default files and folders will keep inside this laravel_app folder. Follow below
commends

cd var/www
rm -r html/

Now open /etc/apache2/sites-enabled/000-default.conf this
file with following commend and change it as below

sudo nano /etc/apache2/sites-enabled/000-default.conf


<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/laravel_app/public
        <Directory /var/www/laravel_app/public>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi
            index.htm index.xhtml index.htm
        </IfModule>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Now restart the Apache server with the following commends
sudo systemctl restart apache2

Now enable the rewrite engine with the following commends
sudo a2enmod rewrite

Now restart again the Apache server with the following commends
sudo systemctl restart apache2

Now inter inside web root and create a new laravel project with composer
with below commends
cd /var/www/
composer create-project laravel/laravel laravel_app "8.5.*" 

Once the installation is completed the change permission to files and folders like below:
sudo chown -R www-data.www-data /var/www/laravel_app
sudo chmod -R 755 /var/www/laravel_app
sudo chmod -R 777 /var/www/laravel_app/storage

Create and configure the Laravel .env file
Now enter inside laravel_app directory and create .env file and put the credintials
for your application like below and save.

cd /var/www/larave_app/
touch .env





Generate an encryption key for your app:

php artisan key:generate
Now browser your ip address and you will see laravel application default page
like below.



Comments

Popular posts from this blog

How to create a droplet inside Digital Ocean