LNMP Building based on CentOS

Source: Internet
Author: User
Tags phpinfo

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:

 
   
  
  1. ls /var/lib/php/session
  2. 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:

 
   
  
  1. user = nginx #修改用户为nginx
  2. 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):

  
 
  1. server {
  2. listen 80;
  3. #此处server_name后填写域名
  4. server_name www.xxx.com;
  5. #ngnix默认的主目录,可根据具体情况修改
  6. root /srv/web;
  7. # 添加上index.php
  8. index index.php index.html index.htm;
  9. # php解析
  10. location ~ \.php$ {
  11. fastcgi_pass 127.0.0.1:9000;
  12. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  13. include fastcgi_params;
  14. }
  15. }

* Prohibit direct access to websites via IP, prevent malicious parsing, add a new server:

 
   
  
  1. server{
  2. listen 80;
  3. # ip处填写服务器ip地址
  4. server_name: ip;
  5. return 444;
  6. }

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:

  
 
  1. chown -R nginx.nginx /srv/web/
  2. find /srv/web/ -type f -exec chmod 644 {} \;
  3. 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

    • Test Nginx:

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:

 
   
  
  1. <?php
  2. phpinfo();
  3. ?>

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

    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.