开发环境搭建指南

作者: sunjoy | 来源:发表于2015-10-24 22:21 被阅读0次

开发环境搭建指南


centos yum源的安装

安装epel源

sudo yum install epel-release -y

php 安装

使用yum命令安装

sudo yum install php -y
sudo yum install php-pecl-memcache -y
sudo yum install php-mysql -y
sudo yum install php-mbstring -y
sudo yum install php-devel -y

lighttpd安装

下载源码包

点击这里下载lighttpd-1.4.37.tar.gz源码包

安装依赖包

sudo yum install pcre-devel -y

安装centos7下可能缺少的依赖包

sudo yum install zlib-devel -y
sudo yum install bzip2-devel -y

使用源码编译安装到默认路径
解压到当前目录

tar zxf lighttpd-1.4.37.tar.gz

编译安装

cd lighttpd-1.4.37
./configure
make
sudo make install

注意,如果要添加ssl支持,需要在configure时改为如下

./configure —with-openssl —with-openssl-libs=/usr/lib64/openssl/

编译完成后,进行配置

sudo mkdir /etc/lighttpd
sudo cp -r doc/config/* /etc/lighttpd/
sudo cp doc/initscripts/rc.lighttpd.redhat /etc/init.d/lighttpd
sudo cp doc/initscripts/sysconfig.lighttpd /etc/sysconfig/lighttpd
sudo chkconfig lighttpd on

为lighttpd建用户和组

sudo groupadd lighttpd
sudo adduser -m -g lighttpd -d /var/www -s /sbin/nologin lighttpd

创建符号链接

sudo ln -s /usr/local/sbin/lighttpd /usr/sbin/lighttpd

建文件夹并设置权限

sudo mkdir /var/log/lighttpd
sudo chown lighttpd:lighttpd /var/log/lighttpd
sudo mkdir /var/lib/lighttpd
sudo mkdir /var/lib/lighttpd/sockets
sudo chown lighttpd:lighttpd /var/lib/lighttpd/sockets
sudo chown -R lighttpd:lighttpd /var/lib/php/session

修改配置文件

sudo vim /etc/lighttpd/lighttpd.conf

修改其中的配置如下:

var.log_root    = "/var/log/lighttpd"
var.server_root = "/var/www"
var.state_dir   = "/var/run"
var.home_dir    = "/var/lib/lighttpd"
var.conf_dir    = "/etc/lighttpd”

可以根据需要改为其他路径,但要注意各路径目录是否存在以及lighttpd用户是否有访问权限

如果需要单独配置虚拟host及访问路径,则添加类似配置

$HTTP["host"] == "172.16.200.116" {
    server.document-root = "/var/www/htdocs"
}

编辑modules.conf文件

sudo vim /etc/lighttpd/modules.conf

启用mod_alias mod_redirect mod_rewrite模块,只用去掉server.modules里这几个模块前面的注释即可

添加其他模块 ,在文件末尾添加相应的include项

include "conf.d/status.conf"
include "conf.d/fastcgi.conf"
include "conf.d/secdownload.conf"
include "conf.d/expire.conf"

修改fastcgi配置

sudo vim /etc/lighttpd/conf.d/fastcgi.conf

添加fastcgi配置如下:

fastcgi.server = ( ".php" =>
               ( "php-local" =>
                 (
                   "socket" => socket_dir + "/php-fastcgi-1.socket",
                   "bin-path" => "/usr/bin/php-cgi",
                   "max-procs" => 1,
                   "broken-scriptfilename" => "enable",
                 )
               ),
               ( "php-tcp" =>
                 (
                   "host" => "127.0.0.1",
                   "port" => 9999,
                   "check-local" => "disable",
                   "broken-scriptfilename" => "enable",
                 )
               ),
               ( "php-num-procs" =>
                 (
                   "socket" => socket_dir + "/php-fastcgi-2.socket",
                   "bin-path" => "/usr/bin/php-cgi",
                   "bin-environment" => (
                     "PHP_FCGI_CHILDREN" => "16",
                     "PHP_FCGI_MAX_REQUESTS" => "10000",
                   ),
                   "max-procs" => 5,
                   "broken-scriptfilename" => "enable",
                 )
               ),
            )

启动lighttpd

sudo /etc/init.d/lighttpd start

在/var/www/htdocs/下添加文件index.html, 文件内容 hello world

访问 http://127.0.0.1/ 能看到hello word则搭建完成

若提示无法连接,则需要检查服务器防火墙是否开启了对80端口的访问允许,查看iptables

sudo vim /etc/sysconfig/iptables

添加如下规则

-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT

保存,然后重启iptables

sudo service iptables restart

再次尝试访问 http:/127.0.0.1 应该可以看到hello world页面

mongodb 安装:

通过yum命令安装,但是需要单独设置yum的repo

在/etc/yum.repos.d/新建 mongocdb.repo文件

对于64位系统文件内添加如下内容(32位则将x86_64换为i686):

[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

保存后执行

sudo yum install mongodb-org

完成mongodb安装

启动

sudo service mongod start

启动成功后可在命令行使用 mongo命令连接mongodb

rockmongo 安装:

下载rockmongo-v1.1.7.zip 包解压

unzip -d rockmongo rockmongo-v1.1.0.zip
cp -r rockmongo /var/www/htdocs/

安装php-mongo

sudo pecl install mongo

出现提示后输入 yes

安装完成后,在php.ini中添加

extension=mongo.so

重启lighttpd

sudo service lighttpd restart

访问http://127.0.0.1/rockmongo 可以看到rockmongo的登录界面

mysql 安装:

命令行安装

sudo yum install mysql -y
sudo yum install mysql-server -y
sudo yum install mysql-devel -y

启动mysql

sudo service mysqld start

修改root密码

mysqladmin -u root password “newpassword”

删除匿名用户

mysql -uroot -p
MySQL> delete from mysql.user where User=“";
MySQL> FLUSH PRIVILEGES;

安装handlersocket(最新版本已无需安装该插件):

下载安装包并解压,进入目录

./autogen.sh
./configure --with-mysql-source=/home/czj/download/mysql-5.1.73 \
--with-mysql-bindir=/usr/bin \
--with-mysql-plugindir=/usr/lib64/mysql/plugin

--with-mysql-source 为mysql源码路径

--with-mysql-bindir 为mysql二进制可执行文件路径

--with-mysql-plugindir 为mysql插件路径

yum安装的mysql可以使用

先用rpm -qa *mysql*看看你安装了哪些包,然后用 rpm -ql xxxxxxx 去查看具体的包安装位置

然后执行

make
sudo make install

查看plugin目录下是否有handlersocket插件

到此插件编译完成

在mysql中启用插件:

在mysql配置文件/etc/my.cnf中增加如下配置:

[mysqld]
#*********** HandlerSocket setting ***********
loose_handlersocket_port = 9998
# the port number to bind to (for read requests)
loose_handlersocket_port_wr = 9999
# the port number to bind to (for write requests)
loose_handlersocket_threads = 16
# the number of worker threads (for read requests)
loose_handlersocket_threads_wr = 1
# the number of worker threads (for write requests)
open_files_limit = 65535
# to allow handlersocket accept many concurrent
# connections, make open_files_limit as large as
# possible.

重启mysql

sudo service mysqld restart

用root用户登录后
安装handlersocket插件:

mysql> install plugin handlersocket soname "handlersocket.so";
Query OK, 0 rows affected (0.00 sec)

可以通过show plugin查看是否安装成功

如果9998和9999端口没有在使用,则需要关闭selinux

相关文章

网友评论

    本文标题:开发环境搭建指南

    本文链接:https://www.haomeiwen.com/subject/vjzthttx.html