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 enablezts,我们选择另外一个版本的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/

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native