Installation LEMP – Linux Nginx MariaDB PHP7Author: Rafal Marguzewicz
Tags: Linux • MariaDB • nginx • PHP7
If we have installed Linux system, we can to go install the rest of the kit LEMP Linux, NGINX, MariaDb i PHP7. Since the first time, when I installed NGINX, Apache seems to me less attractive.
MariaDB instead MySQL I chose technical but also ehical reasons. Fast of PHP7 will improve the approach to this language. Together LEMP is very fast and powerful set.
LEMP action plan:
- Explain possible problems
Installation PHP7 on Linux
sudo apt install php7.0 php7.0-fpm php7.0-mysql php7.0-cli php7.0-curl php7.0-json php7.0-gd php7.0-mcrypt php7.0-mbstring
Installation NGINX the stable version
sudo apt install nginx
sudo apt install mariadb-server
In case any problems, I recommend to visit this page, chose your system, last the stable version MariaDB. During installation, you will be asked for the root password root. If it’s localhost developers developers localhost, password you can set empty. Then installer ask for the password, 3 times
2. Configuration LEMP
Folder of Website files where –
/home/<user>/Desktop/localhost. if it’s production server, I propose keep files in a folder /home/<user>/www. Remember set owner and/or group on www-data.
sudo chown www-data:www-data -R /home/<user>/www/
/etc/nginx/ – folder where NGINX have configuration files .
- nginx.conf – main configuration file. All settings of server HTTP. To segregate settings nginx.conf can include content of server_blocks.conf (the default is diferent)
- server_blocks.conf – settings of server blocks (domains, subdomains, redirect, rewrite and subpages).
- global.conf – optimizations
- php.conf – you can include when you need PHP7 (only for main domains)
- ssl.conf – you can include when you need HTTPS/2. After need to generate SSL keys. Recommended free letsencrypt
If you configure host with one user, you do not need default concept, domain configurations into separate files and folders sites-available or conf.d.
sudo rm -fr /etc/nginx/conf.d/ sudo rm -fr /etc/nginx/sites-available/ sudo rm -fr /etc/nginx/sites-enabled/
I have prepared a package for you that you can download and copy to the NGINX folder
If server local/developers
wget https://pceuropa.net/blog/wp-content/uploads/nginx_config_localhost.tar.gz && tar vxf nginx_config_localhost.tar.gz
wget https://pceuropa.net/blog/wp-content/uploads/nginx_config_remote.tar.gz && tar vxf nginx_config_remote.tar.gz
Do not forget change path in file server_blocks.conf. Next we copy files to folder NGINX
sudo cp *.conf /etc/nginx/
and reload config NGINX for confirm changes
sudo service nginx reload
Instead changes filed by method copy files, you can edit them, cut ctrl + shift + V only needed elements :
sudo nano /etc/nginx/nginx.conf sudo nano /etc/nginx/server_blocks.conf sudo nano /etc/nginx/global.conf sudo nano /etc/nginx/fastcgi.conf sudo nano /etc/nginx/php.conf sudo nano /etc/nginx/ssl.conf
Configuration for localhost is different from the production server – on localhost useful is show the list of folders. On productions, better show blank page.
3. Possible problems
NGINX: bad address of configuration folders, syntax errors config. Apache in system (sudo apt-get remove apache).
Linux: permissions (chmod lub chown) to files or folders. Problems with install packages.
SQL: during installation, you may not be asked about password – something of the service MySQL is already running .
In case of problems, more information is needed:
If syntax error in configuration file of NGINX fallow command, print out line with mistake:
sudo nginx -t
Invalid folder address or permissions, logs should help
sudo tail /var/log/nginx/error.log
sudo nano /var/log/nginx/error.log
sudo chown www-data:www-data -R /home/user/www/site
or check if path are the same with those with from configuration.
In case problem with SQL server, check if you can log in from terminal
mysql -u root -p
If not, fallow to procedure to reset root password.