How to Find MySQL, PHP and Apache Configuration Files

In this post, we will learn a number of commands for locating the default configuration files for MySQL database server (my.conf), PHP programming language (php.ini) and Apache HTTP server (http.conf), which together with Linux form the LAMP (Linux Apache Mysql/MariaDB PHP) stack.

A configuration file (or config file) contains system related or application settings. It gives developers and administrators control over operation of the system or an application.

As a Linux Sysadmin, knowing the location of configuration files or mastering means of finding them is an invaluable skill.

In Linux Directory Structure, the /etc directory or its sub-directories store system related or application configuration files.

Although this is the primary location of configuration files, a few developers choose to store other configuration files in custom directories.

How To Find MySQL (my.conf) Configuration File

You can locate the the MySQL configuration file using the mysql command line tool or mysqladmin, a client for managing a MySQL server.

The following commands will display the mysql or mysqladmin help page, which includes a section that talks about the files (configuration files) from which default options are read.

In the commands below, the grep option -A displays NUM lines of trailing context after matching lines.

$ mysql --help | grep -A1 'Default options'
$ mysqladmin --help | grep -A1 'Default options'
Find MySQL my.cnf Configuration File

Find MySQL my.cnf Configuration File

Make an effort to master the MySQL administration through these helpful articles.

  1. Learn MySQL for Beginners Guide – Part 1
  2. Learn MySQL for Beginners Guide – Part 2
  3. 20 Useful Mysqladmin Commands for Database Administration

How To Find PHP (php.ini) Configuration File

PHP can be controlled from the terminal using php command line utility, in conjunction with the -i switch which enables showing of PHP information and configurations and grep command help you to can find the PHP configuration file like so:

$ php -i | grep "Loaded Configuration File"
Find PHP (php.ini) Configuration File

Find PHP (php.ini) Configuration File

Find Apache http.conf/apache2.conf Configuration File

You can invoke apache2 directly (which is not recommended in most cases) or administer it using apache2ctl control interface as below with the -V flag which shows the version and build parameters of apache2:

--------- On CentOS/RHEL/Fedora ---------
$ apachectl -V | grep SERVER_CONFIG_FILE

--------- On Debian/Ubuntu/Linux Mint ---------
$ apache2ctl -V | grep SERVER_CONFIG_FILE
Find Apache Configuration File

Find Apache Configuration File

That’s all! Remember to share your thoughts about this post or provide us other possible ways of locating the above configuration files in the comments.

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.

Support Us

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide
The Complete Linux System Administrator Bundle
Become an Ethical Hacker Bonus Bundle

You may also like...

2 Responses

  1. LempStacker says:

    I just use command awk and sed, check configuration file of mysql, php, nginx

    Check MySQL Configuration File.

    [[email protected] ~]$ mysql --help | awk '$0~/Default options/{getline;print}'
    /etc/my.cnf ~/.my.cnf
    [[email protected] ~]$ mysqladmin --help | awk '$0~/Default options/{getline;print}'
    /etc/my.cnf ~/.my.cnf 

    Check PHP Configuration File.

    [[email protected] ~]$ php -i | awk '$0~/^Loaded Configuration File/{print $NF}'

    Check Nginx Configuration File.

    [[email protected] ~]$ nginx -V 2>&1 | sed -r -n '[email protected]*conf-path=(.*) --error.*@@p'

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.