Installation of LEMP services under CentOS (Nginx, Mariadb/mysql and PHP)

Source: Internet
Author: User
Tags anonymous fpm install php

This environment is based on CentOS 7

1) Install Nginx

Yum Install Nginx # systemctl enable nginx.service# systemctl start Nginx.service

2) Install MARIADB

Yum Install mariadb-server# systemctl enable mariadb# systemctl start mariadb

When the installation is complete, the first boot should run the script first:

# mysql_secure_installation

This is a few security hardening measures for the database server, including setting the (non-empty) root password, deleting anonymous users, and locking remote access.

Here are the commands and echoes:

# mysql_secure_installationnote:running All PARTS of this SCRIPT are RECOMMENDED for all MariaDB SERVERS in Produ ction Use! Please READ each STEP carefully!in order to log into MariaDB to secure it, we'll need the currentPassword forThe root user. If You've just installed MariaDB, andYou haven't set the root password yet, the password would be blank,So, should just press ENTER here. Enter Current Password forRoot (enter fornone): OK, successfully used password, moving on ... Setting The root password ensures that nobody can log into the Mariadbroot user without the proper authorisation. Set Root Password? [y/N] New password:re-enterNewPassword:password updated successfully!Reloading Privilege tables ..... Success! bydefault, a MariaDB installation had an anonymous user, allowing Anyoneto log into MariaDB without had to had a user Accou NT created forthem. this isIntended only fortesting, and to make the Installationgo a bit smoother. You should remove them before moving into aproduction environment. Remove Anonymous Users? [y/N] ... Success!normally, Root should only is allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password fromThe network. Disallow Root Login remotely? [y/N] ... Success! bydefault, MariaDB comes with a database named'Test'That anyone canaccess. this isAlso intended only fortesting, and should is removedbefore moving into a production environment. Remove test database and access to it? [y/N]-Dropping test database ... Success! -removing privileges on test database ... Success!reloading the privilege tables would ensure that all changes made so farwill take effect immediately. Reload Privilege Tables now? [y/N] ... Success!Cleaning up ... all done! If You've completed all of the above steps, your MariaDBinstallation should now is secure. Thanks for usingmariadb!

3) Install PHP

The installation of Lemp requires at least PHP-FPM and php-mysql two modules.

The PHP-FPM (FastCGI process Manager) implements the access interfaces for Nginx servers and PHP applications that generate dynamic content.

The Php-mysql module allows the PHP program to access the Mariadb/mysql database.

Other modules according to the actual situation selection

Yum

4) Configure and start PHP-FPM

# vim/etc/php-fpm.d/www.conf

Change the user and group sections to Nginx

user == Nginx

Then start PHP-FPM

sudo systemctl start php-sudo systemctl enable php-/etc/systemd/system/ Multi-user.target.wants/php-fpm.service To/usr/lib/systemd/system/php-fpm.service.

To continue, adjust the security configuration options for PHP and add the following two lines to the/etc/php.ini file:

cgi.fix_pathinfo=0date. TimeZone ="Asia/shanghai"

The second line defines the default time zone associated with the date/time correlation function in PHP. Use the method in PHP's time zone configuration at the last section of this article to find or set your time zone and set the value of the corresponding date.timezone.

After the adjustment is complete:

# systemctl Restart nginx# systemctl restart PHP-fpm

5) Permanently shut down the HTTPD service

Due to the installation of PHP, the system defaults to the installation of httpd, in order to ensure the security of permanently shut down the service.

# systemctl Disable httpd

6) Time zone configuration for PHP (timezone)

The default time zone for PHP is configured in the php.ini file, where the configuration file is located first:

# php--iniconfiguration File (php.ini) Path:/etcloaded Configuration File:/etc/Php.iniscan forAdditional. ini filesinch:/etc/php.dadditional. ini files parsed:/etc/php.d/Curl.ini,/etc/php.d/Fileinfo.ini,/etc/php.d/Gd.ini,/etc/php.d/Json.ini,/etc/php.d/Mbstring.ini,/etc/php.d/Mcrypt.ini,/etc/php.d/Mysql.ini,/etc/php.d/Mysqli.ini,/etc/php.d/Pdo.ini,/etc/php.d/Pdo_mysql.ini,/etc/php.d/Pdo_sqlite.ini,/etc/php.d/Phar.ini,/etc/php.d/Sqlite3.ini,/etc/php.d/Zip. ini#

The second line of command echo shows that the configuration file is located at:/etc/php.ini, next determine our time zone marker (TIMEZONE,TZ), using the Tzselect command:

# Tzselectidentify a location TimeZone rules can be set correctly. pleaseSelecta continent or ocean.1) Africa2) Americas3) Antarctica4) Arctic Ocean 5) Asia 6) Atlantic Ocean7) Australia8) Europe9) Indian OceanTen) Pacific Ocean One) None-i want to specify the Timezone using the Posix TZ format.#?5 pleaseSelecta country.1) Afghanistan -) Israel *) Palestine2) Armenia +) Japan $) Philippines3) Azerbaijan -) JordanPanax Notoginseng) Qatar4) Bahrain +) Kazakhstan -) Russia5) Bangladesh A) Korea (north) the) Saudi Arabia6) Bhutan at) Korea (south) +) Singapore7) Brunei -) Kuwait A) Sri Lanka8) Cambodia -) Kyrgyzstan the) Syria 9) China           -) Laos +) TaiwanTen) Cyprus -) Lebanon -) Tajikistan One) East Timor -) Macau $) Thailand A) Georgia in) Malaysia $) Turkmenistan -) Hong Kong -) Mongolia -) Arab Emirates -) India to) Myanmar (Burma) -) Uzbekistan the) Indonesia +) Nepal the) Vietnam -) Iran -) Oman -) Yemen -) Iraq the) pakistan#?9 pleaseSelectOne of the following Timezone regions. 1) Beijing  Time2) Xinjiang time#?1The following information has been Given:china Beijing Timetherefore TZ='Asia/shanghai'would be used. Local Timeis Now:thu Mar in Ten: -: theCst2018. Universal time is Now:thu Mar in  Geneva: -: theUtc2018. is the above information OK?1) Yes2) no#?1You can MakeThis change permanent foryourself by appending the line TZ='Asia/shanghai'; export Tzto thefile '. profile' inchyour home directory; ThenLog out and loginchagain. Here is the TZ value again, this TimeOn, output So, youcan Use the/usr/bin/tzselect commandinchShell Scripts:asia/shanghai#

Our time zone is: Asia/shanghai

Now open the configuration initialization file for PHP php.ini find and modify the following:

Date.timezone = "Asia/shanghai"

Save after determining.

7) Finally restart the related service, update the configuration

# systemctl Restart nginx# systemctl restart PHP-fpm

8) Configure Nginx's website

The configuration file is as follows:

Server {Listen the;    server_name www.example.com; Root/var/www/html/example;         Index index.php index.html index.htm; Location/ {  if(-F $request _filename/index.html) {rewrite (.*) $1/index.html break; }        if(-F $request _filename/index.php) {rewrite (.*) $1/index.php; }        if(!-F $request _filename) {Rewrite (.*) /index.php; } try_files $uri $uri/ =404; } # REDIRECT Server error pages to the static page/50x.html error_page - 502 503 504/50x.html; Location= /50x.html {} # Nginx passes PHP scripts to FastCGI server via a TCP/9000Socket # This setting much is consistent with/etc/php-fpm.d/www.conf # Try_files prevents Nginx from passing bad scripts to FastCGI server location~\.php$ {try_files $uri=404; Fastcgi_pass127.0.0.1:9000;      Fastcgi_index index.php;      Fastcgi_param script_filename $document _root$fastcgi_script_name;    Include Fastcgi_params;    }}server {server_name example.com; Return301$scheme://Www.example.com$request_uri;}

9) test Server configuration

In the/var/www/html/directory, add the file index.php, which reads as follows:

<?php phpinfo ();? >

After saving, enter http://www.example.com/in the browser to view the display.

Installation of LEMP services under CentOS (Nginx, Mariadb/mysql and PHP)

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.