The LAMP platform refers to a software bundle consisting of Linux, Apache, MySQL, and PHP. Apache serves as the web server, MySQL as the relational database, and PHP as the server-side scripting language. Common web applications such as WordPress, Joomla, and Magento can run on the LAMP platform. This guide is based on a cloud server installed with the Fedora 34 operating system and introduces the method for installing the LAMP platform.
First, remotely log in to the cloud server via SSH and update the system to the latest state.
$ sudo dnf -y upgrade
In the Fedora operating system, the Apache server runs as the httpd daemon. Install the Apache server using the following command.
$ sudo dnf -y install httpd
Start the httpd service:
$ sudo systemctl start httpd
Access the cloud server's IP address in a browser to test if Apache has been installed successfully. If the following webpage appears, it indicates that the Apache server has been successfully installed.
Set Apache server to start automatically with the system.
$ sudo systemctl enable httpd
Other common Apache commands are as follows:
$ sudo systemctl stop httpd(stop)
$ sudo systemctl restart httpd(restart)
$ sudo systemctl reload httpd(heavy load)
After successful installation of Apache, the path to its configuration file is: /etc/httpd/conf/httpd.conf. If the configuration file is complex, it can be split into multiple files and placed in the /etc/httpd/conf.d/ directory. Additionally, the default root directory for Apache is /var/www/html.
In the Fedora operating system, the command to install MySQL is as follows:
$ sudo dnf install -y community-mysql-server
After installation, start MySQL and set it to start automatically with the system.
$ sudo systemctl start mysqld
$ sudo systemctl enable mysqld
Once MySQL is installed successfully, its configuration file path is /etc/my.cnf.d/community-mysql-server.cnf. If the configuration file is complex, it can be split into multiple files and placed in the /etc/my.cnf.d/ directory.
Please restart MySQL after modifying the configuration file to make it effective.
$ sudo systemctl restart mysqld
Other common MySQL commands are as follows:
$ sudo systemctl stop mysqld(停止)
$ sudo systemctl start mysqld(启动)
Execute the following command to enhance MySQL's security. This command will run a setup wizard, requiring answers to a series of questions and setting the MySQL root password.
$ sudo mysql_secure_installation
Below, we log into MySQL as root and create an example database named sample_db and a database user sample_db, where ROOT_PASSWORD and EXAMPLE_PASSWORD are replaced with the root password and database user password.
$ sudo mysql -u root -p 'ROOT_PASSWORD'
mysql> CREATE DATABASE sample_db;
CREATE USER 'test_user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'EXAMPLE_PASSWORD';
GRANT ALL PRIVILEGES ON sample_db.* TO 'test_user'@'localhost';
FLUSH PRIVILEGES;
Query OK, 1 row affected (0.00 sec)
mysql> QUIT;
In the Fedora operating system, the command to install PHP and its extensions is as follows:
$ sudo dnf install -y php
$ sudo dnf install -y php-cli php-fpm php-common php-mbstring php-curl php-gd php-mysqlnd php-json php-xml php-intl php-pecl-apcu php-opcache
Once PHP is installed successfully, its configuration file path is: /etc/php.ini. If the configuration file is complex, it can be split into multiple files and placed in the /etc/php.d/ directory.
Please restart Apache after modifying the configuration file to make it effective.
$ sudo systemctl restart httpd
Create a test.php file in the Apache root directory.
$ sudo vi /var/www/html/test.php
The content of the test.php file is as follows:
<?php
$con = new mysqli('localhost', 'test_user', 'EXAMPLE_PASSWORD', 'sample_db');
if ($con->connect_error) {
die("Failed to connect to the database: " . $con->connect_error);
}
echo "Connection to the database was successful";
Use the cloud server's IP address or domain name to test accessibility. For example: http://192.0.2.1/test.php. If "Connection to the database was successful" appears, it means that the Apache server can correctly parse PHP, and MySQL can connect properly.
Following these steps, we have successfully installed the LAMP platform on a Fedora cloud server and can upload our developed website programs or third-party applications like WordPress.
23-02-2024 02:02:07
22-02-2024 03:19:32
22-02-2024 03:16:03
22-02-2024 03:14:03
22-02-2024 03:11:58