Install LEMP in CentOS Server

You are currently viewing Install LEMP in CentOS Server

To install the LEMP (Linux, Nginx, MySQL, PHP) stack on CentOS, follow these steps:

  1. Update the System:
   sudo yum update
  1. Install Nginx:
   sudo yum install nginx
  1. Start and Enable Nginx:
   sudo systemctl start nginx
   sudo systemctl enable nginx
  1. Install MySQL (MariaDB):
   sudo yum install mariadb-server
  1. Start and Enable MariaDB:
   sudo systemctl start mariadb
   sudo systemctl enable mariadb
  1. Run MySQL Secure Installation:
   sudo mysql_secure_installation

Follow the on-screen instructions to set the root password and secure your MySQL installation.

  1. Install PHP and Required Modules:
   sudo yum install php php-mysqlnd
  1. Restart Nginx and PHP-FPM:
   sudo systemctl restart nginx
   sudo systemctl restart php-fpm
  1. Test the LEMP Stack:
    Create a PHP info file to test the installation. Create a file named info.php in your web root directory (often /usr/share/nginx/html/):

Open your web browser and navigate to http://your_server_ip/info.php. You should see the PHP information page.

  1. 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.

Leave a Reply