Scenario
LAMP is a common web service architecture run on Linux and consisting of Apache, MySQL/MariaDB, and PHP. This article describes how to set up LAMP on a Linux CVM.
Software
These are the software involved:
CentOS is a distribution of the Linux operating system. We will use version 7.6 in this article.
Apache is a web server software. We will use version 2.4.6 in this article.
MariaDB is a database management system. We will use version 10.4.8 in this article.
PHP is a scripting language. We will use version 7.0.33 in this article.
Prerequisites
Instructions
Step 1: Logging in to a Linux instance
Step 2: Installing Apache
1. Run the following command to install Apache.
2. Run the following commands to start Apache and set it to start automatically when the system starts.
3. Open a browser window and visit the following URL to verify that Apache is working properly.
http://[Public IP address of the CVM instance]
The following appears if Apache is installed properly:
Step 3: Installing MariaDB
1. Run the following command to check if MariaDB is already installed.
rpm -qa | grep -i mariadb
If the following appears, MariaDB is already installed.
If that’s the case, run the following to remove MariaDB to avoid conflicts between different versions. yum -y remove [Package name]
If nothing is returned, MariaDB is not installed. In this case, proceed to the next step.
2. Run the following command to create a file named MariaDB.repo
under /etc/yum.repos.d/
.
vi /etc/yum.repos.d/MariaDB.repo
3. Press i to switch to edit mode and input the following.
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
4. Press Esc and input :wq to save the file and go back.
5. Run the following command to install MariaDB.
yum -y install MariaDB-client MariaDB-server
6. Run the following commands to start MariaDB and set it to start automatically when the system starts.
7. Run the following command to verify that MariaDB is successfully installed.
If the following appears, MariaDB is successfully installed.
8. Run the following command to exit MariaDB.
Step 4: Installing and configuring PHP
1. Run the following commands to update the software source of PHP in Yum.
rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2. Run the following command to install the packages required for PHP 7.0.33.
yum -y install php70w php70w-opcache php70w-mbstring php70w-gd php70w-xml php70w-pear php70w-fpm php70w-mysql php70w-pdo
3. Run the following command to edit the Apache configuration file.
vi /etc/httpd/conf/httpd.conf
4. Press i to enter edit mode and make the following changes:
4.1 Find ServerName www.example.com:80
and start a new line below it. Input the following:
4.2 Find Require all denied
in <Directory>
and change it to Require all granted
.
4.3 Find <IfModule dir_module>
and change the content to DirectoryIndex index.php index.html
.
4.4 Start a new line below AddType application/x-gzip .gz .tgz
and input the following:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
5. Press Esc and input :wq to save the file and go back.
6. Run the following command to restart Apache.
Verifying the Environment Configuration
1. Run the following command to create a test file.
echo "<?php phpinfo(); ?>" >> /var/www/html/index.php
2. Open a browser window on your local machine and visit the following URL to check whether the environment configuration is successful.
http://CVM Public IP/index.php
If the following appears, the LAMP environment is configured successfully.
Relevant Operations
FAQ
If you encounter a problem when using CVM, refer to the following documents for troubleshooting based on your actual situation.
Was this page helpful?