CentOS6.5 安装apache/mysql/php

1, 安装mysql

yum -y install mysql mysql-server

chkconfig --levels 235 mysqld on

/etc/init.d/mysqld start
mysql_secure_installation


2,安装httpd

yum -y install httpd
chkconfig --levels 235 httpd on
/etc/init.d/httpd start

3,安装php
yum -y install php
/etc/init.d/httpd restart
yum -y install php-mysql
yum -y install php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy curl curl-devel php-pecl-apc
/etc/init.d/httpd restart


4,配置

开启mysql远程访问

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

创建utf8数据库
CREATE DATABASE `test_db` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;


vi /usr/local/apache/conf/httpd.conf
#添加php支持。
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
#添加默认索引页面index.php,再找到“DirectoryIndex”,在index.html后面加上“ index.php”
DirectoryIndex index.html index.php
#不显示目录结构,找到“Options Indexes FollowSymLinks”,修改为
Options FollowSymLinks
#开启Apache支持伪静态,找到“AllowOverride None”,修改为
AllowOverride All
保存httpd.conf配置,然后再执行以下两行命令
chown -R apache:apache /var/www/html/
service httpd restart


以上安装好后php版本是php5.3.3

为了使一个单独程序用php的pthreads,需要编译php enable zts,我们选择另外一个版本的php,并让这两个环境共存。


1,安装编译环境及相关依赖

yum groupinstall -y 'Development Tools'
yum install \
    libxml2-devel \
    httpd-devel \
    libXpm-devel \
    gmp-devel \
    libicu-devel \
    t1lib-devel \
    aspell-devel \
    openssl-devel \
    bzip2-devel \
    libcurl-devel \
    libjpeg-devel \
    libvpx-devel \
    libpng-devel \
    freetype-devel \
    readline-devel \
    libtidy-devel \
    libxslt-devel

yum install openssl

wget http://www.atomicorp.com/installers/atomic
sh ./atomic
yum  install  libmcrypt  libmcrypt-devel


2,下载pthreads-2.0.10,php5.6并编译

先将pthreads解压后放到php-<version>/etx/目录

php目录运行:./buildconf --force

查看是否有enable-pthreads选项:./configure --help | grep pthreads


./configure \
    --prefix=/usr/local/php56 \
    --with-config-file-path=/etc/php56 \
    --with-config-file-scan-dir=/etc/php56/php.d \
    --with-libdir=lib64 \
    --with-mysql \
    --with-mysqli \
    --enable-opcache \
    --enable-pcntl \
    --enable-mbstring \
    --disable-debug \
    --disable-rpath \
    --with-bz2 \
    --enable-soap \
    --enable-zip \
    --enable-calendar \
    --enable-bcmath \
    --enable-exif \
    --enable-ftp \
    --enable-intl \
    --with-openssl \
    --with-curl \
    --with-gd \
    --with-zlib-dir=/usr/lib \
    --with-png-dir=/usr/lib \
    --with-jpeg-dir=/usr/lib \
    --with-freetype-dir=/usr/lib \
    --with-gettext \
    --with-iconv \
    --with-mcrypt \
    --with-pcre-regex \
    --with-mhash \
    --with-ldap \
    --enable-maintainer-zts \
    --with-apxs2=/usr/sbin/apxs \
    --enable-pthreads

make & make install

此时新版本的libphp.so会覆盖老的,所有此时重新装下旧版php

yum reinstall php


3,php相关配置
vi /etc/php.ini
timezone = Asia/Shanghai
memory_size = 512M
upload_max_filesize = 80M;
post_max_size = 80M;

mkdir /etc/php56

cp php.ini-production /etc/php56/php.ini

/usr/local/php56/bin/php -c /etc/php56/php.ini test.php


4,php多线程程序例子

<?php
  class test_thread_run extends Thread 
  {
      public $url;
      public $data;

      public function __construct($url)
      {
          $this->url = $url;
      }

      public function run()
      {
          if(($url = $this->url))
          {
              $this->data = model_http_curl_get($url);
          }
      }
  }

  function model_thread_result_get($urls_array) 
  {
      foreach ($urls_array as $key => $value) 
      {
          $thread_array[$key] = new test_thread_run($value["url"]);
          $thread_array[$key]->start();
      }

      foreach ($thread_array as $thread_array_key => $thread_array_value) 
      {
          while($thread_array[$thread_array_key]->isRunning())
          {
              usleep(10);
          }
          if($thread_array[$thread_array_key]->join())
          {
              $variable_data[$thread_array_key] = $thread_array[$thread_array_key]->data;
          }
      }
      return $variable_data;
  }

  function model_http_curl_get($url,$userAgent="") 
  {
      $userAgent = $userAgent ? $userAgent : 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2)'; 
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL, $url);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($curl, CURLOPT_TIMEOUT, 5);
      curl_setopt($curl, CURLOPT_USERAGENT, $userAgent);
      $result = curl_exec($curl);
      curl_close($curl);
      return $result;
  }

  for ($i=0; $i < 100; $i++) 
  { 
      $urls_array[] = array("name" => "baidu", "url" => "http://www.baidu.com/s?wd=".mt_rand(10000,20000));
  }

  $t = microtime(true);
  $result = model_thread_result_get($urls_array);
  $e = microtime(true);
  echo "多线程:".($e-$t)."\n";

  $t = microtime(true);
  foreach ($urls_array as $key => $value) 
  {
      $result_new[$key] = model_http_curl_get($value["url"]);
  }
  $e = microtime(true);
  echo "For循环:".($e-$t)."\n";
?>


参考链接:

https://www.howtoforge.com/apache_php_mysql_on_centos_6.5_lamp
http://blog.csdn.net/along602/article/details/42695779
http://docs.php.net/manual/en/pthreads.installation.php
http://zyan.cc/pthreads/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值