Deploying LNMP Environments
Installation
Configuration
MARIADB Configuration
PHP Configuration
phpMyAdmin Configuration
PHP-FPM Configuration
Nginx Configuration
Test
LNMP (linux,nginx,mariadb,php) deployment, the following default under root permissions, take Centos7 as an example.
Installation
- Installing NMP (nginx-mariadb-php)
yum install nginx mariadb-server php php-fpm
- Set the boot up and start the service immediately:
systemctl enable nginx mariadb php-fpm && systemctl start nginx mariadb php-fpm
- Can be installed phpMyAdmin easy to manage MARIADB database:
yum install phpmyadmin
Configuring the MARIADB Configuration
mysql_secure_installation
Enter > Follow the prompts to enter y> 2 password (not recommended no password) > enter > Follow the prompts to enter y> last appearance: Thanks for using mariadb!
PHP Configuration
Edit the /etc/php.ini file, locate the line like Session.save_path , remove the comment, and modify the following:
session.save_path = "/var/lib/php/session"
See if the Session Directory exists and if it does not exist, create it manually:
ls /var/lib/php/session
mkdir /var/lib/php/session
To ensure that permissions are met, change the Session Directory file permissions:
chown nginx:nginx /var/lib/php/session -R
phpMyAdmin Configuration
Copy the phpMyAdmin directory to the Nginx root directory, with the root directory/srv/web as an example:
cp /usr/share/phpMyAdmin/ /srv/web/phpMyAdmin;
! Description: CentOS installs the phpMyAdmin in the/usr/share/directory, archlinux in the/usr/share/webapps/directory, the rest of the distribution according to the sentiment operation.
phpMyAdmin can be changed to phpMyAdmin or other easy-to-operate names. If you change the name, then the Nginx configuration should be changed to the corresponding directory name.
X can also be soft-linked phpMyAdmin directory:
ln -sf /usr/share/phpMyAdmin /srv/web/phpMyAdmin
PHP-FPM Configuration
Edit/etc/php-fpm.d/www.conf as follows:
user = nginx #修改用户为nginx
group = nginx #修改组为nginx
Nginx Configuration
Edit the. conf file under/etc/nginx/conf.d/, if/etc/nginx/conf.d/does not have any conf files under it, create a new. conf file, such as website.conf, as follows (as modified by the situation):
server {
listen 80;
#此处server_name后填写域名
server_name www.xxx.com;
#ngnix默认的主目录,可根据具体情况修改
root /srv/web;
# 添加上index.php
index index.php index.html index.htm;
# php解析
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
* Prohibit direct access to websites via IP, prevent malicious parsing, add a new server:
server{
listen 80;
# ip处填写服务器ip地址
server_name: ip;
return 444;
}
When accessed via an IP address, a 444http status code is returned, the server does not return information to the client, and the connection is closed.
*
* Permissions Issues : Nginx home directory permissions require file Permissions 644, folder 755, the owner of Nginx execution User (the default is Nginx group Nginx), the root directory for/srv/web as an example:
chown -R nginx.nginx /srv/web/
find /srv/web/ -type f -exec chmod 644 {} \;
find /srv/web/ -type d -exec chmod 755 {} \;
The 3 commands can be written to BASHRC in an alias store for easy execution, such as writing into/ETC/BASHRC,NANO.BASHRC, and then writing to the end of the file:
alias webroot=‘chown -R nginx.nginx /srv/web/ && find /srv/web/ -type d -exec chmod 755 {} \; && find /srv/web/ -type f -exec chmod 644 {} \;‘
Save and execute SOURCE/ETC/BASHRC to make it effective. In the future, if you encounter permissions problems, just execute webroot.
Test
After the configuration is complete, restart all services before testing:
systemctl restart nginx mariadb php-fpm
nginx -t
Success returns the following:
Nginx:the configuration file/etc/nginx/nginx.conf syntax is OK
Nginx:configuration file/etc/nginx/nginx.conf Test is successful
Log in to the website to test, open the domain name or IP in the browser.
Test PHP parsing:
Add the phpinfo.php test file to the root directory with the contents:
<?php
phpinfo();
?>
After saving, open the Web site, for example, the URL is xxx.com, browse xxx.com/info.php, you can see the PHP details page.
- MARIADB test, in the main directory under the phpMyAdmin name unchanged as an example, such as the URL is xxx.com, browse xxx.com/phpmyadmin into the mariadb login page, user name root, password is mariadb configuration input password.
List of attachments
LNMP Building based on CentOS