Skip to main content

Create an apache virtual host in ubuntu 16.04

Let's create apache virtual host on your local computer.
Open your terminal and run following codes.

First go to your project folder using cd command
cd Projects/CodeIgniter/Login/
To get file path enter
pwd
This will give you file path of Login folder
/home/shyamali/Projects/CodeIgniter/Login

Now we can create a virtual host.

Step 1 : You have to create a virtual host
sudo vim /etc/apache2/sites-available/local.login.com.conf

This will open an empty file
Then paste following code inside the that file

<virtualHost *:80>
  # Admin email, Server Name (domain name) and any aliases
  ServerAdmin webmaster@domain1.com
  ServerName local.codeigniter.com
  ServerAlias www.local.codeigniter.com
  DirectoryIndex index.php
  DocumentRoot /home/shyamali/Projects/CodeIgniter/Login
  <Directory /home/shyamali/Projects/CodeIgniter/Login>
               # Require all granted
                # Options FollowSymLinks
                Options Indexes FollowSymLinks Includes ExecCGI
                AllowOverride All
                Require all granted
                #Order deny,allow
                #Allow from all
  </Directory>
  ErrorLog /var/log/apache2/error-mydomainname.com.log
  CustomLog /var/log/apache2/access-mydomainname.com.log combined
</VirtualHost>
Make sure to change ServerName, ServerAlias, DocumentRoot, Directory path according to your specifications. 

Step 2 : Enable site
sudo a2ensite local.codeigniter.com

Then it will display following message
Enabling site local.codeigniter.com.
To activate the new configuration, you need to run:
service apache2 reload

Step 3 : Then you have to restart apache
sudo service apache2 reload

Step 4 : Then you have to navigate your local site.
open hosts file
sudo vim /etc/hosts
Then enter your site name and local IP address and save it
127.0.0.2       www.local.codeigniter.com

Now you are all set up for your virtual host
type http://www.local.codeigniter.com/ in your browser and you will see codeigniter default page.


Congratulations !

Comments

Popular posts from this blog

Start coding with CodeIgniter using PhpStorm on Ubuntu 16.04

CodeIgniter uses MVC architecture.  Model  Stores php files which are communicate with the database. Get, store, update informations to the database are handled by php files in model. Login, registration, etc...  View  Stores php files which display informations in the browser. Tables, images, descriptions, etc..  Controller   Stores php files which make the connection between model and the view. When files in the model get information, the controller will call the relevant file in the view and display them to the user. Let's start coding with CodeIgniter framework.  Step 1 : Download codeIgniter framework from  CodeIgniter . Step 2 : Copy files to a folder called Login (in my case the folder path /home/shyamali/Projects/CodeIgniter/Login) Step 3 : Then open Login folder by using PhpStorm. If you have not yet installed PhpStrom  How to install PhpStrom in Ubuntu 16.04 . Step 4 :  If you have not yet in...

Merge Bootstrap to your current codeIgniter project in PhpStorm on ubuntu 16.04

I will be leading you how to merge bootstrap into your codeIgniter project. There are two ways that you can bootstrap in your project. Method 1 -  Load bootstrap online   In this method you have to give links of following libraries inside the head tag in view pages. //css <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> //jquery <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> //javascript <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> Method 2 -  Download and load bootstrap  You can download Bootstrap and merge it with your project. Step 1 : Download Lastest Bootstrap  and Jquery  into your computer. Step 2 : Create a folder called asserts in your codeIgniter project folder. Step 3 : Extract it and copy css, fonts, js folders to assets folder. Step 4 : Copy jquery.js f...

How to Read and Write files using CodeIgniter - PHP

How to read a file This post will explain how to read and write files using php. When reading a file from php, we can let the user select the file or we can give a specific file manually. Here is a explanation for reading and writing a csv file. if (!empty($_POST) && $_POST['file_upload']) {     $target_file = '/tmp/'  . basename($_FILES["file_name"]["name"]);     $fileType = pathinfo($target_file,PATHINFO_EXTENSION);     if($fileType =='csv'){ // read the csv file. Discussed below }else{     $this->session->set_flashdata('error_message', "Please upload valid file type"); } Here we have check if the is a post(that means submit button has been pressed). Then we have uploaded the file to a folder called tmp. Then we check the file format(whether it is csv or not).   Then we set some config $config['upload_path'] = '/tmp'; $config['allowed_types'] = '*'; $config[...