Installing LEMP (Linux, Nginx, MariaDB, PHP)
Nginx installation and configuration:
- Install dependencies before installing Nginx.
sudo yum install epel-release
- Install Nginx using yum.
sudo yum install nginx
- Start Nginx services.
sudo systemctl start nginx
- Check your Nginx server if it is working using your browser.
http://youripaddress/
- Enable Nginx at boot start.
sudo systemctl enable nginx
PHP installation and configuration:
- Include php-mysql php-fpm package.
sudo yum install php-mysql php-fpm
- Browse php.ini directory file.
sudo nano /etc/php.ini
- Look for cgi.fix and update it with the data below.
cgi.fix_pathinfo=0
- Configure www.conf by browsing its location and updating its www.conf file.
sudo nano /etc/php-fpm.d/www.conf
listen = /var/run/php-fpm/php-fpm.sock listen.owner = nobody listen.group = nobody user = nginx group = nginx
- Start PHP processor.
sudo systemctl start php-fpm
- Enable PHP processor to start at boot.
sudo systemctl enable php-fpm
Virtual hosts configuration and other configuration:
- Create a directory for sites-available and sites-enabled.
mkdir -p /etc/nginx/sites-available mkdir -p /etc/nginx/sites-enabled
- Add a configuration file in sites-available folder.
sudo nano /etc/nginx/sites-available/yourdomain.com.conf
- Add a configuration in your configuration file (yourdomain.com.conf) using the data below.
server { listen 80; server_name www.yourdomain.com yourdomain.com; # note that these lines are originally from the "location /" block root /var/www/yourdomain.com/public_html; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$args; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/yourdomain.com/public_html; } location ~ .php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
- Create a symbolic link to sites-enabled.
sudo ln -s /etc/nginx/sites-available/yourdomain.com.conf /etc/nginx/sites-enabled/yourdomain.com
- Browse nginx.conf file.
sudo nano /etc/nginx/nginx.conf
- Add the code below inside http to enable your configuration (yourdomain.com.conf) file.
include /etc/nginx/sites-enabled/*;
- Create a directory for your website.
mkdir -p /var/www/yourdomain.com/{public_html,logs}
- Browse www directory and change ownership and permission in www directory to access publicly.
cd /var/www
sudo chown nginx:nginx * -R sudo chmod 755 * -R
- Restart Nginx service.
sudo systemctl restart nginx
- To know if you have successfully installed and configured PHP, test it using the following steps:
- Create a PHP file to your site directory.
sudo nano /var/www/yourdomain/public_html/info.php
- Add a PHP code to test it.
<?php phpinfo(); ?>
- Check your browser to see if it is working by displaying its PHP version and information.
http://your-server-ip/info.php
- Create a PHP file to your site directory.
MariaDB Installation and Configuration:
- Get components, helper package and install using yum.
sudo yum install mariadb-server mariadb
- Start the database services.
sudo systemctl start mariadb
- Secure your database. Read instructions and steps.
sudo mysql_secure_installation
- Start MariaDB at boot by enabling it.
sudo systemctl enable mariadb