热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ubuntu14.04LTS安装nginx+mariaDB+php7+YAF的方法

这篇文章主要介绍了ubuntu14.04LTS安装nginx+mariaDB+php7+YAF的方法,详细讲述了ubuntu14.04LTS环境下nginx+mariaDB+php7+YAF的安装方法与相关注意事项,需要的朋友可以参考下

本文讲述了ubuntu14.04LTS安装nginx+mariaDB+php7+YAF的方法。分享给大家供大家参考,具体如下:

ubuntu apt-get方式安装nginx

参考:

http://nginx.org/en/linux_packages.html

首先

in order to authenticate the nginx repository signature and to eliminate warnings about missing PGP key during installation of the nginx package, it is necessary to add the key used to sign the nginx packages and repository to the apt program keyring.

下载密钥

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

然后添加

sudo apt-key add nginx_signing.key

加入nginx的repository

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

若安装稳定版本,则输入以下内容

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

若最新版本,则输入以下内容:

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

然后安装

apt-get update
apt-get install nginx

安装完成

nginx -v
nginx version: nginx/1.8.0

MariaDB数据库安装

MariaDB是一个开源数据库且100%与MySQL兼容,目标是替代MySQL数据库。

MariaDB的背景 :

2008年,MySQL被后来被Oracle在2010年收购的Sun Microsystems收购了。 最初被Sun公司的收购由于符合项目的需要而受到MySQL社区的欢呼,但是这种情绪并没有持续太久,接下来被Oracle的收购,不幸期望远远低于预 期。许多MySql的开发者离开了Sun和Oracle公司开始新的项目。在他们中间就有MySQL的创建者以及项目长期技术带头人之一的Michael 'Monty' Widenius。Monty和他的团队创建了MySQL的一个fork版本并且命名它为MariaDB。

默认上MariaDB的包并没有在Ubuntu仓库中。要安装MariaDB,我们首先要设置MariaDB仓库。

设置 MariaDB 仓库

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 key "MariaDB Package Signing Key " 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'

安装 MariaDB :

sudo apt-get update
sudo apt-get install mariadb-server

在安装中,你会被要求设置MariaDB的root密码。

从命令行连接到MariaDB :

keyun@ubuntu-server:~$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 43
Server version: 10.0.23-MariaDB-1~trusty-log mariadb.org binary distribution
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>

MariaDB 服务

sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

以上只是在Ubuntu上装完MariaDB,下面要设置MariaDB允许远程访问

1、如果Ubuntu有设置防火墙或者iptables规则的话,请自行打开

2、3306端口是不是没有打开?

使用nestat命令查看3306端口状态:

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

从结果可以看出3306端口只是在IP 127.0.0.1上监听,所以拒绝了其他IP的访问。

解决方法:修改/etc/mysql/my.cnf文件。打开文件,找到下面内容:

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1

把上面这一行注释掉或者把127.0.0.1换成合适的IP,建议注释掉。

重新启动后,重新使用netstat检测:

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

1. 把用户权限分配各远程用户。

登录到mysql服务器,使用grant命令分配权限

代码如下:
mysql> grant all on . to 你的用户名如root@'%' identified by '你的密码';

完成后使用mysql命令连接,提示成功,为了确保正确可以再远程登陆测试一下。

安装PHP7

因为是最小化安装的ubuntu,先安装make

sudo apt-get install make

下载源码

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

根据鸟哥指示,安装gcc4.8

使用新一点的编译器, 推荐GCC 4.8以上, 因为只有GCC 4.8以上PHP才会开启Global Register for opline and execute_data支持, 这个会带来5%左右的性能提升(Wordpres的QPS角度衡量) 其实GCC 4.8以前的版本也支持, 但是我们发现它支持的有Bug, 所以必须是4.8以上的版本才会开启这个特性.

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 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade

查看版本

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; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

先安装依赖

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

因本机lib目录在/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

最后一条命令,作用是php-fpm随系统自启动。

利用php自带的php-fpm管理工具,可以很方便的start,stop,restart
把管理工具从源码包里放到php/sbin文件夹里,方便使用

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

配置nginx与php-fpm后,通过phpinfo(),看到如下

 

至此,php7安装成功。

安装apache ab压测工具

sudo apt-get install apache2-utils

压测一下

echo "hello world"
ab -n 1000 -c 20 http://10.81.36.158:9528/

QPS 7000左右

接下来开启opcache

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

找到opcache设置

添加以下内容

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

重启php-fpm

sudo kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid

或者

sudo /usr/local/php/sbin/init.d.php-fpm restart

再次测试,QPS上升到8000以上

开启HugePages

参考:https://www.jb51.net/article/85491.htm

再次测试,QPS偶尔能彪上10000

安装YAF

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

解压缩以后, 进入Yaf的源码目录, 依次执行(其中PHP_BIN是PHP的bin目录):

sudo /usr/local/php/bin/phpize

报错:

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

解决办法:

sudo apt-get install m4
sudo apt-get install autoconf
sudo apt-get install libpcre3 libpcre3-dev 

phpize执行后:

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/

安装成功,修改php.ini,加入yaf扩展

extension=yaf.so

重启php-fpm,查看phpinfo()

 

安装yaf成功

PS:使用PDO过程中,出现 SQLSTATE[HY000] [2002] No such file or directory 错误

经查,是mysql.sock找不到

在phpinfo()中,看到pdo_mysql.default_socket的值是/tmp/mysql.sock

 

但是在服务器上并没有这个文件

通过sudo service mysql status 命令

* /usr/bin/mysqladmin Ver 9.1 Distrib 10.0.23-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Server version     10.0.23-MariaDB-1~trusty-log
Protocol version    10
Connection       Localhost via UNIX socket
UNIX socket       /var/run/mysqld/mysqld.sock
Uptime:         3 min 28 sec

找到sock文件的位置在/var/run/mysqld/mysqld.sock

于是在/tmp下 做个软链接

sudo ln -s /var/run/mysqld/mysqld.sock mysql.sock

问题解决

通过localhost无法访问到数据库,但是通过IP可以

分析:这是典型的socket没有正确设置的情况。

连接MySQL数据库有两种方式:TCP/IP(一般理解的端口的那种)和Unix套接字(一般叫socket或者sock)。大部分情况下,可以用localhost代表本机127.0.0.1,但是在MySQL连接时,二者不可混用,而且MySQL中权限设置中localhost与127.0.0.1也是分开设置的。当设置为127.0.0.1时,系统通过TCP/IP方式连接数据库;当设置为localhost时,系统通过socket方式连接数据库。

根据上面的sudo service mysql status命令

得到sock文件的位置在/var/run/mysqld/mysqld.sock

于是,修改php.ini

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

重启php-fpm

问题解决

希望本文所述对大家ubuntu服务器配置有所帮助。


推荐阅读
  • 如何实现织梦DedeCms全站伪静态
    本文介绍了如何通过修改织梦DedeCms源代码来实现全站伪静态,以提高管理和SEO效果。全站伪静态可以避免重复URL的问题,同时通过使用mod_rewrite伪静态模块和.htaccess正则表达式,可以更好地适应搜索引擎的需求。文章还提到了一些相关的技术和工具,如Ubuntu、qt编程、tomcat端口、爬虫、php request根目录等。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
  • 禁止程序接收鼠标事件的工具_VNC Viewer for Mac(远程桌面工具)免费版
    VNCViewerforMac是一款运行在Mac平台上的远程桌面工具,vncviewermac版可以帮助您使用Mac的键盘和鼠标来控制远程计算机,操作简 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • 推荐系统遇上深度学习(十七)详解推荐系统中的常用评测指标
    原创:石晓文小小挖掘机2018-06-18笔者是一个痴迷于挖掘数据中的价值的学习人,希望在平日的工作学习中,挖掘数据的价值, ... [详细]
  • Java String与StringBuffer的区别及其应用场景
    本文主要介绍了Java中String和StringBuffer的区别,String是不可变的,而StringBuffer是可变的。StringBuffer在进行字符串处理时不生成新的对象,内存使用上要优于String类。因此,在需要频繁对字符串进行修改的情况下,使用StringBuffer更加适合。同时,文章还介绍了String和StringBuffer的应用场景。 ... [详细]
  • 本文详细介绍了在ASP.NET中获取插入记录的ID的几种方法,包括使用SCOPE_IDENTITY()和IDENT_CURRENT()函数,以及通过ExecuteReader方法执行SQL语句获取ID的步骤。同时,还提供了使用这些方法的示例代码和注意事项。对于需要获取表中最后一个插入操作所产生的ID或马上使用刚插入的新记录ID的开发者来说,本文提供了一些有用的技巧和建议。 ... [详细]
  • switch语句的一些用法及注意事项
    本文介绍了使用switch语句时的一些用法和注意事项,包括如何实现"fall through"、default语句的作用、在case语句中定义变量时可能出现的问题以及解决方法。同时也提到了C#严格控制switch分支不允许贯穿的规定。通过本文的介绍,读者可以更好地理解和使用switch语句。 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • Oracle10g备份导入的方法及注意事项
    本文介绍了使用Oracle10g进行备份导入的方法及相关注意事项,同时还介绍了2019年独角兽企业重金招聘Python工程师的标准。内容包括导出exp命令、删用户、创建数据库、授权等操作,以及导入imp命令的使用。详细介绍了导入时的参数设置,如full、ignore、buffer、commit、feedback等。转载来源于https://my.oschina.net/u/1767754/blog/377593。 ... [详细]
author-avatar
手机用户2502859733
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有