You are on page 1of 19

Starting Apache and MySQL

Instructions provided in this article are based on Windows operating system but the approaches
should be similar for other operating systems.

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. Thats where you should put your web
site related stuff. For each web site you create, its 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 its 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
servers 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, its required to restart Apache and/or MySQL. In XAMPP, if
these two are already running, stop them and start again in the Control Panel.

PhpMyAdmin Tutorial: Create Database


In this part of our PhpMyAdmin tutorial we will describe the steps which must be followed in order to
create a new database, add a table with records, create a database backup and perform a database
restore procedure.
We will start with the database creation.

How to Create a MySQL Database?

Please note that you can not create a database directly through cPanel->PhpMyAdmin due to the
lack of user privileges. However, you can easily create a new database from your cPanel->MySQL
Databases. Navigate to the Create New Database box. Enter the database name in the New
Database text field and click on the Create Database button.

The database name will be preceded by the cPanel username. For example, if your cPanel user
name is user and you want to have a database named test, the actual database name will be
user_test. You will get a confirmation message.
How to Add MySQL Database Tables?

Navigate to your cPanel->PhpMyAdmin tool and open the newly create database. It is empty and
there are no tables.
Enter the table name and the number of fields. Click on the Go button to create the table.

On the next screen you should enter the fields' names and the corresponding properties. The
properties are:

Type

Here you should pick the type of the data, which will be stored in the corresponding field. More
details about the possible choices can be found in the official MySQL Data Types documentation.

Length/Values

Here you should enter the length of the field. If the field type is "enum" or "set", enter the values
using the following format: 'a','b','c'...

Collation

Pick the data collation for each of the fields.

Attributes

The possible attributes' choices are:

BINARY - the collation for the field will be binary, for example utf8_bin;

UNSIGNED - the field numeric values will be positive or 0;

UNSIGNED ZEROFILL - the field numeric values will be positive or 0 and leading zeros will be
added to a number;

ON UPDATE CURRENT_TIMESTAMP - the value for a data type field has the current timestamp as
its default value, and is automatically updated;

Null

Here you define whether the field value can be NULL. More about the NULL value can be found in
the corresponding MySQL documentation.
Default

This property allows you to set the default value for the field.

Extra

In the Extra property you can define whether the field value is auto-increment.

The radio buttons that come below define whether there is an Index defined for the particular field
and specify the Index type.

Comments

Here you can add comments, which will be included in the database sql code.

At the end you can include Table comments and pick the MySQL Storage Engine and the Collation.
Once you are ready, click on the Save button.

If you want to add more fields you should specify their number and click on the Go button instead of
Save.
The database table will be created and you will see the corresponding MySQL query.

Now we will proceed with the populating of the table with data.

How to Add Content in a Database Table?

In order to add records in a database table click on the Insert tab.


Enter the data in the corresponding fields and click on the Go button to store it.

At the bottom of the page you will see a drop-down menu labelled Restart insertion with x rows .
There you can pick the number of the rows that you can populate with data and insert at once. By
default the value is 2.

The Ignore check box will allow you to ignore the data entered below it. It will not be added.

You can see the newly inserted record by clicking on the Browse tab.
You can edit or delete the record by clicking on the corresponding icons.

To insert more records, return to the Insert tab and repeat the procedure.

How to Backup a Database?

Once you are ready, you can create a backup of your database through the Export tab.
Select the tables which you want to be exported.

Leave the radio button selection to the SQL option. The Structure and the Data check boxes should
remain checked.

Select the Save as file check box and then click on the Go button.

In this way you will save the dump SQL file with your database structure and content on your local
computer.

If you have a large database with a lot of records, the server timeout value can be reached. In such
a case you can export the database in several batches. You can find more details in our MySQL
Knowledge Base.

How to Restore a Database Backup?

You can restore your database backup from the Import tab.
Click on the Browse button to select your database backup file from your local computer.

Pick the charset of the file from the corresponding drop-down menu.

If the file is too big, the MySQL server timeout can be reached. In such a case you can interrupt the
import action. Then you can continue with the data import defining the number of the queries to be
skipped from the file beginning. In this way you will skip the imported queries and continue from the
point of the interruption.

Additionally you can pick the SQL compatibility mode of the imported file. You can find more details
in the Server SQL Modes documentation.

PhpMyAdmin Tutorial: Repair and Optimize


Database
Sometimes the database tables get crashed. Also, they should be optimized from time to time. In this
part of our PhpMyAdmin tutorial we will show how to repair and optimize database tables through
PhpMyAdmin.

How to Repair MySQL Database Tables?


Open the database which should be repaired.

Select the tables that need repair and pick the Repair table action from the drop-down menu located
below the tables' list.

The tables will be repaired and you will get a confirmation screen.

How to Optimize MySQL Database Tables?

Open the database which you want to optimize.


Select the tables that need optimization.

From the drop-down menu pick the Optimize table option.

After the tables' optimization a confirmation message with a list of the optimized tables will be
visualized on the screen.
PhpMyAdmin Tutorial: Run MySQL Query
In the following part of our PhpMyAdmin tutorial we will show how to construct and run a MySQL
query.

Actually there are two options to run a MySQL query. It depends on your MySQL syntax level of
knowledge.

The one for advanced users is through the SQL tab. There you should enter the entire SQL query
code and click on the Go button to execute it.

The other option is to construct a MySQL query in the Query tab.


There you can define different search conditions, sort the results and query multiple tables.

You should select the tables used in the query from the Use Tables list.

The fields which will be included in the SELECT MySQL statement should be picked from the Field
drop-down menus. The Show check box should be selected.

In the Criteria text field you should enter the criteria according to which the search will be completed.

Through the Sort drop-down menu you can visualize the result sorted in an ascending or a
descending order.

The text window located below allows you do add extra search conditions.

Additionally, you can use the Ins and the Del check boxes to add or delete text rows for search
conditions. The same can be performed through the Add/Delete Criteria Row drop-down menu. To
add or delete columns use the corresponding Ins and Del check boxes or the Add/Delete Field
Columns drop-down menu.

In the Modify section you can define the relations between the fields (whether they are connected
through the AND or the OR logical operators).

You need to click on the Update Query button to complete the modifications.

To run the query click on the Submit Query button.


The query which we have included in our example is:

SELECT `AT_admins` . * FROM AT_admins WHERE (`AT_admins`.`login` LIKE "a%");

It shows all the records from the AT_admins table for which the login field starts with "a".

You can find more details about the MySQL syntax in the official MySQL Documentation.

PhpMyAdmin Tutorial: PhpMyAdmin


Operations
There are different operations which you can perform on the whole database and on a separate
table.

Database Operations

Select a database and navigate to the Operations tab.

There you will find all the possible actions which you can apply on a database.

The first option allows you to create a new table under the current database. Enter the table name
and the number of the fields. Then click on the Go button.
The second option is called Rename database to. However, the action can not be performed directly
through the PhpMyAdmin area due to lack of privileges for the user. If you want to rename the
database, you should create a new MySQL database, export the database tables and import them in
the new one. Then you should delete the old database through cPanel->MySQL Databases.

The same is the case with the Copy database to option. The difference with the above one is that
you should not delete the source database.

The last option allows you to change the database collation. Pick the preferred one from the drop-
down menu and confirm the modification by clicking on the Go button.

Database Tables Operations

In order to perform the corresponding operations on a database table, you should select one and
click on the Operations tab.

The Alter table order by option allows you to change the listing order for the table's records. It can be
ascending or descending. Pick the field on which to base the sorting. Click on the Go button to
confirm your choice.

The Move table to option allows you to move the table with a new name under the current database
or to move it under a different database.

In the Table options section you can rename the table, insert comments, change the storage engine
and the collation. Additionally, you can use the pack_keys option. It takes effect only with MyISAM
tables. It packs the keys. When the DEFAULT choice is selected, the storage engine packs only long
CHAR, VARCHAR, BINARY and VARBINARY columns. When 1 is selected numbers columns are
packed along with the strings. The 0 choice disables the packing of keys.

Also, there are 2 more check-boxes. When the checksum option is enabled the table checksum is
calculated. The delay_key_write option makes the index updates faster because they are not flushed
to disk until the table is closed.

Using the Copy table to option you can copy the table with a new name under the current database
or it can be duplicated in another database.

Under the Table Maintenance section you will find different options which will help you to maintain
your database table:

Check table - checks the table and the views associated with it for errors and problems;
Analyze table - analyses and stores the key distribution for the table. Then the MySQL
server uses the stored key distribution for JOIN operations and for decisions which index
to be used in a table query;
Repair table - repairs a possibly corrupted table;
Optimize table - the action should be performed when you delete or modify many
records from the table. It will reclaim the used space, defragment the data file removing
the overhead and sort the indexes.
Flush the table - clears and reloads the internal cache related to the table.

https://www.youtube.com/watch?v=ZPbCqMZpydw

You might also like