Ubuntu Server 16.04 Installation Lemp/lnmp Detailed tutorials

Source: Internet
Author: User
Tags gmp imap interbase soap snmp snmp module sybase tidy

This article tags: Install lemp/lnmp tutorial Ubuntu LEMP MySQL Nginx ubuntuserver internet gossip

LEMP refers to the Linux + Nginx (pronunciation engine x so here is E instead of N) + MySQL + PHP abbreviation, some places in the country called LNMP (because LNMP can not read it, and LEMP could be directly pronounced, In the future, all the tutorials will be written LEMP)

The following actions are done under the root user, either by using the sudo -i switch to root operation or by joining the sudo command yourself

First, install Nginx 1.10.X

Because nginx update is frequent, and Ubuntu Server has been updated slowly in the old can not support the new features, so we use the Nginx official PPA instead of the default source installation

First, join Nginx's PPA

apt-get install software-properties-common -yadd-apt-repository ppa:nginx/stableapt-get update

If you like the new features of Nginx, you can use the add-apt-repository ppa:nginx/development Mainline version of the installation nginx instead of the default version Stable

Then install some common software (some VPS templates are too streamlined) and Nginx

apt-get install curl vim wget unzip nginx -y

If you need more features of nginx, you can use it apt install nginx-extras instead of the default Nginx

Second, install PHP 7.0.X

This site is running in PHP 7.0, although some old programs, plug-ins do not support PHP 7.0, but this goods speed is really a lot of ah, strongly called on developers gradually transferred to the development of PHP 7.0, as for some domestic procedures, can only ha da.

After execution, install some common software and PHP 7.0.X

apt-get install php-fpm php-mysql php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc php-zip -y

Above only some of the necessary PHP components are installed, if your program requires additional PHP components, can be found through the apt-cache search php7.0 command, Ubuntu Server 16.04 Default PHP 7.0 is already in use, and all components can be replaced with php-xxx, such as using apt install php-cli to install PHP7.0-CLI

[email protected]:~$ sudo apt-cache search php7.0libapache2-mod-php7.0-server-side, html-embedded scripting Language (Apache 2 module) php-all-dev-package depending on all supported PHP development Packagesphp7.0-server-side, H tml-embedded scripting language (metapackage) php7.0-cgi-server-side, html-embedded scripting language (CGI binary) PHP7 .0-cli-command-line interpreter for the PHP scripting Languagephp7.0-common-documentation, examples and common module For Phpphp7.0-curl-curl module, phpphp7.0-dev-files for PHP7.0 module, DEVELOPMENTPHP7.0-GD-GD module for PHPPHP7. 0-GMP-GMP module for Phpphp7.0-json-json module for PHPPHP7.0-LDAP-LDAP module for PHPPHP7.0-MYSQL-MYSQL module fo R PHPPHP7.0-ODBC-ODBC Module for phpphp7.0-opcache-zend opcache module for phpphp7.0-pgsql-postgresql module for PHP Php7.0-pspell-pspell module for phpphp7.0-readline-readline module for Phpphp7.0-recode-recode module for phpphp7.0- SNMP-SNMP Module for phpphp7.0-Sqlite3-sqlite3 module for Phpphp7.0-tidy-tidy module for Phpphp7.0-xml-dom, SimpleXML, WDDX, XML, and XSL module fo R Phpphp7.0-xmlrpc-xmlrpc-epi Module for phplibphp7.0-embed-html-embedded scripting language (embedded SAPI library) ph P7.0-bcmath-bcmath module for PHPPHP7.0-BZ2-BZIP2 module for phpphp7.0-enchant-enchant module for Phpphp7.0-fpm-se Rver-side, html-embedded scripting language (fpm-cgi binary) php7.0-imap-imap module for Phpphp7.0-interbase-interbase Module for phpphp7.0-intl-internationalisation module for phpphp7.0-mbstring-mbstring module for Phpphp7.0-mcrypt-li Bmcrypt module for phpphp7.0-phpdbg-server-side, html-embedded scripting language (phpdbg binary) Php7.0-soap-soap Modu Le for phpphp7.0-sybase-sybase module for phpphp7.0-xsl-xsl module for PHP (dummy) php7.0-zip-zip module for PHPPHP7. 0-DBA-DBA Module for PHP

After the installation is complete, the edits /etc/php/7.0/fpm/php.ini are replaced with ;cgi.fix_pathinfo=1cgi.fix_pathinfo=0

vim /etc/php/7.0/fpm/php.ini

Direct input

:%s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g

Then press ESC and then press: Wq and then press ENTER to save and exit

RestartPHP7.0-fpm

systemctl restart php7.0-fpm
Third, configure Nginx websiteFile

Let's start by assuming that your domain name is example.com your server IP 192.0.2.2 (RFC 5737) and that you have resolved example.com's a record to your server IP 192.0.2.2

We start editing Nginx's default configuration file/etc/nginx/sites-available/default

vim /etc/nginx/sites-available/default

Enter or edit the following:

server {    listen 80 default_server;    listen [::]:80 default_server;    root /var/www/html;    index index.php index.html index.htm;#默认第一个域名,可以替换 _ 为 example.com 或不作处理    server_name _;    location / {        try_files $uri $uri/ =404;    }#开启 PHP7.0-fpm 模式    location ~ \.php$ {        include snippets/fastcgi-php.conf;        fastcgi_pass unix:/run/php/php7.0-fpm.sock;    }    location ~ /\.ht {        deny all;    }}

Then restart the Nginx

nginx -s reload

We can see that the default directory is /var/www/html then we create aphpinfo.php

vim /var/www/html/phpinfo.php

Input

<?php phpinfo(); ?>

After you save the exit, enter http://example.com/ or http://192.0.2.2/ see the Classic phpinfo page in the browser to indicate that the installation was successful, and if unsuccessful, carefully compare the steps to find out where the error occurred

Iv. installation of MySQL 5.7

Execute the following command

apt-get install mysql-server mysql-client -y

After successful installation, you will be asked to enter the root password of MySQL two times, please remember to use random, non-guessed password

I've seen a lot of newbies. The first installation with a weak password, and then the server is the day, so it is highly recommended that after the installation of MySQL, a security setting, a very simple command

mysql_secure_installation

After execution will let you choose password strength, generally choose 1 or 2

[email protected]:~# mysql_secure_installationsecuring the MySQL server deployment. Enter Password for user root:validate password PLUGIN can is used to test passwordsand improve security. It checks the strength of Passwordand allows the users to set only those passwords which aresecure enough. Would do you like to setup VALIDATE PASSWORD plugin? Press y| Y for Yes, no other key for No:y enter Y for initial security settings There is three levels of password validation Policy:low Length >= 8 MEDIUM length >= 8, numeric, mixed case, and special Charactersstrong Length >= 8, numeric, mixed case, special char Acters and dictionary fileplease Enter 0 = low, 1 = MEDIUM and 2 = Strong:2 the strongest password of course to enter 2Using existing Password for root. Estimated strength of the Password:100change the password for root? (Press y| Y for Yes, any other key for No): N If a strong password was previously set, you do not need to re-change the root password, otherwise press Y to enter two times to reset by default, a MySQL installation have an A nonymous user,allowing anyone to log into MySQL withoutHave to havea the user account created for them. This was intended only fortesting, and the installation go a bit smoother. You should remove them before moving into a productionenvironment. Remove anonymous users? (Press y| Y for Yes, anything other key for no): Y remove anonymous user, no bird to remove it directly normally, root should only is allowed to connect from ' localhost '. This ensures, someone cannot guess atthe root password from the network. Disallow Root login remotely? (Press y| Y for Yes, any other key for no): Y Turn off root login and don't need to log in remotely. Success.by default, MySQL comes with a database named ' Te St ' Thatanyone can access. This was also intended only for Testing,and should was removed before moving into a productionenvironment. Remove test database and access to it? (Press y|  Y for Yes, any other key for No): Y Remove Test database reloading the privilege tables would ensure that all changesmade so far would Take effect immediately. Reload privilege tables now? (Press y| Y for Yes, any of other keys for No): Y Reset Database permissions

Again, the password must be random, not guessing, using a weak password to cause the server is the case of the day is not clear

Once we have the initial security set up, we can create a database operation by first logging in to MySQL using root

mysql -u root -p

Will prompt you to enter a password, enter a password to log in, create a database named example

CREATE DATABASE example DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Because of the popularity of mobile phones, we are no longer using the utf-8 code, but instead utf8mb4 we can store emoji expressions in the MySQL database, such as this????????????

Then we create a named example_user user, use a strong password and give the example database permissions

GRANT ALL ON example.* TO ‘example_user‘@‘localhost‘ IDENTIFIED BY ‘这里改成你要设置的强大的没人能猜出来的随机的密码‘;

The terminal will be prompted Query OK, 0 rows affected, 1 warning (0.00 sec) not to take care of this warning

Then we refresh the permissions

FLUSH PRIVILEGES;

No problem, just use the exit; command to quit.

Then we test the database and /var/www/html build a mysql-test.php (via) file in the directory

vim /var/www/html/mysql-test.php

Input

<?php# Fill our vars and run on cli# $ php -f mysql-test.php$dbname = ‘example‘;    //MySQL 数据库名$dbuser = ‘example_user‘;   //MySQL 用户名$dbpass = ‘你的强大的没人可以猜出来的密码‘;$dbhost = ‘localhost‘;  //?? hostname ?????? localhost$link = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to ‘$dbhost‘");mysqli_select_db($link, $dbname) or die("Could not open the db ‘$dbname‘");$test_query = "SHOW TABLES FROM $dbname";$result = mysqli_query($link, $test_query);$tblCnt = 0;while($tbl = mysqli_fetch_array($result)) {  $tblCnt++;  #echo $tbl[0]."<br />\n";}if (!$tblCnt) {  echo "MySQL is working fine. There are no tables.";} else {  echo "MySQL is working fine. There are $tblCnt tables.";}?>

After creating the access http://example.com/mysql-test.php if it appears, MySQL is working fine. There are no tables. MySQL works correctly.

Well, the above is the basic Ubuntu Server 16.04 Installation LEMP tutorial, if there is a problem can be sent comments at any time comment message discussion.

written at the end: for Freedom look outside the world, as well as it this line, not to go to Google data, finally, Amway a V--PN agent. a red apricot VPN, to Google to check the information is the absolute first choice, the connection speed, the use is also convenient. I bought is 99¥ a year, through this link (http://my.yizhihongxing.com/aff.php?aff=2509) registered after the Member center to lose the coupon code, split down, only 7 yuan per month, special benefits.

This article tags: Install lemp/lnmp tutorial Ubuntu LEMP MySQL Nginx ubuntuserver internet gossip

Turn from SUN's BLOG-focus on Internet knowledge, share the spirit of the Internet!

Original address: "Ubuntu Server 16.04 Installation lemp/lnmp detailed tutorial "

Related reading: Aaron swartz– The internet genius of the life course: every moment asked himself, now the world what is the most important thing I can participate in doing? "
Related reading: " site environment Apache + PHP + mysql xampp, how to implement a server on the configuration of multiple sites?" "

Related reading: What is the engineer culture? Why are the engineers alive? Why do I need an engineer culture as an IT or internet company? "

Related reading: useful for programmers: 2017 latest in Google's Hosts file download and summary of the various hosts encountered the problem of the solution and configuration of the detailed

related reading: the Win10 perpetual activation tutorial and how can I see if the Windows system is permanently activated? 》

Related blog:SUN ' S blog -Focus on Internet knowledge and share the spirit of Internet! Go and see:www.whosmall.com

Original address: http://whosmall.com/?post=209

Ubuntu Server 16.04 Installation Lemp/lnmp Detailed tutorials

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.