Working with XAMPP
XAMPP is an AMP stack which lets you install Apache, MySQL and PHP in your computer together with some other useful software. It has been designed to provide you an easy installation experience. It’s free and available for Windows, Mac OS and Linux.
Downloading and Installing XAMPP
Go to XAMPP web site and download the installer based on your operating system. Installation should be similar to a normal software installation you do in your operating system.
When installing, there would be an option to select whether you want to run Apache and MySQL as services. If you chose it, Apache and MySQL will start at system boot-up which may not need if your computer is tight with memory resources or if you are not doing PHP development frequently. You can change these settings after installation.
Starting Apache and MySQL
Go to the location where you installed XAMPP (usually C:\Program Files\xampp) and double click on XAMPP Control Panel (xampp-control.exe). This will bring you following screen. Click on Start buttons next to Apache and MySQL for starting them.
Once opened, you would see XAMPP icon on the right of your task bar. Clicking on that icon will show/hide XAMPP control panel. To exit from XAMPP, click on Exit button in XAMPP Control Panel.
Apache Is Not Starting Error
Sometimes you would experience that even after clicking Start button several times, Apache is not starting. This is usually because some other service is running at the port required by Apache which is 80 by default. An easy reproducible way for this error is starting Skype before starting Apache.
In such a case, you would need to stop other service temporary and restart it after starting Apache. For an example, if you do so for Skype, it will find another port for working after restarting.
In the installation directory, you would see a program called Port Check (xampp-portcheck.exe). Double click on it and it will show you status of required port for Apache, MySQL and other software that comes with XAMPP. If required ports are already occupied, it will show the names of services that run on those ports.
Making Requests to the Server
Once you started Apache in control panel, type http://localhost in your web browser. This would bring you a web page that lists XAMPP related details.
Putting Stuff in Web Folder
Under XAMPP root directory there is a folder called htdocs. That’s where you should put your web site related stuff. For each web site you create, it’s better to create a folder inside htdocs folder and then put content inside that to avoid conflicts.
For an example, you can create a folder called learnphp inside htdocs folder and put welcome.php inside that. Then you can access it via the URL http://localhost/learnphp/welcome.php.
Root URL and Home Page Content
In above example, root URL of your web site is http://localhost/learnphp/ and it’s generally expected to see home page of the web site once root URL is typed in the web browser.
Usually web servers have been configured to look for an index file (can be index.htm, index.html, index.php etc) in the root of the web site folder and show its content for the home page of the site. So, if you had a file called index.php inside learnphp, you would see its output once you typed http://localhost/learnphp/.
Make sure you have only one index file in your web site to avoid conflicts. If you have more than one (say index.html, index.php), required file will be chosen based on the order defined in your web server’s configuration settings.
Locations of Configuration Files
Based on your requirements, sometimes you would need to change default settings of your web and database servers. Usually this is done by altering their configuration files. In XAMPP, Apache, PHP and MySQL configurations files are located in following locations (This assumes XAMPP installation directory as C:\Program Files\xampp).
Apache Conf File (httpd.conf): C:\Program Files\xampp\apache\conf\httpd.conf
PHP Conf File (php.ini): C:\Program Files\xampp\apache\bin\php.ini
MySQL Conf File (my.cnf): C:\Program Files\xampp\mysql\bin\my.cnf
In XAMPP, some Apache configuration settings have been moved to sub configuration files under xampp\apache\conf\extra.
To open my.cnf, double clicking on it may not work sometimes. In that case, open Notepad and then locate my.cnf file by setting Files of Type to All Files as below.
Restarting Apache and MySQL
To take effect any configuration change, it’s required to restart Apache and/or MySQL. In XAMPP, if these two are already running, stop them and start again in the Control Panel.