How to start the server on linux

Ubuntu Linux: Start, Stop, Restart, Reload OpenSSH Server

I need to provide a remote access to my Ubuntu Linux based server. How do I start / stop, OR restart the ssh server under Ubuntu Linux operating system using command line options?

You need to run a script called /etc/init.d/ssh to stop, start, and restart the OpenSSH server. You can also use the service command to control a System V init script. If you are using the latest version of Ubuntu such as 12.04 LTS or 13.04+, you need to use upstart job based commands as listed below.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Ubuntu Linux with sudo command
Est. reading time 3 mintues

Start / Stop / Restart / Reload OpenSSH Server on Ubuntu

Latest version of Ubuntu such as Ubuntu Linux 16.04 LTS or 18.04 LTS and others use the systemctl command to control ssh server on Ubuntu. Older version use the service command. To find out your Ubuntu Linux version, type:
lsb_release -a
cat /etc/*release*
Sample outputs:

Ubuntu Linux: Start OpenSSH Server

Type the following command:
$ sudo /etc/init.d/ssh start
OR
$ sudo service ssh start
For systemd based Ubuntu Linux 16.04/18.04/20.04 LTS or above servers, run:
$ sudo systemctl start ssh

Ubuntu Linux: Stop OpenSSH server

Type the following command:
$ sudo /etc/init.d/ssh stop
OR
$ sudo service ssh stop
Again for systemd based Ubuntu Linux 16.04/18.04/20.04 LTS or above server, enter:
$ sudo systemctl stop ssh

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Ubuntu Linux: Restart OpenSSH server

Type the following command:
$ sudo /etc/init.d/ssh restart
OR
$ sudo service ssh restart
For systemd based Ubuntu Linux 16.04/18.04/20.04 LTS or above server, execute:
$ sudo systemctl restart ssh

systemctl command in action on Ubuntu Linux desktop

Источник

Ubuntu Linux: Start / Restart / Stop Nginx Web Server

Ubuntu Linux restart nginx

Type the following command:
sudo systemctl restart nginx
OR
sudo service nginx restart
OR (older Ubuntu Linux version):
sudo /etc/init.d/nginx restart

Start / Restart / Stop Nginx Commands

The same commands can be used to start / stop / restart the nginx server on a Ubuntu Linux. For example:

One can use the following service command to restart or start or stop Nginx web server on an older version of Ubuntu server:

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

To view status of your Nginx server

Use any one of the following command:
sudo service status nginx
## OR ##
sudo systemctl status nginx
Sample outputs:

A note about reload nginx server

It is also possible to use the following syntax to reload nginx server after you made changes to the config file such as nginx.conf:
sudo nginx -s reload
OR
sudo systemctl reload nginx
OR
sudo service nginx reload

Dealing with error messages on screen

If the nginx server failed to start or stop or restart, check for the syntax error:

Fig.01: Fixing config file errors

nginx: [emerg] getpwnam(“nginxf”) failed in /etc/nginx/nginx.conf:2

To fix this error, edit the file with a text editor such as vi/vim/joe etc:

Update config file. Save and close the file. Test is again:

I also recommend that you check for nginx server log files for more info:

It is also possible to use the systemd systemctl and journalctl commands for details on errors:
$ sudo systemctl status nginx.service
$ sudo journalctl -xe

Conclusion

You learned how to restart, start, stop the Nginx web server on Ubuntu Linux using command line options. See nginx home page here for more info.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

Hi. i just use command: sudo service nginx restart but i get an error
* Restarting nginx nginx [fail]
Please help me how to solve? thanks

Same problem here. Any ideas?

Check for error.log file:
tail -f /var/log/nginx/error.log
or
nginx -t

Hi! This is really useful. Do you have an ansible equivalent of these commands?

Hi this error due to default configuration file issue, please check default file is correctly configured or not. path:check /etc/nginx/sites-available/defalut

Check your hosts file at etc/hosts and reboot(restart) your system and run the below command as root(sudo)

* Restarting nginx nginx [ OK ]
xxx@xxx:

Источник

Ubuntu Linux: Start / Restart / Stop Apache Web Server

H ow do I start, restart, or stop Apache 2.x web server on Ubuntu Linux operating systems using command line options?

You can use any one of the following method to restart / start / stop your Apache (httpd) sever on Ubuntu:

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Shell
Est. reading time 1m
  1. systemctl command – Only works on systemd based Ubuntu like version 16.04 LTS and above.
  2. /etc/init.d/apache2 – A sys v init style script to start / stop / restart the Apache2 service under Debian or Ubuntu Linux.
  3. service command – This command work in most Linux distributions including Debian and Ubuntu.
  4. upstart command – Only works on certain version of Ubuntu.
  5. apache2ctl command – This method should work on all Linux and Unix like operating systems.

Method #1: systemctl command examples

To start Apache 2 on Ubuntu Linux LTS 16.04 LTS or the latest systemd based Ubuntu Linux, type:
$ sudo systemctl start apache2.service
To stop Apache 2 on Ubuntu Linux LTS 16.04 LTS or the latest systemd based Ubuntu Linux, type:
$ sudo systemctl stop apache2.service
To restart Apache 2 on Ubuntu Linux LTS 16.04 LTS or the latest systemd based Ubuntu Linux, type:
$ sudo systemctl restart apache2.service
To status of start/restart/stop operation, enter:
$ journalctl -u apache2
To find out whether Apache 2 running or not, enter:
$ sudo systemctl status apache2.service
Sample session:

Fig.01: Ubuntu Linux systemctl start/stop/restart Apache server (systemd)

Method #2: /etc/init.d/apache2 command examples

You need to login as root user or use the sudo command to control Apache web-server.

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Task: Start Apache 2 Server

# /etc/init.d/apache2 start
or
$ sudo /etc/init.d/apache2 start

Task: Restart Apache 2 Server

# /etc/init.d/apache2 restart
or
$ sudo /etc/init.d/apache2 restart

Task: Stop Apache 2 Server

# /etc/init.d/apache2 stop
or
$ sudo /etc/init.d/apache2 stop

Method #3: service command examples

To restart Apache 2, enter:
$ sudo service apache2 restart
To stop Apache 2, enter:
$ sudo service apache2 stop
To start Apache 2, enter:
$ sudo service apache2 start
To gracefully reload Apache 2, enter:
$ sudo service apache2 reload

Method #4: upstart command examples

The following commands only works with certian version of Ubuntu such as Ubuntu Linux LTS 12.04 and 14.04. To start Apache 2 on Ubuntu, run:
$ sudo start apache2
To stop Apache 2 on Ubuntu, run:
$ sudo stop apache2
To restart Apache 2 on Ubuntu, run:
$ sudo restart apache2
To gracefully reload Apache 2 on Ubuntu, run:
$ sudo restart apache2

Method #5: apache2ctl command examples

apache2ctl is Apache HTTP server control interface command, which can be used to stop or start web server under any Linux distribution or UNIX.
To start Apache 2 on Ubuntu, type:
$ sudo apache2ctl start
To stop Apache 2 on Ubuntu, type:
$ sudo apache2ctl stop
To restart Apache 2 on Ubuntu, type:
$ sudo apache2ctl restart
To gracefully reload Apache 2 on Ubuntu, type:
$ sudo apache2ctl graceful

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

/.bash_profile and add:
alias apache=’sudo /etc/init.d/apache2′

Then it’s just apache start, apache restart, etc.

Thanks for the tip. It worked like a charm.

These cmd line works great.

Here is what works for me:

/etc/rc.d/init.d/httpd (space) start

/etc/rc.d/init.d/httpd (space) stop

nice tutorials,
is there a way to run the apache server as services just like in xampp?
Thanks,
man

wohooooooo. good tutorial . 4 thumbs ^_^

it s not workin for me….
the result is
sudo: /etc/init.d/apache2 commad not found
pls help me guys

sudo /etc/init.d/apache2 do not put that column after sudo

i has stop my apache server, but another connections still establish

unix 3 [ ] STREAM CONNECTED 14940 /tmp/orbit-username/

I’m from Brazil, and your tip helped me a lot, thanks!

sudo service apache2 restart

Thanks mate! nice and easy ( I like the easy ones!)

Thanks for the help.

the amount of times i forget this. sheesh. thanks gzip

Hi! this tutorial is great. things have been ok but mine didnt work at the configuration stage. i restart the server but this d response:
Restarting web server apache2 apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
… waiting apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
help me pls

Your can also use this command
sudo service apache2 restart

Does the “sudo service apache2” apply for the php cli ?

PHP Cli uses a different php.ini .

sudo service apache2 This worked for me, thanks a lot. I had an instance of apache2 running, but it was screwing up apache that was trying to run in xampp.

Nice tutorial. Help a lot 🙂

If you get “command not found” then apache2 may have been installed in a non-standard directory. For instance the bitnami installers put it in ‘stack’, so to find the ctl.sh you may need to use

sudo stack/apache2/scripts/ctl.sh restart

Whether this actually solves your problem or not, I don’t know, but it doesn’t cause the error.

Also when using bitnami the command

sudo stack/ctlscript.sh restart

restarts every service bitnami installed, including apache, in a logical order.

Final comment on this: If you are using one of the XAMPP or other stacks that installs apache as part of a larger package, you want to watch the stack-restart command (like the one I gave above for bitnami) very closely and always get the verbose log.

If you have made some change like blowing away an app directory you aren’t using to fit within tight cloud host requirements, the configuration files generated for apache may be wrong/fragile and may cause apache to just not start with no indication why. However the stack-restart command for the stack you are using will generally report that problem. For instance in bitnami the restart is fragile – unless every single line of the configuration files it is relying on is up to date, you’ll have to go edit them yourself

sudo nano /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf

PHP is however more robust and usually only generates a warning if it doesn’t find some app configuration include. The worst you will see from PHP is a line like this

WARNING: Nothing matches the include pattern ‘/opt/bitnami/apps/limesurvey/conf/php-fpm/pool.conf’ from /opt/bitnami/php/etc/php-fpm.conf at line 17.

so you can sudo nano that .conf file also, but it might be better to let all future shell users have at least a chance to notice that you blew away an app package and then manually reconfigured. I would leave the warnings in place myself. Your mileage may vary.

why we have to restart apache server in ubantu

## How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 14.04

$ sudo apt-get update
$ sudo apt-get install apache2

Источник

Читайте также:  Считыватель отпечатков пальцев hp probook windows 10
Оцените статью