Installing Apache web server on Linux Cloud Servers

2020-01-10 By Aaron 130632 Views linux apache web servers development
8 reviews

The Apache web server is an open-source HTTP server for modern operating systems including Linux and Windows. It is the most popular web server on the Internet. The configuration file of Apache and the installation method vary according to different distributions of Linux. But the default document root is /var/www/html in all distributions.


apachediagram


Debian and Ubuntu distributions refer to Apache as “Apache2” and the configuration file of Apache2 is /etc/apache2/apache2.conf.

CentOS refer to Apache as httpd and configuration file of httpd is /etc/httpd/httpd.conf.


After installation is completed, you can check whether Apache is installed or not by entering a server IP address into your browser’s address bar:

http://your_server_ip


You can see the default Apache web page as shown below if it is successfully installed.

apache1


LayerStack customers can deploy Cloud Servers using Ubuntu 20 with LAMP OS via LayerPanel which already includes Apache, MySQL and PHP services inside the default OS as follows.

LAMPdeploypage1


Also, you may check the following instructions for installing, configuring and testing Apache server on Debian, Ubuntu and CentOS below.




Ubuntu & Debian


Install Apache server

  1. Run the following command to install Apache.

    # apt-get install apache2
    
  2. Run the following command to start the Apache process.

    # /etc/init.d/apache2 start
    
  3. Verify that the service is running by executing the following command.

    # /etc/init.d/apache2 status
    
  4. Run the following command to restart Apache.

    # /etc/init.d/apache2 restart
    


Configure Apache server

The next step is to set up the web server configuration for the domain. The Apache configuration directory is /etc/apache2 and apache2.conf is main Apache configuration file. Each domain needs its own Virtual Host configuration file.

The configuration files use the .conf extension, and need to be saved in the /etc/apache2/sites-available/ directory.

  1. Create a file at /etc/apache2/sites-available/yourdomain.com.conf and add the following lines to it.

    # nano /etc/apache2/sites-available/yourdomain.com.conf
    
    <virtualhost *:80="">  
    ServerAdmin webmaster@localhost  
    ServerName yourdomain.com  
    ServerAlias www.yourdomain.com  
    DocumentRoot /var/www/yourdomain.com  
    ErrorLog ${APACHE_LOG_DIR}/error.log  
    CustomLog ${APACHE_LOG_DIR}/access.log combined  
    </virtualhost>
    
  2. Create a directory for the website and then create index.html file for the website.

    # mkdir /var/www/yourdomain.com
    
  3. Add some content to index.html.

    # vi /var/www/yourdomain.com/index.html
    
  4. Restart Apache service for the above changes to take effect.

    # /etc/init.d/apache2 restart
    or
    # sudo systemctl restart apache2
    
  5. Open any browser and enter the website URL.

    http://yourdomain.com
    


Test Apache server

The Apache web server can be tested by entering the server IP address into the browser’s address bar:

http://your_server_ip

apache4





CentOS 7/8


Install Apache server

  1. Run the following command to install Apache.

    # yum install httpd
    
  2. Apache does not start automatically even after the installation is completed. Run the following command to start the Apache process.

    # systemctl start httpd
    
  3. Verify that the service is running by executing the following command.

    # systemctl status httpd
    
  4. Run the following command to restart Apache.

    # systemctl restart httpd
    


Configure Apache server

The next step is to add and update the VirtualHost for a new domain in Apache. Each domain needs its own configuration file. The configuration files use the .conf extension, and need to be saved in the /etc/httpd/conf.d/ directory.

In the below example, yourdomain.com needs to be replaced with the actual name of the website.

  1. Create a file at /etc/httpd/conf.d/yourdomain.com.conf and add the following lines to it.

    # vi /etc/httpd/conf.d/yourdomain.com.conf
    
    
    <virtualhost *:80="">
    ServerAdmin [email protected]
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com
    DocumentRoot /var/www/html/yourdomain.com/
    ErrorLog /var/log/httpd/yourdomain.com/error.log
    CustomLog /var/log/httpd/yourdomain.com/access.log combined
    </virtualhost>
    
  2. Create a directory for the website and then create index.html file for the website.

    # mkdir /var/www/html/yourdomain.com
    
  3. Add some content to index.html.

    # vi /var/www/html/yourdomain.com/index.html    
    
  4. Restart Apache service for the above changes to take effect.

    # systemctl restart httpd
    
  5. Open any browser and enter the website URL.

    http://yourdomain.com
    


Test Apache server

The Apache web server can be tested by entering the server IP address into the browser’s address bar:

http://your_server_ip

apache2




CentOS 6


Install Apache server

  1. Run the following command to install Apache.

    # yum install httpd
    
  2. Run the following command to start the Apache process.

    # service httpd start
    
  3. Verify that the service is running by executing the following command.

    # service httpd status
    
  4. Run the following command to restart Apache.

    # service httpd restart
    


Configure Apache server

The next step is to set up the web server configuration for the domain. The configuration files name is httpd.conf, and the Apache configuration directory location is /etc/httpd/.

  1. Open the apache configuration file which is /etc/httpd/conf/httpd.conf and add the following lines to the bottom of the file.

    # vi /etc/httpd/conf/httpd.conf
    
    <virtualhost *:80="">
    ServerAdmin [email protected]
    ServerName yourdomain.com
    DocumentRoot /var/www/html/yourdomain.com/
    ErrorLog /var/log/httpd/yourdomain.com/error.log
    CustomLog /var/log/httpd/yourdomain.com/access.log combined
    </virtualhost>
    
  2. Create a directory for the website and then create index.html file for the website.

    # mkdir /var/www/html/yourdomain.com
    
  3. Now add some content to index.html.

    # vi /var/www/html/yourdomain.com/index.html
    
  4. Restart Apache service for the above changes to take effect.

    # service httpd restart
    
  5. Open any browser and enter the website URL.

    http://yourdomain.com
    


Test Apache server

The Apache web server can be tested by entering the server IP address into the browser’s address bar:

http://your_server_ip

apache3


Related Tutorials

What do you think about this article?

Rate this article
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.