Apache Web Server Start



When you look at every single website on the Internet, Apache is the most popular web server. It powers 47% of the websites with a known web server, according to W3Techs. However, Apache’s usage greatly drops when you start looking at the web’s most highly trafficked sites. Apache only powers: 27.1% of the 100,000 most popular sites. Change the port number at the following lines. 'Listen' from 80 to 8888 and 'ServerName' machinename (ex:localhost) from 80 to 8888. Save then close. Open up Apache Service Monitor and restart service or go to Computer Management Services and locate Apache 2.2 and start or restart. Apache will execute, and will remain running until it is stopped by pressing Control-C. You can also run Apache via the shortcut Start Apache in Console placed to Start Menu - Programs - Apache HTTP Server 2.4.xx - Control Apache Server during the installation.

Apache HTTP server

This will start Apache as root. Before doing this ensure that your server is properly configured for security and access restrictions. The apachectl script is designed to act like a standard SysV init script; it can take the arguments start, restart, and stop and translate them into the appropriate signals to httpd.

The Apache HTTP Server, an open-source web server developed by the Apache Software Foundation. The Apache server is used to host web content. It responds to requests for content from web browsers, such as Internet Explorer and Firefox.

Note : The post uses RHEL/CentOS 7 distribution to install and configure the Apache server. Although the start/stop/install commands may differ but the configuration steps are same in all the linux distribution

Installing Apache

To configure your system as a web server, begin by installing the httpd software package.

Use the systemctl utility to enable the HTTP daemon to start at boot time and also to start the daemon immediately.

Configuration files

The main configuration file for Apache is /etc/httpd/conf/httpd.conf. An auxiliary directory, /etc/httpd/conf.d, also exists to store configuration files that are included in the main configuration file. Configuration files that load modules are in the /etc/httpd/conf.modules.d directory.

New apachectl subcommands in CentOS / RHEL 7

A new apachectl sub-commands are available in CentOS / RHEL 7. The following example uses the configtest subcommand to check the configuration for possible errors.

Use the graceful subcommand to reload the configuration without affecting active requests.

Configuring Apache

The main configuration file for Apache is /etc/httpd/conf/httpd.conf. Apache runs as installed, but you can modify configuration directives in this file to customize Apache for your environment. Some of these directives are described in the post below.

Testing Apache HTTP server

You can confirm that Apache is working by pointing a browser on the local system to http://localhost as shown in the picture below. You can also point a browser to http:// followed by the IP Public address of the server or the ServerName directive that you specified in the configuration file. The test page shown below confirms the functioning Apache HTTP server.

To test the display of actual content, create an HTML file named index.html in the directory specified by the DocumentRoot directive (the default directory is /var/www/html). Apache automatically displays the index.html file in this directory, if it exists.

Apache Containers

Apache containers are special configuration directives that group other directives. The containers use XML-style tags, meaning that the beginning of a container is <name> and the end is </name>. An index of all the container directives is available at http://httpd.apache.org/docs/current/sections.html. Refer the post below to get the most commonly used apache containers.

Apache Virtual Hosts

Apache supports virtual hosts, meaning that a single Apache server can respond to requests directed to multiple IP addresses or host names. Each virtual host can provide content and be configured differently.
You can configure virtual hosts in two ways:
1. IP-based Virtual Hosts (host-by-IP)
2. Name-based Virtual Hosts (host-by-name)

host-by-IP
With host-by-IP, each virtual host has its own IP address and port combination. The Apache web server responds to the IP address that the host resolves as. Host-by-IP is required for serving HTTPS requests due to restrictions in the Secure Sockets Layer (SSL) protocol.

host-by-name
With host-by-name, all virtual hosts share the common IP address. Apache responds to the request by mapping the host name in the request to ServerName and ServerAlias directives in the particular virtual host’s configuration file.

Use the <VirtualHost host-name> container to implement virtual hosts. After the first VirtualHost is defined, all of the content served by Apache must also be moved into virtual hosts.

The following example is a simple name-based virtual hosts configuration:

Apple released its 2020 newest macOS Big Sur on November 12, 2020. It is a time of year again that you might need to reconfigure your macOS if you are upgrading from the macOS Catalina. Or if you have a new macOS, follow the below steps to enable your local web server on macOS Big Sur (version 11.0.1)

Start the Apache Server

macOS comes with Apache Server by default. To start the built-in Apache server, open the Terminal app from your Application folder or type Terminal in the Spotlight Search (shortcut: Command + Space Bar)

Type sudo apachectl start and press enter

Open any of your favorite browser (e.g. Safari, Chrome)

Type localhost or 127.0.0.1 in the address bar

If Apache Server is started, you should see the below:

Create Sites Directory

It is recommended to create a Sites directory under username folder (username is your mac login name) This directory will be your document root for any web-related stuff.

  1. Go to Mac HDD > Users > [your account folder]
  2. Create a folder with the name Sites. When the folder is created, it will generate a folder with a compass image on the folder as you can see from the below screenshot.

Create username.conf file

To be able to recognize the files putting into Sites directory, username.conf needed to be setup.

1. Type whoami and press enter. (Note down the name. this is your account name / username) For example, if your username is developer, we will be making a .conf file with the name of developer.conf under /etc/apache2/users

2. Type cd /etc/apache2/users and press enter.

3. Type ls and press enter. Check if there is an existing username.conf file (username is your account name)

4. If there is an existing username.conf, make a backup copy by typing sudo cp username.conf username.conf.bak

5. Type sudo nano username.conf and press enter (note: username will be your account name e.g. developer.conf)

6. Copy and paste the following configuration.

7. Press Control + o Snap assist. and press enter to save the file.

8. Press Control + x to exit the nano editor.

Configure the httpd.conf file

1. Open the Terminal app from your Application folder or type Terminal in the Spotlight Search (shortcut: Command + Space Bar)

2. Type cd /etc/apache2 and press enter.

3. Type sudo cp httpd.conf httpd.conf.bak and press enter. (This step is optional if you want to keep the copy of the original config file but I would recommend keeping one just in case.)

4. Type sudo nano /etc/apachae2/httpd.conf and press enter.

5. Press control + w and type LoadModule authz_core_module and press enter. (control + w will activate the search and it will look for a line with the keyword you put in)

Uncomment the following modules. The # you see in front of each line means that line is commented out. That means that a specific line or module on that line will be ignored. What we want to do is, uncomment this so the module is enabled.

6. Use control + w to find each of the modules below.

7. Uncomment the following line for the User home directories.

8. Replace the below two lines with your username document root. (You can comment on those two lines by putting # in front of them.

9. Replace with the following:

Note: USERNAME needs be replaced with your username (e.g. developer)

10. Press control + w and type AllowOverride None then enter

Replace AllowOverride None to AllowOverride All

Your DocumentRoot configuration in httpd.conf will look like below:

11. Press control + o and press enter to save the file.

12. Press control + x to exit the nano editor.

Configure the httpd-userdir.conf file

1. Type cd /etc/apache2/extra and press enter.

2. Type sudo cp httpd-userdir.conf httpd-userdir.conf.bak and press enter. (this step is optional if you want to keep the copy of original file.)

Apache Web Server Start

3. Type sudo nano httpd-userdir.conf and press enter.

Uncomment the following line.

Apache Web Server Start

4. Press control + o and press enter to save the file.

5. Press control + x to exit the nano editor.

6. Type sudo apachectl restart (this step will restart the Apache server to take effect of the changes made in the config file)

Enable the PHP

macOS has built-in PHP (at least in Big Sur and prior versions) You just need to enable the PHP from the Apache’s config file. Follow the below steps to do so.

1. Open the Terminal app from your Application folder or type Terminal in the Spotlight Search (shortcut: Command + Space Bar)

2. Type cd /etc/apache2 and press enter.

3. Type sudo nano /etc/apache2/httpd.conf and press enter.

4. Press control + w and type php (this will search for a line with keyword php in Apache’s config file.)

Apache web server start command

You should be seeing the following line. Uncomment the LoadModule php7_module libexec/apache2/libphp7.so by removing the # in the front of that line of code.

5. Press control + o and press enter to save the file.

6. Press control + x to exit the nano editor.

7. Type sudo apachectl restart (this step will restart the Apache server to take effect of the changes made in the config file)

Create a phpinfo() page

To try out the PHP is working on your local mac web server, create a phpinfo() file and load it on the browser.

1. Open the Terminal app from your Application folder or type Terminal in the Spotlight Search (shortcut: Command + Space Bar)

2. Type cd ~/Sites/ and press enter.

3. Type sudo nano phpinfo.php and press enter. (this will bring up the nano editor with blank screen since the phpinfo.php is newly created file and has no code at this point)

4. Put the following code.

5. Press control + o and press enter to save the file.

6. Press control + x to exit the nano editor.

7. Open a browser and type the following in the address bar.

Apache Web Server Start

You should be seeing a page something like below. This means, the PHP is working on your local mac server.

Setting Up the MySQL Server

To be able to use a local database, you need to install a database server. In this case, we will be installing the MySQL Server. Follow the below steps to setup your MySQL Server on your local macOS.

  1. Go to https://dev.mysql.com/downloads/mysql/

2. Download the installer with DMG file.

3. Double click the MySQL server installer.

Follow the instructions on the Installer.

Restart Apache Centos

If above message shows up, click Allow.

Select Use Strong Password Encryption

Setup a password for “root” user and click Finish to complete the setup.

Apache Web Server Not Starting Xampp Ubuntu

Once the installation is complete, you can move the installer to the trash.

Now, if you go to System Preferences, you should be seeing MySQL.

If you check, it should have the green indicator showing it is up and running.

External numeric keypad for laptop. If you need to setup a MySQL Workbench, you can refer to Using MySQL Workbench on macOS Catalina (2019)

If you are using macOS Catalina, check out Setting Up Your Local Server on macOS Catalina (2019) – MAMP – macOS, Apache, MySQL, PHP to setup your mac local web server.

Latest Post