The steps to set up a LAMP environment (Linux + Apache + MySQL/MariaDB + PHP) on a server in Singapore are as follows. This tutorial uses Ubuntu 22.04 and CentOS 9 as examples. Some commands need to be adjusted for other versions.
First you need to connect to the server, login to the Singapore server using SSH:
ssh root@your_server_ip
Update system again, Ubuntu/Debian:
apt update && apt upgrade -y
CentOS/RHEL:
dnf update -y
Install Apache in Ubuntu/Debian:
apt install apache2 -y
systemctl enable apache2
systemctl start apache2
CentOS/RHEL:
dnf install httpd -y
systemctl enable httpd
systemctl start httpd
Verify Apache installation, Ubuntu/Debian:
apt install apache2 -y
systemctl enable apache2
systemctl start apache2
CentOS/RHEL:
dnf install httpd -y
systemctl enable httpd
systemctl start httpd
Go to http://your_server_ip, and if you see the Apache default page, you are successful.
If you still need to set up a firewall, Ubuntu:
ufw allow 80/tcp
ufw allow 443/tcp
ufw reload
CentOS:
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
Install MySQL/MariaDB, Ubuntu/Debian:
apt install mysql-server -y
systemctl enable mysql
systemctl start mysql
# Run the security configuration script
mysql_secure_installation
CentOS/RHEL:
dnf install mariadb-server mariadb -y
systemctl enable mariadb
systemctl start mariadb
# Run the security configuration script
mysql_secure_installation
Install PHP, Ubuntu/Debian:
apt install php libapache2-mod-php php-mysql php-curl php-gd php-zip php-mbstring -y
To restart Apache:
systemctl restart apache2
CentOS/RHEL Enable EPEL and Remi warehouses:
dnf install epel-release -y
dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y
dnf module enable php: remi-8.1-y # Select the version as required
Install PHP and extensions:
dnf install php php-mysqlnd php-curl php-gd php-zip php-mbstring -y
To restart Apache:
systemctl restart httpd
To test a LAMP environment, first create a PHP test file:
echo "<? php phpinfo(); ? >" > /var/www/html/info.php
Ubuntu path is:
/var/www/html/
CentOS path:
/var/www/html/
To access the test page, you need to open the browser to visit http://your_server_ip/info.php, and the PHP information is displayed normally. The test PHP script tests the database connection by creating the database and users ahead of time.
It is better to configure a firewall to close unwanted ports. Common port SSH: 22\HTTP: 80\HTTPS: 443. You also need to disable PHP danger functions. Edit the /etc/php./ version number /apache2/php.ini (Ubuntu) or /etc/php.ini (CentOS) to disable the following functions:
disable_functions = exec,passthru,shell_exec,system
Then configure the SSL certificate and update the system periodically. The 403 Forbidden error may be displayed. You are advised to check the file permission:
chown -R www-data:www-data /var/www/html/ # Ubuntu
chown -R apache:apache /var/www/html/ # CentOS
If php can't connect to MySQL, be sure to install the PHp-mysql extension and restart Apache. If the port is also occupied, run the netstat -tulpn | grep :80 command to find the occupied process.