Ubuntu 14.04 LTS Installation Nginx+mariadb+php7+yaf

Source: Internet
Author: User
Tags fpm gpg install openssl mysql in openssl phpinfo sapi
Ubuntu Apt-get Way to install Nginx

Reference
Http://nginx.org/en/linux_packages.html

First of all

In order to authenticate the Nginx repository signature and to eliminate warnings about missing PGP key during N of the Nginx package, it is necessary to add the key used to sign the Nginx packages and repository to the APT program K Eyring.

Download key

wget Http://nginx.org/keys/nginx_signing.key

And then add

sudo apt-key add Nginx_signing.key

Join Nginx's Repository

cd/etc/apt/sources.list.d/
sudo vim nginx.list

If a stable version is installed, enter the following

Deb http://nginx.org/packages/ubuntu/trusty nginx
deb-src http://nginx.org/packages/ubuntu/trusty nginx

If the latest version is available, enter the following:

Deb http://nginx.org/packages/mainline/ubuntu/trusty nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ Trusty Nginx

And then install

Apt-get Update
apt-get install Nginx

Installation Complete

Nginx-v
Nginx version:nginx/1.8.0
MARIADB Database Installation

MARIADB is an Open-source database and 100% is compatible with MySQL, with the goal of replacing the MySQL database.

MARIADB's background:
In 2008, MySQL was acquired by Sun Microsystems, which was later acquired by Oracle in 2010. Sun's acquisition was initially hailed by the MySQL community for meeting the needs of the project, but the sentiment did not last long and the subsequent takeover by Oracle was unfortunately expected to be far below expectations. Many MySQL developers have left the sun and Oracle companies to start new projects. Among them are the founders of MySQL and Michael ' Monty ' Widenius, one of the long-term technical leaders of the project. Monty and his team created a fork version of MySQL and named it mariadb.

The MARIADB package on the default is not in the Ubuntu warehouse. To install MARIADB, we first need to set up the MARIADB warehouse.

Set up MARIADB Warehouse

sudo apt-get install software-properties-common
sudo apt-key adv--recv-keys--keyserver hkp:// keyserver.ubuntu.com:80 0xcbcb082a1bb943db

executing:gpg--ignore-time-conflict--no-options-- No-default-keyring--homedir/tmp/tmp.3golfm9pz5--no-auto-check-trustdb--trust-model always--keyring/etc/apt/ TRUSTED.GPG--primary-keyring/etc/apt/trusted.gpg--recv-keys--keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
gpg:requesting key 1bb943db from HKP server keyserver.ubuntu.com gpg:key 1bb943db:public ke
Y "mariadb Package signing Key <package-signing-key@mariadb.org>" imported
gpg:total number Processed:1
GPG:               imported:1

sudo add-apt-repository ' Deb http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.0/ Ubuntu Trusty Main '

Install MARIADB:

sudo apt-get update
sudo apt-get install Mariadb-server

In the installation, you will be required to set the MARIADB root password.

To connect to mariadb from the command line:

keyun@ubuntu-server:~$ mysql-u root-p
Enter Password:
Welcome to the MARIADB Monitor.  Commands End With; or \g.
Your mariadb Connection ID is km
Server version:10.0.23-mariadb-1~trusty-log mariadb.org

binary distribution Copyright (c), 2015, Oracle, MARIADB Corporation Ab and others.

Type ' help, ' or ' \h ' for help. Type ' \c ' to clear the current input statement.

MARIADB [(None)]>

MARIADB Service

Sudo/etc/init.d/mysql Stop
sudo/etc/init.d/mysql start

These are just the mariadb on Ubuntu, and the following settings mariadb allow remote access

If Ubuntu has a firewall or iptables rule set, please open it yourself

3306 port is not open.

Use the Nestat command to view the 3306 port status:

~# Netstat-an | grep 3306

TCP 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN

From the results you can see that port 3306 is only listening on the IP 127.0.0.1, so it denies access to other IP.

Workaround: Modify the/etc/mysql/my.cnf file. Open the file and find the following:

    # Instead of skip-networking The default is now to listen only on
    # localhost which are more compatible and isn't less Secure.
    Bind-address  = 127.0.0.1
Comment out the above line or change the 127.0.0.1 to the appropriate IP. Re

-use netstat detection after reboot:

~# netstat-an | grep 3306
TCP        0      0 0.0.0.0:3306               0.0.0.0:* LISTEN

Assign user rights to each remote user.

Log on to the MySQL server and assign permissions using the GRANT command

Mysql> Grant all on. To your username such as root@ '% ' identified by ' your password ';

After the completion of the use of MySQL command connection, prompted the success, in order to ensure that the correct can be remotely logged test. Install PHP7

Because it is a minimized installation of Ubuntu, first install make

sudo apt-get install make

Download source

sudo wget https://downloads.php.net/~ab/php-7.0.2RC1.tar.gz
sudo tar-zvxf php-7.0.2rc1.tar.gz
CD Php-7.0.2rc1

According to Brother Bird, install gcc4.8

With a new compiler, GCC is recommended for more than 4.8 because only gcc 4.8 or more PHP will open the global Register for Opline
and Execute_data support, this will bring about 5% performance promotion (Wordpres QPS angle measure) actually GCC
4.8 Previous versions are also supported, but we found that it supports bugs, so it must be more than 4.8 to open this feature.

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ubuntu-toolchain-r/test 
sudo Apt-get Update

sudo apt-get install gcc-4.8 g++-4.8

sudo update-alternatives--remove-all gcc 
sudo Update-alternatives--remove-all g++

sudo update-alternatives--install/usr/bin/gcc
gcc/usr/bin/gcc-4.8 sudo update-alternatives--install/usr/bin/g++ g++/usr/bin/g++-4.8
sudo update-alternatives--config gcc
sudo update-alternatives--config g++

sudo apt-get update
sudo apt-get upgrade-y
sudo apt-get Dist-upgrade

View version

GCC--version
gcc (Ubuntu 4.8.5-2ubuntu1~14.04.1) 4.8.5
Copyright (C) 2015 free Software Foundation, Inc.
This is free software; The source for copying conditions.  There is NO
warranty, not even to merchantability or FITNESS for A particular.

Install dependencies First

sudo apt-get install LIBXML2
sudo apt-get install Libxml2-dev
sudo apt-get install OpenSSL
sudo apt-get install Libssl-dev
sudo apt-get Install Curl
sudo apt-get install Libcurl4-openssl-dev
sudo apt-get install Libgd-dev
sudo apt-get install Libxslt-dev

Because the native Lib directory is/usr/lib/x86_64-linux-gnu

./configure–prefix=/usr/local/php–with-curl–with-freetype-dir–with-gd–with-gettext–with-iconv-dir– with-kerberos–with-libdir=lib/x86_64-linux-gnu–with-libxml-dir–with-mysqli–with-openssl–with-pcre-regex– with-pdo-mysql–with-pdo-sqlite–with-pear–with-png-dir–with-xmlrpc–with-xsl–with-zlib–enable-fpm–enable-bcmath– enable-libxml–enable-inline-optimization–enable-gd-native-ttf–enable-mbregex–enable-mbstring–enable-opcache– Enable-pcntl–enable-shmop–enable-soap–enable-sockets–enable-sysvsem–enable-xml–enable-zip

sudo make
sudo make install


sudo cp php.ini-development/usr/local/php/lib/php.ini
sudo cp/usr/local/php/ etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
sudo cp/usr/local/php/etc/php-fpm.d/ www.conf.default/usr/local/php/etc/php-fpm.d/www.conf
sudo cp./sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm

The last command, the function is PHP-FPM with the system from start.

Using PHP's own PHP-FPM management tools, can be very convenient start,stop,restart
Put the management tools from the source pack into the Php/sbin folder for easy use

sudo cp./sapi/fpm/init.d.php-fpm/usr/local/php/sbin/
sudo cd/usr/local/php/sbin/
sudo chmod 755 init.d.php-fpm

After configuring Nginx with PHP-FPM, through Phpinfo (), see the following

At this point, the PHP7 installation was successful.

Install Apache AB pressure measuring tool

sudo apt-get install apache2-utils 

Press the echo "Hello World"

Ab-n 1000-c http://10.81.36.158:9528/

QPS about 7000

Next, open Opcache.

sudo vi/usr/local/php/lib/php.ini

Find Opcache Settings
Add the following content

zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1

Restart PHP-FPM

sudo kill-usr2 ' cat/usr/local/php/var/run/php-fpm.pid '

Or

SUDO/USR/LOCAL/PHP/SBIN/INIT.D.PHP-FPM restart

Test again, QPS up to more than 8000

Open Hugepages
Reference: http://www.laruence.com/2015/10/02/3069.html

Again test, QPS occasionally can puma on 10000 install YAF

sudo wget http://pecl.php.net/get/yaf-3.0.2.tgz
sudo tar-zvxf yaf-3.0.2.tgz

After decompression, enter the YAF source directory, followed by execution (where Php_bin is Php's Bin directory):

Sudo/usr/local/php/bin/phpize

Error:

Cannot find autoconf. Please check your autoconf installation and the
$PHP _autoconf environment variable. Then, rerun this script.

Solution:

sudo apt-get install M4
sudo apt-get install autoconf
sudo apt-get install libpcre3 

Phpize after execution:

sudo./configure--with-php-config=/usr/local/php/bin/php-config
sudo make
sudo make install

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/

Installation successful, modify php.ini, add yaf extension

Extension=yaf.so

Reboot php-fpm and view Phpinfo ()

Installation YAF Successful

PS: sqlstate[hy000] [2002] No such file or directory error using the PDO procedure

After investigation, it is mysql.sock can't find

In Phpinfo (), see the value of Pdo_mysql.default_socket is/tmp/mysql.sock

But this file is not on the server.

MySQL status command via sudo service

*/usr/bin/mysqladmin  Ver 9.1 distrib 10.0.23-mariadb, for Debian-linux-gnu on x86_64
Copyright (c), 2015, or Acle, Mariadb Corporation Ab and others.

Server version          10.0.23-mariadb-1~trusty-log
Protocol version
Connection              Localhost via UNIX Socket
UNIX Socket             /var/run/mysqld/mysqld.sock
Uptime:                 3 min sec

Find the location of the sock file in/var/run/mysqld/mysqld.sock

So make a soft link in/tmp
sudo ln-s/var/run/mysqld/mysqld.sock mysql.sock

Problem solving

The database cannot be accessed through localhost, but IP can
Analysis: This is the case where the typical socket is not set correctly.
There are two ways to connect to a MySQL database: TCP/IP (a generally understood port type) and UNIX sockets (usually called sockets or sock). Most of the time, you can use localhost to represent the local 127.0.0.1, but when the MySQL connection, the two are not mixed, and MySQL in the permissions set in localhost and 127.0.0.1 are set separately. When set to 127.0.0.1, the system connects the database via TCP/IP, and when set to LocalHost, the system connects the database via a socket.
According to the sudo service MySQL status command above
Get the location of the sock file in/var/run/mysqld/mysqld.sock

So, modify the php.ini

Pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock

Restart PHP-FPM
Problem solving

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.