First, we need to use sudo apt-get update
to update the list of apt package managers in the current system. Then use the sudo apt install apache2
command to install the Apache software.
sudo apt-get update
sudo apt-get install apache2
After inputting, you will see the following output
ubuntu@VM-0-7-ubuntu:~$ sudo apt-get install apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:........
Need to get2,857 kB of archives.
After this operation,9,307 kB of additional disk space will be used.
Do you want to continue?[Y/n]
Here to ask us whether to install, we press Y
on the keyboard, and then press the Enter key, after which you will see output similar to the following:
Get:1 http://mirrors.tencentyun.com/ubuntu xenial-security/main amd64 libjpeg-tu
.........
Processing triggers forufw(0.35-0ubuntu2)...
ubuntu@VM-0-7-ubuntu:~$
At this time, you have installed the Apache service, try to access your server through a browser, find the public IP of your server in the Tencent Cloud console, and copy it to the browser to open it. If you see the following output, it proves you Apache has been successfully installed.
**2、 Install **MySQLDatabase Service
We have installed the basic web service software Apache. Next we will install the database service. There are many choices for the database. Here we choose the most commonly used MySQL service. Just like installing Apache, we only need to enter sudo apt-get install mysql-server
to install MySQL service. The MySQL version installed here is version 5.7.
sudo apt-get install mysql-server
After the input is complete, you will see the following output
ubuntu@VM-0-7-ubuntu:~$ sudo apt install mysql-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:........0 upgraded,21 newly installed,0 to remove and 205 not upgraded.
Need to get19.4 MB of archives.
After this operation,162 MB of additional disk space will be used.
Do you want to continue?[Y/n] y
Please press Y
on the keyboard and press Enter to continue. Next, the installer will ask you to enter the password of your database root
user, as shown in the figure.
Here, please enter the password you want to set for the root
user. I enter passwd
as an example. Please set a more complicated password when setting it yourself. After the input is complete, press Enter, and the system will ask you to enter the password you just set again. Similarly, after the input is complete, we press Enter. Next will enter the long installation process, you will see output similar to the following.
Do you want to continue?[Y/n] y
Get:1 http://mirrors.tencentyun.com/ubuntu xenial-security/main amd64 mysql-common all 5.7.23-0ubuntu0.16.04.1[15.4 kB]
Get:2 http://mirrors.tencentyun.com/ubuntu xenial/main amd64 libaio1 amd64 0.3.110-2[6,356 B]..........
Setting up mysql-server(5.7.23-0ubuntu0.16.04.1)...
Processing triggers for libc-bin(2.23-0ubuntu9)...
Processing triggers forsystemd(229-4ubuntu21.2)...
Processing triggers forureadahead(0.100.0-19)...
ubuntu@VM-0-7-ubuntu:~$
Next, we will install the php environment.
3、 Install PHP environment
The same simple, we can still use the apt package manager to install php, but this time we not only need to install php itself, but also install php-fpm, which is a FastCGI manager and can be effective Control memory and process, can smoothly reload PHP configuration. Similarly, in order to connect to the database, we also need to install the php-mysql plugin. At the same time, in order to connect to Apache, we also need to install the libapache2-mod-php plugin. Use the following command to quickly install.
sudo apt-get install php
sudo apt-get install php-fpm
sudo apt-get install php-mysql
sudo apt-get install libapache2-mod-php
After entering these three commands, the system will also output a lot of content, we just need to wait patiently. It is worth noting that my system version is Ubuntu server 18.04 LTS, and PHP 7.2 is installed by default.
4、 Check whether it is working properly
We can test whether our php is running normally. Before the test, we need to prepare the test script. Here we create a new file named info.php
. This file must be placed in the directory pointed to by the root
line in the default.conf
we wrote above, in the configuration The file /etc/apache2/apache2.conf
can be viewed. The configuration in this article is in the /var/www/html
directory. The specific operations are as follows.
cd /var/www/html
vim info.php
Then write the following code in the editor
<? php phpinfo();?>
Then press the ESC
key on the keyboard, then press shift
+;
, enter w
+q
to save and exit. Next, visit http://your server's public IP address/info.php through a browser. If you see the result as shown in the figure, it proves that everything is normal. Start deploying your favorite programs as soon as possible.
( Modified from https://cloud.tencent.com/developer/article/1357329)
Recommended Posts