Php Web Server

Apache is a popular web server application you can install on the Raspberry Pi to allow it to serve web pages.

Setting up an Apache Web Server on a Raspberry Pi Apache is a popular web server application you can install on the Raspberry Pi to allow it to serve web pages. On its own, Apache can serve HTML files over HTTP, and with additional modules can serve dynamic web pages using scripting languages such as PHP. The CLI SAPI provides a built-in web server. The web server runs only one single-threaded process, so PHP applications will stall if a request is blocked. URI requests are served from the current working directory where PHP was started, unless the -t option is used to specify an explicit document root. Download the files. Download the latest PHP 5 ZIP package from www.php.net/downloads.php. To install an IIS web server and configure it for PHP web applications, follow the steps listed. Step 1: Install IIS and PHP; Step 2: Configure PHP Settings; Step 3: Configure PHP Application Security; For planning information to review before deployment, see Plan a PHP Website on IIS. For more information, see Build a PHP Website on IIS.

On its own, Apache can serve HTML files over HTTP, and with additional modules can serve dynamic web pages using scripting languages such as PHP.

Install Apache

First, update the available packages by typing the following command into the Terminal:

Then, install the apache2 package with this command:

Test the web server

By default, Apache puts a test HTML file in the web folder. This default web page is served when you browse to http://localhost/ on the Pi itself, or http://192.168.1.10 (whatever the Pi's IP address is) from another computer on the network. To find the Pi's IP address, type hostname -I at the command line (or read more about finding your IP address).

Browse to the default web page either on the Pi or from another computer on the network and you should see the following:

This means you have Apache working!

Changing the default web page

This default web page is just an HTML file on the filesystem. It is located at /var/www/html/index.html.

Navigate to this directory in a terminal window and have a look at what's inside:

This will show you:

This shows that by default there is one file in /var/www/html/ called index.htmland it is owned by the root user (as is the enclosing folder). In order to edit the file, you need to change its ownership to your own username. Change the owner of the file (the default pi user is assumed here) using sudo chown pi: index.html.

You can now try editing this file and then refreshing the browser to see the web page change.

Your own website

If you know HTML you can put your own HTML files and other assets in this directory and serve them as a website on your local network.

Additional - install PHP

To allow your Apache server to process PHP files, you'll need to install the latest version of PHP and the PHP module for Apache. Type the following command to install these:

Now remove the index.html file:

and create the file index.php:

Put some PHP content in it:

Now save and refresh your browser. You should see 'hello world'. This is not dynamic but still served by PHP. Try something dynamic:

or show your PHP info:

Further - WordPress

Now you have Apache and PHP installed you can progress to setting up a WordPress site on your Pi. Continue to WordPress usage.

-->

Azure App Service provides a highly scalable, self-patching web hosting service. This quickstart tutorial shows how to deploy a PHP app to Azure App Service on Windows.

Azure App Service provides a highly scalable, self-patching web hosting service. This quickstart tutorial shows how to deploy a PHP app to Azure App Service on Linux.

You create the web app using the Azure CLI in Cloud Shell, and you use Git to deploy sample PHP code to the web app.

You can follow the steps here using a Mac, Windows, or Linux machine. Once the prerequisites are installed, it takes about five minutes to complete the steps.

If you don't have an Azure subscription, create a free account before you begin.

Prerequisites

To complete this quickstart:

Download the sample locally

In a terminal window, run the following commands. This will clone the sample application to your local machine, and navigate to the directory containing the sample code.

Run the app locally

Run the application locally so that you see how it should look when you deploy it to Azure. Open a terminal window and use the php command to launch the built-in PHP web server.

Open a web browser, and navigate to the sample app at http://localhost:8080.

You see the Hello World! message from the sample app displayed in the page.

In your terminal window, press Ctrl+C to exit the web server.

Use Azure Cloud Shell

Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. You can use either Bash or PowerShell with Cloud Shell to work with Azure services. You can use the Cloud Shell preinstalled commands to run the code in this article without having to install anything on your local environment.

To start Azure Cloud Shell:

OptionExample/Link
Select Try It in the upper-right corner of a code block. Selecting Try It doesn't automatically copy the code to Cloud Shell.
Go to https://shell.azure.com, or select the Launch Cloud Shell button to open Cloud Shell in your browser.
Select the Cloud Shell button on the menu bar at the upper right in the Azure portal.

To run the code in this article in Azure Cloud Shell:

  1. Start Cloud Shell.

  2. Select the Copy button on a code block to copy the code.

  3. Paste the code into the Cloud Shell session by selecting Ctrl+Shift+V on Windows and Linux or by selecting Cmd+Shift+V on macOS.

  4. Select Enter to run the code.

Configure a deployment user

FTP and local Git can deploy to an Azure web app by using a deployment user. Once you configure your deployment user, you can use it for all your Azure deployments. Your account-level deployment username and password are different from your Azure subscription credentials.

To configure the deployment user, run the az webapp deployment user set command in Azure Cloud Shell. Replace <username> and <password> with a deployment user username and password.

  • The username must be unique within Azure, and for local Git pushes, must not contain the ‘@’ symbol.
  • The password must be at least eight characters long, with two of the following three elements: letters, numbers, and symbols.

Php Web Server Docker Image

The JSON output shows the password as null. If you get a 'Conflict'. Details: 409 error, change the username. If you get a 'Bad Request'. Details: 400 error, use a stronger password.

Record your username and password to use to deploy your web apps.

Create a resource group

A resource group is a logical container into which Azure resources, such as web apps, databases, and storage accounts, are deployed and managed. For example, you can choose to delete the entire resource group in one simple step later.

In the Cloud Shell, create a resource group with the az group create command. The following example creates a resource group named myResourceGroup in the West Europe location. To see all supported locations for App Service in Free tier, run the az appservice list-locations --sku FREE command.

You generally create your resource group and the resources in a region near you.

When the command finishes, a JSON output shows you the resource group properties.

Create a resource group

A resource group is a logical container into which Azure resources, such as web apps, databases, and storage accounts, are deployed and managed. For example, you can choose to delete the entire resource group in one simple step later.

In the Cloud Shell, create a resource group with the az group create command. The following example creates a resource group named myResourceGroup in the West Europe location. To see all supported locations for App Service on Linux in Basic tier, run the az appservice list-locations --sku B1 --linux-workers-enabled command.

You generally create your resource group and the resources in a region near you.

When the command finishes, a JSON output shows you the resource group properties.

Create an Azure App Service plan

In the Cloud Shell, create an App Service plan with the az appservice plan create command.

The following example creates an App Service plan named myAppServicePlan in the Free pricing tier:

When the App Service plan has been created, the Azure CLI shows information similar to the following example:

Php Web Server

Create a web app

ServerPhp Web ServerPhp Web Server

In the Cloud Shell, create a web app in the myAppServicePlan App Service plan with the az webapp create command.

In the following example, replace <app-name> with a globally unique app name (valid characters are a-z, 0-9, and -). The runtime is set to PHP 7.4. To see all supported runtimes, run az webapp list-runtimes.

Note

The stop-parsing symbol (--%), introduced in PowerShell 3.0, directs PowerShell to refrain from interpreting input as PowerShell commands or expressions.

When the web app has been created, the Azure CLI shows output similar to the following example:

You've created an empty new web app, with git deployment enabled.

Note

The URL of the Git remote is shown in the deploymentLocalGitUrl property, with the format https://<username>@<app-name>.scm.azurewebsites.net/<app-name>.git. Save this URL as you need it later.

Browse to your newly created web app. Replace <app-name> with your unique app name created in the prior step.

Here is what your new web app should look like:

Web

Push to Azure from Git

Back in the local terminal window, add an Azure remote to your local Git repository. Replace <deploymentLocalGitUrl-from-create-step> with the URL of the Git remote that you saved from Create a web app.

Push to the Azure remote to deploy your app with the following command. When Git Credential Manager prompts you for credentials, make sure you enter the credentials you created in Configure a deployment user, not the credentials you use to sign in to the Azure portal.

This command may take a few minutes to run. While running, it displays information similar to the following example:

Browse to the app

Browse to the deployed application using your web browser.

The PHP sample code is running in an Azure App Service web app.

Congratulations! You've deployed your first PHP app to App Service.

Update locally and redeploy the code

Using a local text editor, open the index.php file within the PHP app, and make a small change to the text within the string next to echo:

In the local terminal window, commit your changes in Git, and then push the code changes to Azure.

Once deployment has completed, return to the browser window that opened during the Browse to the app step, and refresh the page.

Manage your new Azure app

  1. Go to the Azure portal to manage the web app you created. Search for and select App Services.

  2. Select the name of your Azure app.

    Your web app's Overview page will be displayed. Here, you can perform basic management tasks like Browse, Stop, Restart, and Delete.

    The web app menu provides different options for configuring your app.

Clean up resources

In the preceding steps, you created Azure resources in a resource group. If you don't expect to need these resources in the future, delete the resource group by running the following command in the Cloud Shell:

Php Web Server Download

This command may take a minute to run.

Php Web Server Windows

Next steps