To install the LEMP (Linux, Nginx, MySQL, PHP) stack on CentOS, follow these steps:
- Update the System:
sudo yum update
- Install Nginx:
sudo yum install nginx
- Start and Enable Nginx:
sudo systemctl start nginx
sudo systemctl enable nginx
- Install MySQL (MariaDB):
sudo yum install mariadb-server
- Start and Enable MariaDB:
sudo systemctl start mariadb
sudo systemctl enable mariadb
- Run MySQL Secure Installation:
sudo mysql_secure_installation
Follow the on-screen instructions to set the root password and secure your MySQL installation.
- Install PHP and Required Modules:
sudo yum install php php-mysqlnd
- Restart Nginx and PHP-FPM:
sudo systemctl restart nginx
sudo systemctl restart php-fpm
- Test the LEMP Stack:
Create a PHP info file to test the installation. Create a file namedinfo.php
in your web root directory (often/usr/share/nginx/html/
):
<?php
phpinfo();
?>
Open your web browser and navigate to http://your_server_ip/info.php
. You should see the PHP information page.
- Firewall Configuration:
If you have a firewall enabled, you may need to open the necessary ports. For Nginx, you can use:sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --reload
These steps provide a basic LEMP stack on CentOS. Depending on your application requirements, you might need to install additional PHP modules or configure Nginx for specific use cases. Adjust the configurations as needed for your environment and application.