How to Activate Varwwwhtml Apache2 Again
Every so ofttimes I find it practiced to take a step back and go through the nuts. It not only helps to ground me as a tech writer, but it helps a lot of people who are but learning the ropes of whatever piece of engineering science I'm talking about.
This time information technology's all about the Apache spider web server, a piece of software that's been effectually for decades, happily serving upwardly small and big websites without fail. Apache works seamlessly with MySQL, PHP, and a host of other packages, so you tin can serve up unproblematic static or incredibly dynamic websites.
How practice you lot install and configure the server? Where practice yous identify files?
Permit's walk through this, one stride at a fourth dimension. I'll exist demonstrating on Ubuntu Server 20.04.
But first, a scrap more than data.
SEE: Phone interview cheat canvas: Software programmer (TechRepublic Premium)
The difference between Apache on Ubuntu and Red Hat-based distributions
The reason why I accept to specify what Linux distribution I'one thousand using is because Ubuntu- and Red Chapeau-based variants Apache differently–from installation to configuration. For example, on Cherry-red Hat-based distributions, Apache is installed via the httpd package, whereas on Ubuntu-based distributions, the apache2 package will do the trick. Another difference is where and how Apache is configured. In Red Hat-based distributions, much of your Apache configuration will happen in /etc/httpd/conf/httpd.conf. In Ubuntu-based distributions, the configurations are in /etc/apache2/apache2.conf and /etc/apache2/sites-available/. There are nonetheless more differences to be had, only you become the idea.
How to install Apache on Ubuntu Server
In that location are a number of means you can install Apache on Ubuntu. If you simply want the basic server software, you lot tin can open a terminal and issue the command:
sudo apt-get install apache2 -y
However, if y'all want a full-diddled Linux Apache MySQL PHP (LAMP) stack, you'd event the control:
sudo apt-get install lamp-server^
In one case you lot run either of those commands, you'll have Apache upwards and running. You'll likewise want to brand certain to enable Apache to commencement upon a server reboot (or boot). To do that, issue the command:
sudo systemctl enable apache2
Y'all can verify your installation past opening a web browser and pointing it to http://SERVER_IP (where SERVER_IP is the IP address of the server hosting Apache). You should exist greeted by the Apache Welcome Folio (Figure A).
Figure A
What is that page Apache is serving upward? If you look in /var/world wide web/html, y'all'll find the index.html file–allow's modify it.
Back at the terminal window, rename that index.html file with the control:
sudo mv /var/www/html/index.html /var/world wide web/html/alphabetize.html.bak
Now, allow'south create a new welcome file. Issue the command:
sudo nano /var/www/html/index.html
In that file, paste the post-obit:
How-do-you-do, TechRepublic!
How are y'all doing?
Save and close the file. Reload the spider web page in your browser and y'all should see the change (Figure B).
Effigy B
How to create a site for Apache
What we're going to do now is create a virtual host for Apache to serve upwardly. A virtual host is a fancy proper name for a website that'south served by Apache. Y'all tin can have numerous virtual hosts served upwardly on a unmarried Apache server. In fact, you lot are just limited to the ability of your hosting server and the bandwidth of your network.
So let'due south create a virtual host called test.
The first matter nosotros're going to practice is create a directory to firm test with the command:
sudo mkdir -p /var/www/html/exam
Side by side, we'll give the new directory the proper buying with the command:
sudo chown -R $USER:$USER /var/www/html/exam
Finally, nosotros'll grant the proper permissions with the control:
sudo chmod -R 755 /var/world wide web/html/examination
Copy our new alphabetize.html file into the test directory with the control:
sudo cp /var/www/html/index.html /var/www/html/exam/
Now we take to create the virtual host configuration and so Apache knows where exam is. This will exist housed in /etc/apache/sites-available. To do that nosotros'll create the test.conf file with the command:
sudo nano /etc/apache2/sites-bachelor/test.conf
In that file paste the post-obit:
ServerAdmin admin@case.com
ServerName instance.com
ServerAlias www.example.com
DocumentRoot /var/world wide web/html/test
ErrorLog ${APACHE_LOG_DIR}/fault.log
CustomLog ${APACHE_LOG_DIR}/admission.log combined
The most of import line above begins with DocumentRoot, as that instructs Apache where the files for the virtual host will be found. Save and shut that file.
At this signal, we've created the directory to house the files, given it the proper ownership and permissions, and created a configuration for the virtual host. However, Apache is still not enlightened of the new site. Why? Because the configuration file lives in sites-available. What nosotros have to practice is create a link from that configuration into the /etc/apache2/sites-enabled directory. Only those configurations institute in sites-enabled are active on the Apache server.
On not-Ubuntu servers, yous accept to utilise the ln (for link) command to do this. Withal, on Ubuntu there'due south a handy utility that will create that site for you. Said utility is a2ensite. If we run the command:
sudo a2ensite test.conf
Our test virtual host will and then be enabled.
After that command succeeds, you and then must reload Apache (which will only reload the configuration files, not restart the web server) with the control:
sudo systemctl reload apache2
At present, if you point your browser to http://SERVER_IP/test (where SERVER_IP is the IP address of the server) you should run into the aforementioned How-do-you-do, TechRepublic welcome equally y'all did with the basic index.html file, only it's being served from our newly-created virtual host.
You've just installed the Apache spider web server, edited the index.html file, and then created your very own virtual host. You tin take this simple how-to and use it as a basis for spinning up all the Apache-served websites you demand.
Subscribe to TechRepublic'southward How To Make Tech Work on YouTube for all the latest tech communication for business pros from Jack Wallen.
Source: https://www.techrepublic.com/article/how-to-use-the-apache-web-server-to-install-and-configure-a-website/
0 Response to "How to Activate Varwwwhtml Apache2 Again"
Post a Comment