Php apache module linux

Installing PHP Module for Apache on Ubuntu

Apache Web Server is one of the more dominant web servers on the net. Most of those installations are running some form of PHP applications, whether Laravel, WordPress, or some other custom application.

Apache was originally used as a static web server, hosting HTML files, for example, directly the client. However, due to its support for modules the web servers capabilities have grown to run as an application server as well.

Out of the box, a default Apache2 web server installation on Ubuntu 18.04, 18.10, 19.04, and 19.10 will not run a PHP application. The PHP module is not included.

This tutorial will show you how to configure an Apache web server for running PHP applications.

Installing Apache

To install Apache on your Ubuntu server, run the following command.

Installing PHP

Install PHP is simply enough. It can Ben installed using the Apt package manager from Ubuntu’s repositories.

PHP can also be installed from source, if you require a more recent version. That task, unfortunately, is outside of the scope of this tutorial.

To install PHP, run the following command:

Additional PHP modules can be installed with the language itself.

Install Apache PHP Module

The PHP module for Apache is not bundled with Apache. As such, it must be installed in addition to the Apache package.

sudo apt install libapache2-mod-php

Once installed the module will have to be enabled. We accomplish this using the a2enmod command.

Lastly, the Apache web service requires a reboot before the enabled mod will be loaded.

sudo systemctl restart apache2

Источник

Install PHP 8 for Apache and NGINX on Ubuntu

Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.

PHP is one of the building blocks of the modern internet. It is a free, open-source scripting language that typically runs on a web server and can be integrated into regular HTML code. PHP is fast, flexible, and can interact with databases, forms, and file systems. This guide provides a brief introduction to PHP and explains how to install, configure, upgrade, and test it.

Читайте также:  Браузер yandex для линукс

What is PHP?

PHP was originally developed in 1994 for web development. PHP stood for Personal Home Page, but it has been updated as a recursive acronym that stands for PHP: Hypertext Pre-processor. It runs on all major operating systems, and all major web servers support it. The Zend Engine is typically used to compile PHP into source code. Taken together, the two components are known as “Zend PHP”. PHP is available at no cost under the PHP License.

PHP efficiently interacts with databases and can auto-generate files, PDFs, images, and media clips. It is compatible with many protocols and other programming languages through its extensive library. PHP supports functions, arrays, and object-oriented programming, but does not allow for the use of pointers.

The newest version of PHP is version 8. It was released in November 2020, although version 7.4 is still supported and widely used. PHP 8 delivers many new features, including just-in-time compilation, typing changes, and syntax additions. Many changes have also been made to the standard library.

PHP is mainly used for three different purposes:

  • Server-side scripting: This is the most common use for PHP. PHP can run as an interpreted programming language on a web server such as Apache or NGINX. The server processes the PHP code and uses it to generate a web page or HTML response for the client.
  • Command-line scripting: PHP can run as a stand-alone application using the PHP parser. The resulting scripts can be launched as cron jobs or used for text/file processing.
  • Application development: PHP is less commonly used for stand-alone development. In conjunction with the PHP-GTK extension, it can create desktop or cross-platform applications, complete with a GUI.

PHP functions like most interpreted programming languages. It contains a rich selection of control structures and is easy to learn and use. The following code snippet demonstrates how PHP can be used to embed a “Hello, World!” fragment inside HTML.

PHP code is introduced with . Your PHP code can also be written as a separate file and called from an HTML page. The official PHP website offers a simple tutorial that introduces the basics of coding with PHP. More advanced users should consult the Official PHP Documentation, which provides information on control structures, classes, and objects.

Читайте также:  Linux mint видеодрайвер amd

Advantages of PHP

PHP has become widely used in web development for the following reasons:

  • It features very good performance compared to other web technologies, especially when used in conjunction with the Apache webserver. PHP loads and compiles quickly.
  • PHP is an open-source technology and is available at no cost.
  • It can be easily integrated into HTML code.
  • PHP includes many libraries and frameworks, allowing it to work with other languages and technologies.
  • It can interact with all popular databases. When used with the MySQL database, PHP can quickly execute complex queries.
  • PHP is easy to learn and use. In terms of syntax, it is similar to other popular programming languages.
  • It is a mature technology with a large community of users. The PHP documentation is professional and comprehensive.
  • PHP integrates particularly well with WordPress, which is also written in PHP.
  • Because PHP scripts run on the server, they are invisible to the client. The client only receives the end result of the transaction. This behavior improves website and server security.

PHP has only a few disadvantages. Some of these drawbacks include a lack of libraries for new specializations such as machine learning and some security vulnerabilities. However, PHP security has been improved in recent versions.

Before You Begin

  1. If you have not already done so, create a Linode account and Compute Instance. See our Getting Started with Linode and Creating a Compute Instance guides.
  2. Follow our Setting Up and Securing a Compute Instance guide to update your system. You may also wish to set the timezone, configure your hostname, create a limited user account, and harden SSH access. Do not follow the Configure a Firewall section yet as this guide includes firewall rules specifically for an OpenVPN server.
  3. PHP is usually used in conjunction with a web server. An Apache or NGINX web server should already be installed on the Linode. See the Linode guides for Apache or NGINX for more information. Instructions for both servers are included in this guide. If ufw is enabled, ensure it allows web server access.

The steps in this guide are written for non-root users. Commands that require elevated privileges are prefixed with sudo . If you are not familiar with the sudo command, see the Linux Users and Groups guide.

Читайте также:  Usb to serial linux ubuntu

Add the PHP Repository

The following instructions are geared toward Ubuntu version 20.04, but are generally applicable for most Linux distributions. Before proceeding, ensure all packages are updated with sudo apt update .

Most Linux distributions include a PHP module in the default system package. In most cases, however, version 7.4 is still the default. To determine the current version of the default PHP package, run the command sudo apt list php . If this displays a reference to version 8.0, the correct packages are already present.

Listing. Done php/focal 2:7.4+75 all

If version 8 is not yet available, install the ondrej Personal Package Archive (PPA). This archive, which was developed by Ondřej Surý, provides access to all recent versions of PHP.

    Add the ondrej/php repository using APT.

 sudo add-apt-repository ppa:ondrej/php 
Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP () for Supported Ubuntu Releases () are provided. 
 sudo add-apt-repository ppa:ondrej/apache2 
 sudo add-apt-repository ppa:ondrej/nginx 
php/focal 2:8.0+84+ubuntu20.04.1+deb.sury.org+1 all 

How to Install PHP and PHP-FPM with Apache

This section uses either php or php8.0 , depending on the name of the default PHP package. If several different versions of PHP have been installed, a particular version can be identified by specifying the version number. Consult the Add the PHP Repository section of this guide for more details.

Install and Configure PHP as an Apache Module

 sudo apt install php-common php-mysql php-cgi php-mbstring php-curl php-gd php-xml php-xmlrpc php-pear 
PHP 8.0.8 (cli) (built: Jul 1 2021 15:26:46) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.8, Copyright (c) Zend Technologies with Zend OPcache v8.0.8, Copyright (c), by Zend Technologies 

Install and Configure PHP-FPM

The PHP FastCGI Process Manager (FPM) package enhances web server performance. It accelerates page generation, reduces memory consumption, and increases web server capacity. A special Apache module for FastCGI is required to use FPM.

    Install the php-fpm package.

 sudo apt install libapache2-mod-fcgid 
 sudo systemctl status php8.0-fpm 
php8.0-fpm.service - The PHP 8.0 FastCGI Process Manager Loaded: loaded (/lib/systemd/system/php8.0-fpm.service; enabled; vendor pr> Active: active (running) since Thu 2021-07-29 07:30:09 UTC; 1min 30s ago Docs: man:php-fpm8.0(8) 
 sudo a2enmod actions fcgid alias proxy_fcgi 

For information on how to add a virtual host, see the Linode guide on How to Install Apache Web Server on Ubuntu 18.04 LTS.

Источник

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