Php on local web server

How to install Apache 2.4 and PHP 8 on a Windows Machine

In this tutorial, you will learn how to install and configure Apache 2.4 and PHP 8 on a Windows machine. We all know Apache HTTP Server is an open-source cross-platform and free webserver to run web applications and similarly PHP is a free and open-source scripting language used to develop web applications.

To run the PHP code on a Windows machine, first, you’ll need to install and configure a web server (Apache) that executes the PHP application. And on this page, you will find the step-by-step guide on “How to install Apache 2.4 and PHP 8 on a Windows Machine”.

P.S. Tested with Apache 2.4 and PHP 8.1.4 on a Windows 10 machine.

1. Prerequisites

Download the Apache 2.4.x and PHP 8 from its official websites, extract the downloaded file and move it to the C drive.

1.1 Download Apache 2.4.x – Depending on your system build download the binary zip file accordingly.

Download Apache 2.4 - Websparrow.org

1.2 Download PHP 8 – Similarly, depending on your system build download the Thread Safe version of PHP.

Download PHP 8 - Websparrow.org

Before jumping to the main configuration part, be sure you installed latest 14.31.31103.0 Visual C++ Redistributable Visual Studio 2015-2022 : vc_redist_x64 or vc_redist_x86 software.

2. Install Apache

To install the Apache HTTP Server on a local Windows machine move the downloaded and extracted Apache 2.4 binary files to the C drive and follow the below steps:

Step 2.1: Go to the Apache 2.4 bin directory path C:\Apache24\bin (it might be different in your case) and set it into your system environment variable path.

Set Apache 2.4 in system environment variable- Websparrow.org

Step 2.2: Open the command prompt with admin privileges and run the httpd -k install command to install the Apache services.

C:\WINDOWS\system32>httpd -k install Installing the 'Apache2.4' service The 'Apache2.4' service is successfully installed. Testing httpd.conf. Errors reported here must be corrected before the service can be started. AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::ccb2:109d:6198:a489. Set the 'ServerName' directive globally to suppress this message

Step 2.3: Start the Apache service with the command httpd -k start or directly through the Task Manager » Services » Search for Apache2.4 » Right-click on the service » Start .

Start the Apache 2.4 service - Websparrow.org

By default, Apache HTTP Server runs on port 80, make sure no other services/servers running on this port.

Step 2.4: Open the web browser and hit the default Apache localhost URL i.e localhost or localhost:80 . If everything is configured correctly, you will see the default index.html web page contents and it is located inside the C:\Apache24\htdocs directory.

Читайте также:  Java add one day to calendar

Apache 2.4 configuration successful - Websparrow.org

3. Install PHP 8

The next step is to install PHP 8. To do that, similarly, move the downloaded and extracted PHP 8 binary files to the C drive and follow the below steps:

Step 3.1: Copy the PHP 8 home path i.e C:\php-8.1.4 and set it into your machine environment variable.

Set PHP 8 path in system environment variable- Websparrow.org

Step 3.2: Open the command prompt and type php -v to check whether the path is set correctly or not. If the PHP path is set correctly, it will print the PHP version.

C:\WINDOWS\system32>php -v PHP 8.1.4 (cli) (built: Mar 16 2022 09:33:31) (ZTS Visual C++ 2019 x64) Copyright (c) The PHP Group Zend Engine v4.1.4, Copyright (c) Zend Technologies

4. Configure Apache and PHP

Now it’s time to configure Apache HTTP Server with PHP 8.

Step 4.1: Go to the C:\Apache24\conf directory, inside the conf directory edit the httpd.conf file. Go to the end of the file and add the below configuration because, in Apache, PHP is loaded as a module.

# Note: Repalce php_module location with your PHP path and # if the php8apache2_4.dll is not available, # download the non thread safe version of PHP. LoadModule php_module "C:\php-8.1.4\php8apache2_4.dll" AddHandler application/x-httpd-php .php PHPIniDir "C:\php-8.1.4"

Step 4.2: Go to the PHP home directory C:\php-8.1.4, and you will find two configuration files php.ini-development and php.ini-production . Create a copy of php.ini-development and rename it to php.ini

PHP configuration file php.ini - Websparrow.org

Step 4.3: Again open the httpd.conf file and search for ServerName, uncomment and edit the ServerName with localhost .

# ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP address here. # ServerName localhost

And in the same file also search for DirectoryIndex, and append the default index.php file.

# DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # DirectoryIndex index.html index.php 

Step 4.4: Open the command prompt and run the httpd -t command to validate whether everything is configured correctly, it will return Syntax OK if everything is configured correctly.

C:\WINDOWS\system32>httpd -t Syntax OK

5. Test the configuration

To test the Apache 2.4 and PHP 8 configuration, restart the Apache2.4 service from the Task Manager and rename the index.html file to index.php from the C:\Apache24\htdocs directory and add the below piece of code.

Apache 2.4 and PHP 8 configured successfully-Websaparrow.org'; echo ' Your current PHP version is: ' . phpversion(); header("Refresh:10; url=https://websparrow.org"); ?>

Open the web browser and hit the localhost in the URL bar, you will get the following details:

How to install Apache 2.4 and PHP 8 on a Windows Machine

References

Источник

Install PHP on Windows | Setup a local web server

With a local web server installed on your Windows or Linux computer, you can start creating and practicing your programming.

Your local web server should at a minimum:

  • install php (for back end coding)
  • install MySQL databases
  • include phpMyAdmin (to help manage your MySQL databases)
  • include the SendMail application to send local emails

For every single one of my local web server that I have setup over the past 10 years, I always use the XAMPP suite. By default, XAMPP comes with more than enough for even the most skilled web developers to create their own websites.

Читайте также:  line-height

How to Setup a Local Web Server

  1. Download the XAMPP server software from ApacheFriends.org
  2. Install XAMPP (to the default location)
  3. Start the Apache and MySQL applications
  4. Allow Apache and MySQL though the firewall
  5. Browse to your local web server

Step 1: Download the XAMPP server

Like I said before, I always use XAMPP for my local web servers. It is a free open source software suite created by the good people at ApacheFriends.org. So browse over to their website here to download the latest version of XAMPP.

Setup a local web server - Install XAMPP - 1 download XAMPP server

One of the many reasons I love to use XAMPP for my localhost server, is that it is cross platform. Meaning you can install XAMPP on Linux or install XAMPP on Windows. And as a user of both, I am grateful for that!

This tutorial will go through the steps to setup a local web server and install XAMPP on Windows. But the process is mostly the same for Linux and Mac OS.

Step 2: Install XAMPP server

With your XAMPP installer downloaded, you are ready to open that sucker up and start installing the XAMPP server software. With XAMPP, you will be able to install all the web server applications you need to operate your server and websites.

You will need administrator permission on Windows in order to install XAMPP on Windows. If you do not already have admin permission, you will need to contact your administrator.

Go ahead and launch the XAMPP server installer, and accept the UAC message for admin permissions.

You will get a message from the XAMPP installer reminding you that you MUST install XAMPP with admin permissions. If not, then you will not have a fully functional local web server. Bummer!

Select the XAMPP components

On the second screen of the Windows server installer, you will be given the options for which server applications you want to install. Each one has a different purpose:

  • PHP and Perl (used for web dev programming)
  • Apache (this runs the HTTP server)
  • MySQL and phpMyAdmin (to create and manage your databases)
  • SendMail (to send email from your local server)
  • FileZilla (for FTP access to your local server)

Setup a local web server - Install XAMPP - 2. select XAMPP modules to install for XAMPP server

Honestly, I recommend installing all the server programs that XAMPP give you the option for. They don’t take up a lot of space, and you can always learn about them later.

After you select all the server programs to install, move onto the next screen.

Choose your server installation folder

Next, you will be given a choice of where your local web server will be installed in Windows. By default, your XAMPP server will be installed to:

I recommend installing your local server to the default location. There is really no reason to change it.

Setup a local web server - Install XAMPP - 2.2. xampp server install directory

Complete the XAMPP server installation

Next, you must choose your desired written language for your web server.

Now with all your server programs selected and your installation directory chosen, you can click through the rest of the XAMPP installer to complete the installation.

Step 3: Start the Apache and MySQL applications

Once the XAMPP installation has completed, you are ready to open up the XAMPP control panel. The control panel will be your go to spot to start and stop the web server «services» (aka programs).

Читайте также:  Rainbow color in html

You can open the XAMPP control panel any time from the Windows start menu. Or if you already had the program open and minimized it, then check your «more» section of your taskbar.

Setup a local web server - Install XAMPP - 3 xampp control panel to open Apache and MySQL

From inside the control panel, you will see options for to start each of your local server’s applications, or «services». Each service is basically just an application that will run in the background of Windows.

Each time you want to start your local XAMPP server, you simply need to click the *Start *button for the Apache and MySQL services.

Step 4: Allow Apache and MySQL though the firewall

The first time you start each of the XAMPP services, you will get a Windows firewall popup. This is totally normal so do not be alarmed. This is simply the web server programs requesting access to the internet.

Setup a local web server - Install XAMPP - 4 - xampp installer Windows firewall security popup to allow Apache and MySQL though the firewall

Each of the firewall popups must be correctly acknowledged. Be sure to check the «Private networks» options at a minimum. This will allow the other computers on your private local network to access your XAMPP web server.

Additionally, you can also select the «Public networks» option if you want other people on public networks like airports and coffee shops to have access to your XAMPP server. I do NOT recommend this option. But live your best life.

Step 5: Browse to your local web server

After Apache and MySQL have been granted access though your firewall, you are just about ready to browse to your local web server.

From the XAMPP control panel, you should see a green status for both Apache and MySQL. If you do not, then you can simply Stop then Start each of the web server services. Sometimes, the first time you start each server the do not get a green status because of the Windows firewall. This is completely normal.

Setup a local web server - Install XAMPP - 5. xampp control panel with Apache and MySQL running

Once you have green status for both Apache and MySQL, you can open your web browser and navigate to your web server address:

Alternatively, you can press the Admin button next to Apache in the XAMPP control panel.

Now your local web server is all setup and ready to go!

What to do with your local web server?

Setup a local web server - Install XAMPP - 5.1 open your localhost web server for the first time

With your local XAMPP server all setup and ready to go, you are fully ready to embark on your web dev dreams. Start coding out all those sweet websites you have been dreaming of!

I STRONGLY recommend adding some extra security to your local server by changing your MySQL root password.

If you are looking for a good starting place, here is a list of my other tutorials to help get your started. Some are full projects while others are quick one off scripts.

  • Figure out php string functions
  • Get a starting point for working with MySQL databases
  • Learn about the basics of phpMyAdmin
  • Make a simple registration form as part of a PHP member website

Источник

Оцените статью