How to restart apache server through cygwin and ssh - apache

The scenario is this: I have an Apache web server installed on a Windows 7 machine. The same machine has cygwin installed, and cygwin is configured with ssh. This allows me to ssh into cygwin remotely, and then, through cygwin, I can access other files on this computer (even those not in cygdrive).
My question: How can I restart the web server through cygwin if I am accessing it remotely through ssh? Is it possible? Thanks

If your service is called Apache, then like this:
ssh machine "net stop Apache; net start Apache"
Sometimes it is called Apache2 or httpd, depending on your distro.

In linux is
$ sudo service apache2 restart
or
$ sudo /etc/init.d/apache2 restart
See: http://httpd.apache.org/docs/2.2/platform/windows.html#winsvc
and http://httpd.apache.org/docs/2.2/platform/windows.html#wincons

You can try this one
$ service httpd restart
or
$ /etc/init.d/httpd restart

Related

Installed lamp on ubuntu server on an ec2 amazon instance, still can't access server through browser with apache running. Why?

I started an instance on amazon ec2, ami is ubuntu 14.04. I followed the steps on https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html exactly up until "Transferring Files to Your Linux Instance Using the PuTTY Secure Copy Client" Since I don't need to put files on there just yet. Then I followed the following: https://help.ubuntu.com/community/ApacheMySQLPHP.
"To install the default LAMP stack in Ubuntu 10.04 and above
First refresh your package index...
$ sudo apt-get update
... and then install the LAMP stack:
$ sudo apt-get install lamp-server^
Mind the caret (^) at the end. "
After that I tried
sudo /etc/init.d/apache2 restart
After which ubuntu said: httpd (pid 5549) already running
Yet when I try to browse with chrome to the public ip which shows in the amazon console I get
This webpage is not available
ERR_CONNECTION_TIMED_OUT
In my browser. What am I doing wrong?
check your security group settings. What are the inbound rules?
You need to add the IP(s) from where you are opening the web browser in the inbound rules. Also, check whether you are using private IP or public IP on the browser. You need to use public IP.

How can I connect to a Google Compute Engine virtual server with a GUI?

I am testing a Google Compute Engine, and I created a VM with Ubuntu OS. When I connect to it, by clicking this Connect SSH button, it opens a console window.
Is that the connection you get?
How do I open a real screen with a GUI on it? I don't want the console.
Much better solution from Google themselves:
https://medium.com/google-cloud/linux-gui-on-the-google-cloud-platform-800719ab27c5
You need to forward the X11 session from the VM to your local machine. This has been covered in the Unix and Linux stack site before:
https://unix.stackexchange.com/questions/12755/how-to-forward-x-over-ssh-from-ubuntu-machine
Since you are connecting to a server that is expected to run compute tasks there may well be no X11 server installed on it. You may need to install X11 and similar. You can do that by following the instructions here:
https://help.ubuntu.com/community/ServerGUI
Since I have needed to do this recently, I am going to briefly write up the required changes here:
Configure the Server
$ sudo vim /etc/ssh/sshd_config
Ensure that X11Forwarding yes is present. Restart the ssh daemon if you change the settings:
$ sudo /etc/init.d/sshd restart
Configure the Client
$ vim ~/.ssh/config
Ensure that ForwardX11 yes is present for the host. For example:
Host example.com
ForwardX11 yes
Forwarding X11
$ ssh -X -C example.com
...
$ gedit example.txt
Trusted X11 Forwarding
http://dailypackage.fedorabook.com/index.php?/archives/48-Wednesday-Why-Trusted-and-Untrusted-X11-Forwarding-with-SSH.html
You may wish to enable trusted forwarding if applications have trouble with untrusted forwarding.
You can enable this permanently by using ForwardX11Trusted yes in the ~/.ssh/config file.
You can enable this for a single connection by using the -Y argument in place of the -X argument.
These instructions are for setting up Ubuntu 16.04 LTS with LXDE (I use SSH port forwarding instead of opening port 5901 in the VM instance firewall)
1. Build a new Ubuntu VM instance using the GCP Console
2. connect to your instance using google cloud shell
gcloud compute --project "project_name" ssh --zone "project_zone" "instance_name"
3. install the necessary packages
sudo apt update && sudo apt upgrade
sudo apt-get install xorg lxde vnc4server
4. setup vncserver (you will be asked to provide a password for the vncserver)
vncserver
sudo echo "lxpanel & /usr/bin/lxsession -s LXDE &" >> ~/.vnc/xstartup
6. Reboot your instance (this returns you to the Google cloud shell prompt)
sudo reboot
7. Use the google cloud shell download file facility to download the auto-generated private key stored at $HOME/.ssh/google_compute_engine and save it in your local machine*****
cloudshell download-files $HOME/.ssh/google_compute_engine
8. From your local machine SSH to your VM instance (forwarding port 5901) using your private key (downloaded at step 7)
ssh -L 5901:localhost:5901 -i "google_compute_engine" username#instance_external_ip -v -4
9. Run the vncserver in your VM instance
vncserver -geometry 1280x800
10. In your local machine's Remote Desktop Client (e.g. Remmina) set Server to localhost:5901 and Protocol to VNC
Note 1: to check if the vncserver is working ok use:
netstat -na | grep '[:.]5901'
tail -f /home/user_id/.vnc/instance-1:1.log
Note 2: to restart the vncserver use:
sudo vncserver -kill :1 && vncserver
***** When first connected via the Google cloud shell the public and private keys are auto-generated and stored in the cloud shell instance at $HOME/.ssh/
ls $HOME/.ssh/
google_compute_engine google_compute_engine.pub google_compute_known_hosts
The public key should be added to the home/*user_id*/.ssh/authorized_keys
in the VM instance (this is done automatically when you first SHH to the VM instance from the google cloud shell, i.e. in step 2)
you can confirm this in the instance metadata
Chrome Remote Desktop allows you to remotely access applications with a graphical user interface from a local computer or mobile device. For this approach, you don't need to open firewall ports, and you use your Google Account for authentication and authorization.
Check out this google tutorial to use it with Compute Engine : https://cloud.google.com/solutions/chrome-desktop-remote-on-compute-engine

Apache commands with 2nd instance on Mac OS X

I have a Mac OS X 10.9/Mavericks Mac which I have just installed FileMaker Server v13. The FileMaker Server installer creates its own instance of the Apache web server and configures this web server to use port 80 for HTTP and port 443 for HTTPS. The document root for this instance is located at:
/Library/FileMaker Server/HTTPServer/htdocs
I'm trying to use the Apache commands via the Mac OS X Terminal to stop/start/restart this instance but it looks like it's trying to use the standard OS X Apache not the FileMaker Server installed instance.
For example I would like to use:
sudo apachetctl restart
When there are 2 instances of Apache installed how do you specify which instance you wish to command?
Finally found the answer. The following syntax will work:
sudo /Library/Filemaker\ Server/HTTPServer/bin/httpdctl graceful
If you want to keep your OS Apache running it needs to be on a different port. FileMaker doesn't really support console commands and wants you to restart the computer to restart apache.
You can try with the launchctl:
sudo launchctl stop com.filemaker.fms
sudo launchctl start com.filemaker.fms
Or you can try to run httpd and specify the 2nd file directly
/usr/sbin/httpd -f /Library/FileMaker\ Server/HTTPServer/conf/httpd.conf -t
if you you want to restart FileMaker Server you should use this commands in Terminal :
fmsadmin start server
fmsadmin stop server
fmsadmin restart server

$ service apache2 restart [fail]

I have installed Apache on my Ubuntu Server.
For a special reason I have to enable mod_rewrite on it.
So I have done this.
And in every Tutorial on the internet the last command is to restart apache.
But when I do this the console prints [fail].
Can anyone help me here?
$ service apache2 restart
* Restarting web server apache2 [fail]
I had a similar problem, and for me it was about the logged in user not having privileges so instead of
service apache2 restart
I had to do
sudo service apache2 restart
It's telling you some other service is already on port 80, perhaps it's apache
try Code:
sudo /etc/init.d/apache2 stop
followed by Code:
sudo killall apache2
then make sure no services are running on port 80 Code:
sudo netstat -l|grep www
then (re)start apache Code:
sudo /etc/init.d/apache2 restart
Using the systemd features ( starting from Ubuntu 15) , you can restart apache service as follow :
sudo systemctl restart apache2.service
Check the status:
sudo systemctl status apache2.service
There are various reason for this one .
could be the privilege problem if you have privilege problem then
please use sudo for the same .
could be the apache already running in your system then please check the
status of the service by running command service apache2 status if they
said that [FAIL] apache2 is not running ... failed! it mean it is not running
you can start by the command service apache2 start or sudo service
apache2 start
if you having not above problem please look at the PID file of
apache2 by following command cat /var/run/apache2/apache2.pid
which will give you the process ID of the apache it means you
system accidentally shutdown without deleting the PID file so
delete by following command rm - rf/var/run/apache2/apache2.pid or sudo rm -rf/var/run/apache2/apache2.pid and start again the server by
following command service apache2 start or sudo service
apache2 start
I face this issue when I was adding new web site to my web server which is hosted in Digital Ocean Cloud service. So what happened was, when I using sudo commands to restart or reload apache2 server its restring with following error messages.
For me everything worked well despite these two error messages.
Error 1 - Unable to resolve host 'YOUR HOST NAME' .
Error 2 - sum_functio_error() //I don't remember this function name I'll update this later.
So the fix was very simple.
First open your hotsts file.
sudo nano /etc/hosts
Output File
127.0.1.1 hostname
127.0.0.1 localhost
sudo nano /etc/hostname
Output File
hostnamexxx
Try below command to restart.
# /etc/init.d/apache2 restart
OR
$ sudo /etc/init.d/apache2 restart
OR
$ sudo service apache2 restart
To stop Apache 2 web server, enter:
# /etc/init.d/apache2 stop
OR
$ sudo /etc/init.d/apache2 stop
OR
$ sudo service apache2 stop
To start Apache 2 web server, enter:
# /etc/init.d/apache2 start
OR
$ sudo /etc/init.d/apache2 start
OR
$ sudo service apache2 start

Lamp configuration on CentOS

I have installed LAMP on my CentOS server VM, where I want to access my server by the browser of my local machine, but it doesn't work. Please help me find the solution.
Are you sure it's running?
try
ps ax | grep httpd | grep -v grep
and if you see no output do:
/etc/init.d/httpd restart
The server will be accessible on your configured virtual host. Make sure you follow each step in this guide.
Is your VM network bridged or NAT'ted? If bridged, something on the VM is wrong as it should just show as a standard machine on your network. If NAT'ted, you will need to read up on NAT connections in your virtualisation documenation.