Home > Article > Backend Development > 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
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.
Web page environment: Apache
(Others are also available)
PHP version: 8.0
Operating system: Ubuntu 20.04
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. .
The following are some common problems and solutions when installing and using Apache
:
The default is in /var/www/html
. Of course, you can specify different paths for different domain names.
Use the command systemctl restart apache2
.
可以使用httpd -M
命令查看apache
的已经启用的mods
。
也可以在Apache
的安装目录conf/httpd.conf
文件中的LoadModule
指令中查看。
用指令sudo ls -la /etc/apache2/mods-available/
可以查看所有启用的mods。
修改对应的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
提示缺少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!