Home  >  Article  >  Backend Development  >  Super fine! Ubuntu20.04 installs Apache+PHP8 environment

Super fine! Ubuntu20.04 installs Apache+PHP8 environment

藏色散人
藏色散人forward
2023-03-21 15:26:303631browse

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 LAMPArchitecture, 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.

Super fine! Ubuntu20.04 installs Apache+PHP8 environment

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 command source /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 example sudo 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.

Super fine! Ubuntu20.04 installs Apache+PHP8 environment

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。

Super fine! Ubuntu20.04 installs Apache+PHP8 environment

如果还是提示缺少拓展,可能是你没有安装对应的拓展。安装完成后重启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!

Statement:
This article is reproduced at:juejin.im. If there is any infringement, please contact admin@php.cn delete