Ubuntu 20.04 builds LAMP environment

The LAMP environment is to configure Apache, Mysql, and Php under Linux.

Update before downloading:

Update source: sudo apt-get update

Update software: sudo apt-get upgrade

Update system software: sudo apt-get dist-upgrade

Install Apache2

Install

sudo apt install apache2 -y

Check whether it is enabled (the default port is 80. If there is a conflict, remember to change the port. If the firewall is open, remember to release the port number)

systemctl status apache2

If there is a port conflict, go to the configuration file and change it.

Default installation location: /etc/apache2   

Modify the port number: ports.conf

If there is any conflict, replace it

Enter your IP or 127.0.0.1 or locallhost in the browser. When you see the following picture, the installation is successful (if the port number is not 80, you need to bring: IP:port number)

Attachment:
Open, close and restart apache2 (in the directory of apache2)
apache2 start
apache2 stop
apache2 restart

Install Mysql 5.7

Install

sudo apt install mysql-server mysql-client

Check

mysql

See the picture below to indicate success
 


Another:
How to create a user for the database
--Enter mysql
mysql< a i=4> --Create user CREATE USER 'username'@'%' IDENTIFIED BY '123456'; mysql -u username -p password --User login or --Give users permission to add, delete, check, and modify all tables



GRANT ALL ON *.* TO 'username'@'%';

grant select,delete,insert,update on 数据库.* to 用户名@'127.0.0.1';

Install Php

sudo apt-get install php

Check

php -v

See the picture below to indicate success

association

php and apache2

sudo apt-get install libapache2-mod-php

php giving mysql

sudo apt-get install php-mysql

test environment

open a file

cd /var/www/html

Create two files

touch test.php touch test.html

Both files are written with the following content

<?php phpinfo(); ?>

--Browser access
127.0.0.1/test.php
See the picture below to indicate that the php environment is OK
 


--Browser access
127.0.0.1/test.html
See the picture below to indicate that the LAMP environment is OK
 


Another:
If your test.html is blank, it means that the html is not within the parsing range of apache2——>Solution:
Open the file
cd /etc/apache2/mod-available/php7.4.conf
and put the first line:
< ;FilesMatch ".+.ph(ar|p|tml)$">
changed to:
<FilesMatch ".+.( ph(ar|p|tml)|html|htm$">
and restart apache2:
sudo /etc/init.d/apache2 restart< /span>
Of course, you can add others if necessary.

At this point, the LAMP construction is completed!

Guess you like

Origin blog.csdn.net/qq_46264836/article/details/131855457