Super fine! Ubuntu20.04 installs Apache+PHP8 environment
This article brings you relevant knowledge about PHP, and mainly shares with you the whole process of installing Apache
in the Ubuntu20.04 LTS
environment. We will also provide solutions to some of the pitfalls that may arise. Friends who are interested can take a look below. I hope it will be helpful to everyone.
Apache Introduction
Apache
is an open source web server software provided by the Apache Foundation. It is a multi-purpose, portable, and A modifiable HTTP server, one of the commonly used Web server software;
Apache
server supports mainstream operating systems, including UNIX
, Linux
, Mac OS X
, Windows
, etc.
Normally, it can be used in conjunction with MySQL
database, Perl
and PHP
script interpreter to form LAMP
Architecture, you can build a dynamic website system. Apache
is the world's number one and most popular Web
server-side software. It is the Web
server-side software used by the vast majority of websites.
Demo environment
Web page environment: Apache
(Others are also available)
PHP version: 8.0
Operating system: Ubuntu 20.04
Install Apache
After entering the ubuntu system, first update apt
:
sudo apt update
process You will be prompted whether to continue. Enter y
and press Enter to continue.
If you are stuck in this step or have network problems, you can update the apt source to Tsinghua source. For details, see the reference material ( Pay attention to selecting the correct ubuntu version): https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/ Use the command
lsb_release -a
to view the system version information. After modifying/etc/apt/source.list
, use the commandsource /etc/profile
to refresh the configuration.
Then install Apache, its name in apt is apache2
:
sudo apt-get install apache2
After the installation is complete, visit http://localhost/
See if the following interface appears:
If you are using a virtual machine, you can query the internal network IP of the current virtual machine through the
ip addr
command, and then add it from your own Open the web page on your computer to view it. Of course, you can also directly enter localhost in the virtual machine.
At this time, the server only has Apache
installed, but php
is not installed, so php
cannot be parsed temporarily.
We need to install php
, just install it in apt source. Here we take php8.0 as an example:
sudo apt-get install php8.0
You may encounter errors when installing directly here:
E: Unable to locate package php8.0 E: Couldn't find any package by glob 'php8.0'
You need to install a third-party PPA
source, execute the following commands line by line:
sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt-get install php8.0
The method to install php extension is:
sudo apt-get install php8.0-<extension name></extension>
, for examplesudo apt-get install php8.0-mysqli
.
After the installation is complete, you need to enable php8.0 in Apache. Use the following command to enable it:
a2enmod php8.0复制代码
Create a new one in the /var/www/html
directory index.php
file, write in it:
<?php phpinfo(); ?>
The way to create a new file is to first cd to the corresponding directory:
cd /var/www/html
, then enter the command:touch index.php
.
Now revisit http://localhost/index.php
, and you should be able to see php related information.
At this point, you have successfully completed the setup of the Apache
server, and the php
program is ready to run. .
Common problems and solutions
The following are some common problems and solutions when installing and using Apache
:
The web address of Apache is at There?
The default is in /var/www/html
. Of course, you can specify different paths for different domain names.
How to restart Apache
Use the command systemctl restart apache2
.
如何查看Apache当前启用的mods
可以使用httpd -M
命令查看apache
的已经启用的mods
。
也可以在Apache
的安装目录conf/httpd.conf
文件中的LoadModule
指令中查看。
用指令sudo ls -la /etc/apache2/mods-available/
可以查看所有启用的mods。
如何修改php版本
修改对应的mods即可,例如我要从php7.0变为php8.0。
首先安装php8.0:
sudo apt-get install php8.0
同时还要重新安装各种PHP拓展,如果需要的话。
用命令关闭当前的php7.0 mod。
a2dismod php7.0
在用命令开启新的php8.0 mod。
a2enmod php8.0
此时可以用php探针再查一下php版本。
php提示缺少某些拓展怎么办
比如php
提示缺少mysqli
拓展。
打开/etc/php/8.0/apache2/php.ini
,找到extionsion=mysqli
并将前面的;
删除,重启Apache。
如果还是提示缺少拓展,可能是你没有安装对应的拓展。安装完成后重启Apache即可。
总结
以上是对Apache
安装过程的全部教程,感谢大家的阅读。
推荐学习:《PHP视频教程》
The above is the detailed content of Super fine! Ubuntu20.04 installs Apache+PHP8 environment. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
