Modern web projects, be it a personal blog or a small online store, require a reliable and fast server platform. One of the most popular solutions remains the LAMP stack, which includes Apache, MariaDB and PHP. If you rent a CentOS VPS, you can deploy a full-fledged infrastructure in just half an hour, while fully controlling its operation. In this article, we will analyze the step-by-step process of installing and configuring a LAMP environment with an emphasis on security, performance and ease of administration.
Preparing the server and updating the system
First, it is important to make sure that your system is up to date. Once you have connected to your server via SSH, you should update your packages via sudo yum update -y. This will ensure that you have the latest security patches, which is critical for the web server to function. After the update, it is advisable to reboot your VPS so that all changes take effect.
Install Apache and start the service
Apache remains the most popular web server on CentOS. To install it, use the command sudo yum install httpd -y. After the installation is complete, you need to run it with sudo systemctl start httpdand enable autostart sudo systemctl enable httpd. You can check that the server is working correctly by opening the IP address in the browser - the Apache start page should be displayed.
Setting up MariaDB and creating a database
The next step is to install the MariaDB DBMS. It is installed in the same way: sudo yum install mariadb-server -y, then activated by the command sudo systemctl start mariadb and autoload is enabled. Immediately after installation, it is important to execute mysql_secure_installationto set the root password and disable anonymous accounts. After that, you can create a database for the future site: log in to the MySQL console, execute CREATE DATABASE mysite;and create a user with the necessary rights.
Installing PHP and modules
To enable the server to process dynamic requests, you need to install PHP. For CentOS 7 and 8, the command will do sudo yum install php php-mysqlnd php-cli -y. If you need support for popular CMS like WordPress or OpenCart, you should additionally install the modules php-gd, php-xmland php-mbstring. After installation, restart Apache with the command sudo systemctl restart httpd to activate PHP script processing.
Setting up a firewall and basic protection
To make your server accessible to users but protected from unwanted traffic, you need to set up a firewall. CentOS uses firewalld: sudo firewall-cmd --permanent --add-service=httpand --add-service=httpswill open ports for web traffic, and sudo firewall-cmd --reloadwill apply the changes. This will ensure the correct operation of the site and close unnecessary ports for potential attacks.
Installing SSL and Encrypting the Connection
Even for small sites, it is important to provide HTTPS access today. A free certificate from Let's Encrypt can be installed using certbot: sudo yum install certbot python3-certbot-apache -y, then sudo certbot --apache. The installation wizard will prompt you to select a domain and automatically configure a redirect from HTTP to HTTPS.
Performance Optimization
To make your site open faster, you should enable caching and compression. In Apache, this is achieved by activating the mod_expiresand modules mod_deflate. You can specify caching rules for static files and enable compression for text resources. For PHP, it is useful to activate OPcache - this will significantly speed up the CMS.
Final touches and testing
Once the installation is complete, it is important to test the server by checking that the main page opens, PHP works correctly, and that the database is connected. It is useful to create a simple page info.php with a function phpinfo();and make sure that all modules are active. At this point, the basic setup of the LAMP stack is complete, and you can load the site or CMS.
Conclusion
LAMP stack on CentOS is a fast and reliable way to deploy a working environment for a website or online store. Following the steps described, you can prepare a server in less than half an hour, providing protection, stability and high performance. This approach gives you full control over hosting, allows you to scale the project and create a reliable infrastructure for your business.