Install and Configure Apache Ubantu Server
1. Overview
Apache is an open source web server that’s available for Linux servers free of charge.
In this tutorial we’ll be going through the steps of setting up an Apache server.
What you’ll learn
How to set up Apache
Some basic Apache configuration
2. Installing Apache
sudo apt update
sudo apt install apache2
After letting the command run, all required packages are installed and we can test it out by typing in our IP address for the web server.
If you see the page above, it means that Apache has been successfully installed on your server! Let’s move on.
How to Host Multiple Websites on Ubuntu VPS ?
An apache2 web server provides robustness and scalability for hosting multiple websites on your Ubuntu VPS. This means you can utilize the power of your VPS hardware without any downtime on your website.
We can configure apache2 to host multiple websites on the same VPS. To achieve this using apache, we create virtual hosts corresponding to each domain or individual site. A virtual host is a way to direct traffic corresponding to an IP to a specific directory on our VPS. This way we will be able to host multiple websites on a single Ubuntu server.
How to setup a virtual host in apache2 ?
Assuming you have apache2 installed on your machine, all you need to do now is to follow the steps outlined in the next section to host multiple websites. For the sake of this tutorial, I will assume that we have to host 2 websites codewithharry.com and programmingwithharry.com on our ubuntu VPS. We will point the domains to the IP address of our droplets. Here is how A record is set up in GoDaddy.
The process is pretty similar for other domain providers.
Let’s set up our virtual hosts now
Step 1 – Creating Directories for individual sites
Let’s create individual directories to store the contents of codewithharry.com and programmingwithharry.com. Execute the commands below to create these directories inside the /var/www folder
sudo mkdir -p /var/www/codewithharry.com/
sudo mkdir -p /var/www/programmingwithharry.com
Step 2 – Transfer the site contents
Transfer the index.html and related files to the individual site directories using Filezilla
Step 3 – Creating the VirtualHost files
Create a new file inside the /etc/apache2/sites-available/ directory by firing the following commands below:
sudo nano /etc/apache2/sites-available/codewithharry.com.conf
Once the codewithharry.com.conf file is created. paste the below contents inside it
ServerName codewithharry.com
ServerAdmin yourPublicEmail@email.com
DocumentRoot /var/www/codewithharry.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Repeat the same for programmingwithharry.com by executing the command below:
vim /etc/apache2/sites-available/programmingwithharry.com.conf
and paste the below contents:
ServerName programmingwithharry.com
ServerAdmin yourPublicEmail@email.com
DocumentRoot /var/www/programmingwithharry.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Step 4 – Enable the VirtualHosts
In order for these virtual host files to function correctly, we need to enable them.
Enter the directory where we have created virtual hosts:
cd /etc/apache2/sites-available/
Execute the following commands to enable the virtual hosts:
sudo a2ensite codewithharry.com.conf
sudo a2ensite programmingwithharry.com.conf
(Root Folder Ownership Change Commnd)
sudo chown -R www-data:www-data
Finally, you will have to restart the apache server:
sudo service apache2 restart
Step 5 – Test the configuration
Test the configuration of these virtual hosts by visiting your domains. You can configure as many virtual hosts as you want for your domains and this technique can help you power many websites on a single VPS.
Install Mariadb Database Server
What is Mariadb Server
MariaDB Server is a popular open-source relational database management system (RDBMS). It is a fork of MySQL, created by the original developers of MySQL after concerns arose when Oracle Corporation acquired MySQL in 2010.
What Does MariaDB Server Do?
MariaDB Server:
Stores data in tables (rows and columns)
Uses SQL (Structured Query Language) to interact with the data
Can manage large volumes of data efficiently
Supports transactions, joins, indexing, and complex queries
Can be used for:
Web applications (e.g. WordPress, Drupal)
Data warehousing
Analytics
Backend data storage for mobile/desktop
Where It’s Used
Linux servers and web hosting platforms
LAMP/LEMP stacks (Linux, Apache/Nginx, MySQL/MariaDB, PHP/Python)
Applications needing reliable, transactional database support
Install Mariadb Server
sudo apt -y install mariadb-server
sudo mysql_secure_installation
1 Install the core PHP package using apt:
sudo apt install php
2 Confirm the PHP release number:
php -v
3 Install the remaining PHP components:
apt install -y php-cli php-fpm
php-json php-intl php-imagick php-pdo php-mysql
php-zip php-gd php-mbstring
php-curl php-xml php-pear php-bcmath
apache2 libapache2-mod-php
OR
sudo apt install php-apcu php-bcmath php-cli php-common php-curl
php-gd php-gmp php-imagick php-intl php-mbstring php-mysql php-zip php-xml
(Cheking PHP Commnd And Basic Apache Commnd)
sudo systemctl | grep -i php
sudo systemctl restart php-fpm
sudo systemctl stop php-fpm
sudo systemctl start php-fpm
sudo systemctl enable apache2
..Start Apache..
sudo service apache2 start
sudo systemctl start apache2
..Stop Apache..
sudo systemctl stop apache2
sudo service apache2 stop
..Restart Apache..
sudo systemctl restart apache2
sudo service apache2 restart
..View Apache Status..
sudo systemctl status apache2
..Reload Apache..
sudo systemctl restart apache2
sudo service apache2 restart
..Check Apache Version..
sudo apache2 -v
..Test Apache Configuration..
sudo apachectl -t
..Site Enable OR Disable Commnd..
sudo a2ensite
sudo a2dissite
..Ownership Permissson..
sudo chown -R www-data:www-data
..SSL Enable..
sudo a2enmod ssl
..Ubantu Firewall Rule..
sudo ufw enable
sudo ufw disable
sudo ufw reload
sudo ufw status
..Allow Port No ..
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 21/tcp
sudo ufw allow 20/tcp
sudo ufw allow 22/tcp
sudo ufw allow mysql
sudo ufw allow in ftp
..Deny Port No..
sudo ufw deny 22
sudo ufw deny 80
sudo ufw deny 443
sudo ufw deny 21
..Removing Firewall Rules..
sudo ufw delete
.....RHEL & Cent-OS Commnd ........
sudo yum install httpd
udo httpd -v
sudo systemctl start httpd
sudo service httpd start
sudo systemctl enable httpd
sudo chkconfig httpd on
sudo systemctl restart httpd
sudo service httpd restart
sudo systemctl status httpd
sudo service httpd status
sudo systemctl reload httpd
sudo service httpd reload
sudo systemctl stop httpd
php.ini File Modify
sudo nano /etc/php/*/apache2/php.ini
memory_limit = 512M
upload_max_filesize = 500M
post_max_size = 500M
max_execution_time = 300
phpmyadmin install
sudo apt install phpmyadmin php-mbstring
php-zip php-gd php-json php-curl
How to install apache server ?
1- sudo apt install apache2
2- sudo systemctl status apache2
3- sudo systemctl restart apache2
4- sudo systemctl reload apache2
5- sudo systemctl start apache2
6- sudo systemctl stop apache2
7- hostname -I
How to firewall enable apache?
1- sudo ufw enable
2- sudo ufw disable
3- sudo ufw allow in "Apache"
4- sudo ufw status
How to install PHP ?
1- sudo apt install php libapache2-mod-php php-mysql
5- php -v
6- (code)