- 准备
主机环境:centos6.5
lamp版本:httpd-2.4.25
mysql-5.6.26
PHP-7.2.13
- 安装apache
安装包:httpd-2.4.25.tar.bz2
apr-1.4.5.tar.gz
apr-util-1.4.1.tar.gz
pcre-8.10.zip
安装编译环境:
# yum -y groupinstall "Server Platform Development" "Development tools"
安装apr:
# tar zxf apr-1.4.5.tar.gz
# cd apr-1.4.5
# ./configure --prefix=/usr/local/apr
# make && make install
安装apr-util:
# tar zxf apr-util-1.4.1.tar.gz
# cd apr-util-1.4.1
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
#make && make install
安装pcre:
# unzip pcre-8.10.zip
# cd pcre-8.10
# ./configure --prefix=/usr/local/pcre
# make && make install
安装apache:
# tar jxf httpd-2.4.25.tar.bz2
# cd httpd-2.4.25
# ./configure --prefix=/usr/local/httpd --sysconfdir=/usr/local/httpd/etc/ --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre=/usr/local/pcre/ --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=all --enable-mpms-shared=all --with-mpm=prefork
(--enable-so --enable-ssl #允许运行时加载DSO模块 # 启动ssl加密功能
--enable-cgi --enable-rewrite # 启用cgi协议 #启用URL重写功能
--with-zlib :使用指定的zlib压缩库
--with-pcre :使用指定的pcre库
--enable-modules=all # 支持动态启用模块;all:所有,most:常用
--enable-mpms-shared=all #编译并共享模块
--with-mpm=prefork #指定使用的MPM的类型 {prefork|worker|event})
# make && make install
# vim /etc/profile.d/httpd.sh //添加环境变量
export PATH=/usr/local/httpd/bin:$PATH
# ln -sv /usr/local/httpd/include /usr/include/httpd //导出头文件
# vim /etc/man.config
MANPATH /usr/local/httpd/man //导出man手册
# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
# chmod +x /etc/init.d/httpd
# service httpd start
# netstat -antp | grep httpd
tcp 0 0 :::80 :::* LISTEN 19761/httpd
安装依赖包:
# yum -y install openssl openssl-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel
# tar zxf PHP-7.2.13.tar.gz
# cd PHP-7.2.13
#./configure \
--prefix=/usr/local/PHP7 \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-config-file-path=/usr/local/PHP7/etc \
--with-MysqLi \
--with-pdo-MysqL \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--with-curl \
--with-gd \
--with-openssl \
--with-mhash \
--with-gettext \
--with-xsl --with-bz2 \
--enable-inline-optimization \ //优化线程
--enable-MysqLnd \
--enable-mbstring \
--enable-xml \
--enable-bcmath \
--enable-fpm \
--enable-sockets \
--enable-zip \
--enable-soap --enable-ftp \
# make && make install
# cp /usr/src/PHP-7.2.13/PHP.ini-production /usr/local/PHP7/etc/PHP.ini
# vim /usr/local/httpd/etc/httpd.conf
LoadModule PHP7_module modules/libPHP7.so //已有
AddType application/x-httpd-PHP .PHP //添加
DirectoryIndex index.PHP index.html //添加
# service httpd restart
测试apache连接PHP:
# vim /usr/local/httpd/htdocs/index.PHP
<?PHP
echo PHPinfo()
?>
- 安装MysqL
# yum install -y ncurses-devel libaio-devel cmake
# groupadd MysqL
# useradd -M -s /sbin/nologin MysqL -g MysqL
# tar zxf mysql-5.6.26.tar.gz
# cd mysql-5.6.26
# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/MysqL \
-DSYSconfdIR=/etc \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
# make && make install
# chown -R MysqL:MysqL /usr/local/MysqL/
# cp /usr/src/mysql-5.6.26/support-files/my-default.cnf /etc/my.cnf
# vim /etc/my.cnf
basedir = /usr/local/MysqL
datadir = /usr/local/MysqL/data
socket = /var/lib/MysqL/MysqL.sock
# /usr/local/MysqL/scripts/MysqL_install_db --user=MysqL --basedir=/usr/local/MysqL/ --datadir=/usr/local/MysqL/data/
# echo "PATH=$PATH:/usr/local/MysqL/bin" >> /etc/profile
# . /etc/profile
# cp /usr/src/mysql-5.6.26/support-files/MysqL.server /etc/init.d/MysqLd
# chmod +x /etc/init.d/MysqLd
# service MysqLd start
测试PHP通过mysqili连接数据库: 添加MysqL用户和密码
<?PHP
$link=new MysqLi('localhost','root','hzk97106');
if(!$link){
echo"database error";
}else{
echo "connection successfully!";
}
$MysqLi->close();
?>
<?PHP
$link=new pdo('MysqL:hosts=localhost','root','hzk97106');
if(!$link){
echo"database error";
}else{
echo "connection successfully!";
}
$MysqLi->close();
?>
mongodb说明:https://docs.mongodb.com/ecosystem/drivers/PHP/
对于5.X来说需要的扩展文件是mongo.so文件,对应的下载链接:https://pecl.php.net/package/mongo
对于7.X版本需要生成的扩展文件是mongodb.so文件,对应的下载链接在这里:https://pecl.php.net/package/mongodb
安装包:mongodb-linux-x86_64-rhel62-4.0.2.tgz
mongodb-1.4.2.tgz
# tar zxf mongodb-linux-x86_64-rhel62-4.0.2.tgz
# mv mongodb-linux-x86_64-rhel62-4.0.2 /usr/local/mongodb
# export PATH=/usr/local/mongodb/bin:$PATH
# cd /usr/local/mongodb/bin/
# mkdir /usr/local/mongodb/db
# touch /usr/local/mongodb/mongodb.log
# vim mongodb.conf
dbpath=/usr/local/mongodb/db
logpath=/usr/local/mongodb/mongodb.log
port=27017
fork=true
# /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongodb.conf
# echo "PATH=$PATH:/usr/local/mongodb/bin" >> /etc/profile
# . /etc/profile
# mongo
# cd /usr/src
# tar zxf mongodb-1.4.2.tgz
# cd mongodb-1.4.2
# ./configure --with-PHP-config=/usr/local/PHP7/bin/PHP-config
# make && make install
# vim /usr/local/PHP7/etc/PHP.ini
# service httpd restart
安装包:redis-3.2.1.tar.gz redis-3.1.6.tgz
下载地址:http://pecl.php.net/package/redis
# tar zxf redis-3.2.1.tar.gz
# mv redis-3.2.1 /usr/local/redis
# cd /usr/local/redis/
# make
# make install
# vim /usr/local/redis/redis.conf
daemonize yes (no -> yes)
# /usr/local/bin/redis-server /usr/local/redis/redis.conf
# redis-cli //使用客户端
PHP扩展:
# tar zxf redis-3.1.6.tgz
# cd redis-3.1.6
# ./configure --with-PHP-config=/usr/local/PHP7/bin/PHP-config
# make && make install
# vim /usr/local/PHP7/etc/PHP.ini
# service httpd restart
<?PHP
$redis->connect('127.0.0.1',6379);
$redis->set('name','hzk');
echo $redis->get('name'); ?>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。