Lost httpd.conf file located apache [closed]
How can I find where my httpd.conf file is located? I am running an Ubuntu Linux server from the Amazon Web Services EC2 (Elastic Compute Cloud) and I can’t find my Apache config.
Which OS are you using? How did you install Apache? Which version of Apache are you running? These are all things that you should include when this gets moved the correct place (probably SeverFault).
2 Answers 2
Get the path of running Apache
$ ps -ef | grep apache apache 12846 14590 0 Oct20 ? 00:00:00 /usr/sbin/apache2
Append -V argument to the path
$ /usr/sbin/apache2 -V | grep SERVER_CONFIG_FILE -D SERVER_CONFIG_FILE="/etc/apache2/apache2.conf"
In some OS’s you will get the relative path of conf file : -D SERVER_CONFIG_FILE=»apache2.conf» You can run «/usr/sbin/apache2 -V | grep HTTPD_ROOT» to find the root. Output: «-D HTTPD_ROOT=»/etc/apache2/apache2.conf» The absolute path will be then : «/etc/apache2/apache2.conf»
Doesn’t work on my shared host since ps only shows tasks running as me. I had to just try running «httpd -V» and «apache2ctl -V» as Rich Bower suggests.
I’m on ubuntu 14.04 with Apache2 and sudo /usr/sbin/apache2 -V | grep SERVER_CONFIG_FILE gives me some warning errors Invalid Mutex directory so the right command I used is sudo apachectl -V | grep SERVER_CONFIG_FILE
See http://wiki.apache.org/httpd/DistrosDefaultLayout for discussion of where you might find Apache httpd configuration files on various platforms, since this can vary from release to release and platform to platform. The most common answer, however, is either /etc/apache/conf or /etc/httpd/conf
Generically, you can determine the answer by running the command:
(That’s a capital V). Or, on systems where httpd is renamed, perhaps apache2ctl -V
This will return various details about how httpd is built and configured, including the default location of the main configuration file.
One of the lines of output should look like:
which, combined with the line:
will give you a full path to the default location of the configuration file
How to Edit Config Files in Ubuntu
Configuration files contain the information needed to control the operation of a program. Linux users, especially Linux administrators, need to know how to edit configuration files to maintain an Ubuntu server or desktop. Configuration files on Ubuntu are stored in subdirectories of the /etc folder as text files and can be edited with text editors. Some examples of configuration files are /etc/hosts, host.conf, hosts. resolv.conf, /etc/networks, syslog.conf, etc. in Linux-based operating systems.
To make configuration changes, you need to open the file with a text editor and edit it. In this article, I describe several ways to edit configuration files in Ubuntu. The steps described in this guide have been tested on Ubuntu 22.04, but will work on other Ubuntu versions as well.
- Using Gedit Editor
- Using Nano Editor
- Using Vim Editor
- Using Gvim Editor
- Using Emacs Editor
Now let’s take a look at these text editors. By using these editors, you can easily edit files in the terminal .
Using Gedit Editor
Gedit is the default text editor of the Gnome desktop environment. It supports tabs so you can open different files in multiple tabs. It is a simpler and easier text editor as compared to other available text editors.
To edit a config file in the text editor, launch Terminal by pressing Ctrl+Alt+T key combinations. Then type the below command as sudo:
$ sudo gedit /path/to/filename
Replace /path/to/filename with the actual file path of the configuration file that you want to edit. When prompted for a password, enter sudo password.
Example: editing of the /etc/resolv.conf file
It is like the notepad editor in Windows OS. As soon as the editor window opens, you can start typing or editing without entering in any mode. Once you have done with the editing, press Ctrl+S to save the file.
Using Nano Editor
Nano is the simplest and the most powerful built-in editor in the many Linux distributions. You do not have to learn the Nano editor before using it and also there is no need to remember the commands. They are displayed at the bottom and can be triggered with the Ctrl key. For instance to save a file, press Ctrl+O.
To edit any config file, simply open the Terminal window by pressing the Ctrl+Alt+T key combinations. Navigate to the directory where the file is placed. Then type nano followed by the filename that you want to edit.
Replace /path/to/filename with the actual file path of the configuration file that you want to edit. When prompted for a password, enter sudo password.
Now you can edit and make changes in the config file using nano editor.
Once you have done editing, press Ctrl+O to save and Ctrl+X to exit the Editor.
Using Vim Editor
Vim or Vi editor also comes pre-installed with most Linux distributions. It has no visible prompts or control that can be a little harder for beginners. However, once you learned it, it is a more quick and powerful tool for editing. Using Vim, you can edit and view multiple files in one session.
To open a file in Vim editor, open the Terminal window by pressing the Ctrl+Alt+T key combinations. Then type vi as sudo followed by filename along with the file path like:
Replace /path/to/filename with the actual file path of the configuration file that you want to edit. When prompted for a password, enter sudo password.
Then edit the file using Vim editor. Note that when the editor opens, you enter command mode. Here are the few steps to edit a file in Vim editor:
- To edit the file, Press I from the keyboard to enter into insert mode, here you can do editing just like the normal editor.
- When done with editing, get out of this mode by pressing Esc. It will return you to normal mode.
- To save the file, type :w in command mode
- To quit the editor, type :q in command mode
- To combine the above actions type :wq to save and quit simultaneously.
Using Gvim Editor
Gvim is a Vim editor with a graphical user interface. To install Gvim, launch Terminal by pressing Ctrl+Alt+T. then type the below command in Terminal to start the installation.
$ sudo apt-get install vim-gnome
Once done with the installation, you can open and edit any config file in it. Type the below command with sudo in Terminal to open any config file in Gvim:
Press I to enter in insert mode where you can edit the file.
In Gvim editor, you can do various functions using the toolbar just like any normal GUI application like saving the file, undo, redo, finding a keyword, etc.
Using Emacs Editor
Emacs is also a text editor but it is not a built-in editor. You have to manually install it using the Ubuntu Terminal. It has so many features including a built-in web browser, calculator, calendar, Terminal, etc.
To install Emacs editor, launch Terminal by pressing Ctrl+Alt+T key combinations. Type the below command in Terminal as sudo:
Once done with the installation, you can open and edit any config file in it.
To open a config file using the emacs editor, type emacs followed by filename along with the file path in the below syntax:
$ sudo emacs /path/to/filename
Replace /path/to/filename with the actual file path of the configuration file that you want to edit. When prompted for a password, enter the sudo password.
Edit the file as normal and save it using the toolbar.
You can also open the config file in bash instead of a separate window.
Type the following command as sudo in Terminal:
Edit the file as a normal text file. Then press Ctrl+X and Ctrl+C to save the file. When it prompts for saving the file, press y to save and quit the editor.
So these were some simple editors you can use to easily and safely edit config files in your Ubuntu operating system.
Search
About This Site
Vitux.com aims to become a Linux compendium with lots of unique and up to date tutorials.