- Creating Your Own Webserver and Hosting A Website from Your Linux Box
- Requirements:
- Install WordPress on Linux
- Install Drupal on Linux
- Install Joomla on Linux
- Setting Up Own Webserver and Hosting A Website in Linux
- What is Apache?
- What is MySQL?
- What is PHP?
- What is Kompozer?
- What is IP?
- How to Setup Virtual Server
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- Creating a Linux service with systemd
- The program
- Turning it into a service
- Going further
- Starting in the right order
- Restarting on exit
- Avoiding the trap: the start limit
- Is that really it?
Creating Your Own Webserver and Hosting A Website from Your Linux Box
Many of you would be a web programmer. Some of you might be owing to a website and would certainly be editing and updating it frequently. While a few having no adequate knowledge of web technologies would still be planning to have one.
Through this article, I will make know how you could develop a working website with very little knowledge and could even host it using your Linux box. Things could be as simple as that.
Requirements:
Linux Box (However, You can use Windows but things surely won’t be as much simple and perfect as it will be on Linux Machine, Debian has been used here for example citing). If you don’t have an operating system installed, or you don’t know how to install a Linux operating system, then here are few guides that show you how to install a Linux operating system.
Apache, PHP, and MySQL (having a prompt knowledge of any other SQL, you can use it but examples in the article will be using MySQL.
Content Management Framework – Drupal with KompoZer, or you can use WordPress or Joomla.(But here I used Drupal as my Content Management System (CMS)).
Install WordPress on Linux
Install Drupal on Linux
Install Joomla on Linux
Setting Up Own Webserver and Hosting A Website in Linux
An Internet Connection with Static IP (Preferred) connected through a modem having a virtual hosting facility (In Reality it is not as much complex as it sounds here).
What is Apache?
Apache is a web server program. It comes installed and configured on most of the Systems. Check if it is installed on your system or not.
Sample Output
Sample Output
From the above output, it is clear that Apache is installed on the box, if it is not in your case you can ‘apt‘ or ‘yum‘ the required package. Once the Apache is installed start it as.
Note: You might have to type ‘httpd‘ and not ‘apache‘ on some server Viz., RHEL. Once the ‘apache2‘ or ‘http‘ aka ‘httpd‘ server is started you could check it in your browser by going to any of the following links.
This link will open into a hosted page which means Apache has been successfully installed and started.
What is MySQL?
MySQL is a database server program. It comes packed with a number of distros. Check if it installed on your system or not and where it is installed.
Sample Output
From the above output, it is clear that MySQL is installed along with the location of binary files. If in case it’s not installed, do ‘apt‘ or ‘yum‘ to install it and start it.
Note: You might have to type “mysqld” in place of mysql, obviously without quotes, in some distro viz., RHEL. Check the status of MySQL, run.
Sample Output
The above output shows that MySQL is running for 11 min 58 sec.
What is PHP?
PHP is the server-side scripting language designed for web development and is commonly used as a general-purpose programming language. You have to just deploy the php script after installing php. As I said above use ‘apt‘ or ‘yum‘ to install the required package for your box.
If you successfully installed the php in your system, you could check if it is working correctly or not by creating a file “info.php” in your ‘/var/www/html‘ or ‘/var/www‘ directory (which is your Apache directory) with the content given below.
Now navigate to your browser and type any of the following link.
Check PHP Info in Debian 10
Which means php is installed and working correctly. Now you can build your website in your Apache directory, however, it is not always a good idea to reinvent a wheel again and again.
For this, there exists the Content Management Framework (CMF), viz., Drupal, Joomla, WordPress. You could download the latest framework from the link provided below and can use any of these frameworks, however, we will be using Drupal in our examples.
Download Drupal from the above link which would be a tar archive. Move the tar archive to your Apache directory ‘/var/www/html‘ or ‘/var/www‘. Extract it to the root of the apache directory. Where ‘x.xx‘ would be version number.
If everything goes OK, again open your browser and navigate to the below links and you will be greeted with.
Drupal Installation
Choose Your language settings.
Language Selection
Checking for requirements and file permission. Provide proper permission to the required files and folders. You may need to create certain files manually, which is not a big deal.
File Permission Checking
Setup Database, the backend process.
Database Configuration
If the Database setting goes perfect profiles are installed automatically.
Database Installation
Installing Drupal
Configuring means setting ‘Site Name‘, ‘Email‘, ‘User Name‘, ‘Password‘, ‘Time Zone‘, etc.
Enter User Details
And if everything goes smoothly, you will get a screen something like this.
Installation Completed
Open Your page by referring to the address http://127.0.0.1.
Welcome to Drupal
What is Kompozer?
Kompozer is a tool that lets you work in GUI for designing a website in html and you can insert a php script anywhere you want. Kompozer made it too easy to create a web page.
well you don’t need to install it on most of the Linux system. Just download, extract, and run Kompozer.
Kompozer
If are creative, kompozer is right there for you.
What is IP?
A Few Words about Internet Protocol (IP) Addresses.
It is generally called loopback IP address or localhost, and it always points to the machine on which it is browsed. All the machines on a network referring to the above address will loop back to its own machine.
Ipconfig/ifconfig: Run this in your terminal to know your machine local address.
Sample Output
Search for the inet addr:192.168.1.2 here 192.168.1.2 is my local IP. Any computer on your LAN including you could refer to your hosted web page using this address.
However a computer outside of your LAN won’t be able to access your web page using this IP address. You will have to ask your Internet service provider to provide you with a static IP (That doesn’t change with time). Once you got your static IP address, the easiest way to find your IP is to type “My IP is” at google and note-down the result.
You won’t be able to access this IP from your own machine nor any other machine on your LAN. However, you can use a proxy server (www.kproxy.com) to access your hosted page using your static IP. But before that, you need to set up a virtual server and your service provider will surely be helpful in this regard.
How to Setup Virtual Server
Hmmm! That’s not difficult at all. First, you need to know the port apache is using, which in most of the case is 80.
the output would be something like:
Now go to your router which generally is http://192.168.1.1 and the user name/password would be admin-admin, however, it could be different in your case based on service provider and area.
Next, go to the Virtual server tab. Fill the port number, service name, and local IP address, inform, and save. Ask for assistance from your ISP.
Setup Virtual Server
Remember You will only be able to access this webserver from your machine, any other machine on your LAN, or a computer on the Internet when your machine is UP and running MySQL and Apache simultaneously.
With great power, comes a big responsibility. And now it’s your responsibility to safeguard your machine. Never give your IP address to any unknown person till you know your ways in and out.
We surely will try to cover the issues related to security and how to safeguard it. Feel free to give your valuable comments and share them with your friends. You know ‘Sharing is Caring‘. Your Positive comment encourages and motivates us.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
Creating a Linux service with systemd
Sep 5, 2017 · 3 min read
While writing web applications, I often need to offload compute-heavy tasks to an asynchronous worker script, schedule tasks for later, or even write a daemon that listens to a socket to communicate with clients directly.
While there might sometimes be better tools for the job — always consider using existing software first, such as a task queue server —writing your own service can give you a level of flexibility you’ll never get when bound by the constraints of third-party software.
The cool thing is th a t it’s fairly easy to create a Linux service: use your favourite programming language to write a long-running program, and turn it into a service using systemd.
The program
Let’s create a small server using PHP. I can see your eyebrows rising, but it works surprisingly well. We’ll listen to UDP port 10000, and return any message received with a ROT13 transformation:
And test it in another terminal:
Cool, it works. Now we want this script to run at all times, be restarted in case of a failure (unexpected exit), and even survive server restarts. That’s where systemd comes into play.
Turning it into a service
Let’s create a file called /etc/systemd/system/rot13.service :
- set your actual username after User=
- set the proper path to your script in ExecStart=
That’s it. We can now start the service:
And automatically get it to start on boot:
Going further
Now that your service (hopefully) works, it may be important to dive a bit deeper into the configuration options, and ensure that it will always work as you expect it to.
Starting in the right order
You may have wondered what the After= directive did. It simply means that your service must be started after the network is ready. If your program expects the MySQL server to be up and running, you should add:
Restarting on exit
By default, systemd does not restart your service if the program exits for whatever reason. This is usually not what you want for a service that must be always available, so we’re instructing it to always restart on exit:
You could also use on-failure to only restart if the exit status is not 0 .
By default, systemd attempts a restart after 100ms. You can specify the number of seconds to wait before attempting a restart, using:
Avoiding the trap: the start limit
I personally fell into this one more than once. By default, when you configure Restart=always as we did, systemd gives up restarting your service if it fails to start more than 5 times within a 10 seconds interval. Forever.
There are two [Unit] configuration options responsible for this:
The RestartSec directive also has an impact on the outcome: if you set it to restart after 3 seconds, then you can never reach 5 failed retries within 10 seconds.
The simple fix that always works is to set StartLimitIntervalSec=0 . This way, systemd will attempt to restart your service forever.
It’s a good idea to set RestartSec to at least 1 second though, to avoid putting too much stress on your server when things start going wrong.
As an alternative, you can leave the default settings, and ask systemd to restart your server if the start limit is reached, using StartLimitAction=reboot .
Is that really it?
That’s all it takes to create a Linux service with systemd: writing a small configuration file that references your long-running program.
Systemd has been the default init system in RHEL/CentOS, Fedora, Ubuntu, Debian and others for several years now, so chances are that your server is ready to host your homebrew services!
Источник