云开发环境
本文于 2268 天之前发表,文中内容可能已经过时。
一直为开发环境的选择烦恼着,以前使用的是虚拟机。配置lnmp开发环境,其实如果只是在一台机子上折腾,虚拟机的开发环境是很好的。由于开发的时候还涉及到回家调试的问题,自己的电脑又不想天天携带者,所以以前的虚拟机步骤很少痛苦。那时候就在想,什么时候能有云虚拟主机。
自己上传vm文件到git的形式尝试过,文件太大了,更新起来很麻烦的。
前一段时间阿里云促销,所以直接买了三年的服务器。有一个想法就是布置一个云开发环境。
好处: 使用阿里云的镜像备份可以方便的管理自己版本的镜像,这个速度很快,推荐推荐!有网的地方就可以进行调试。
环境搭建
lnmp搭建
使用的系统centos6.9,貌似centos6用的人比较多。
lnmp搭建有很多方法,比较推荐使用源码的方式进行安装,软件都不是太大,编译的速度都挺快的。编译安装对于软件和配置文件的摆放都可以随心,这一点挺好的。软件统一放到/usr/src目录下1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47cd /usr/src
wget http://am1.php.net/distributions/php-5.6.30.tar.gz
tar zxvf php-5.6.30.tar.gz
cd php-5.6.30
依赖安装
yum -y install gd-devel pcre-devel libxml2-devel libjpeg-devel libpng-devel libevent-devel libtool* autoconf* freetype* libstd* gcc44* ncurse* bison* openssl* libcurl* libcurl* libmcrypt*
根据所需安装扩展
./configure --prefix=/usr/local/php \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-sysvshm \
--enable-sysvmsg \
--enable-inline-optimization \
--with-curl \
--with-mcrypt \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-ftp \
--without-pear \
--enable-opcache
make && make install
1 | cp ./php.ini-development /usr/local/php/lib/php.ini |
添加到系统1
2
3
4
5
6
7
8
9
10
11
12cp /usr/src/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod a+x /etc/init.d/php-fpm
# 添加到init.d服务中
chkconfig --add php-fpm
# 设置服务自动运行
chkconfig php-fpm on
ln -s /usr/local/php/bin/php /usr/bin/php
ln -s /usr/local/php/sbin/php-fpm /usr/bin/php-pfm
# 配置语法检测
php-pfm -t
service php-fpm start
mysql
配置用户组和文件夹1
2
3
4
5
6
7
8
9
10
11# mysql运行用户
$ groupadd mysql
$ useradd mysql -g mysql -M
$ mkdir -p /usr/local/mysql
$ mkdir -p /usr/local/mysql/data
$ chown -R mysql:mysql /usr/local/mysql
$ vi /etc/profile
# profile追加如下内容
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
$ source /etc/profile
下载安装1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.41.tar.gz
tar zxvf mysql-5.6.41.tar.gz
cd mysql-5.6.41
yum -y install ncurses-devel perl ncurses-devel bison-devel
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost \
make && make install
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
根据需求进行配置
[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
character_set_server=utf8
init_connect='SET NAMES utf8'
# 开发机设置为远程可以访问的
bind=0.0.0.0
... ...
[client]
default-character-set=utf8
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig mysqld on
service mysqld start
初次进入设置密码提示 其他的操作也做不了
SET PASSWORD = PASSWORD('123456');
GRANT ALL PRIVILEGES ON *.* TO root@"%" WITH GRANT OPTION;
FLUSH PRIVILEGES;
nginx安装
准备1
2
3
4
5
6
7
8
9# 用户
$ groupadd www
$ useradd -g www www -s /bin/false -M
# 依赖
$ yum -y install pcre* opensll*
$ wget http://nginx.org/download/nginx-1.7.8.tar.gz
$ tar zxvf nginx-1.7.8.tar.gz
$ cd nginx-1.7.8
安装1
2
3./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre
make && make install
系统服务1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53vi /etc/init.d/nginx
# 追加入如下内容
#!/bin/bash
# chkconfig: - 85 15
# description: Nginx is a World Wide Web server.
# processname: nginx
nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done"
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done"
;;
test)
$nginx -t -c $conf
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done"
;;
restart)
echo -n "Restart Nginx"
$0 stop
sleep 1
$0 start
echo " done"
;;
show)
ps -aux|grep nginx
;;
*)
echo -n "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac
# 保存并退出
$ cd /etc/init.d
$ chmod +x nginx
$ chkconfig --add nginx
$ chkconfig --level 2345 nginx on
$ chkconfig nginx on
# 检测配置
$ service nginx test
$ service nginx start
php-fpm和nginx的关联
1 | 有sock和listen两种配置模式 |
重新启动lnmp,一般就可以运行了。出现问题的时候再具体调试。
其他一些安装
composer可以参照官网进行安装,一般可以运行php -v就可以安装成功,基本上都是成功的;
nodejs安装
安装nodejs费的时间最多,而且特别繁琐。也可以直接使用rpm进行安装。本人也是安装了一次,备份了镜像方便以后使用的。node安装顺利的话估计要一个个小时,gcc编译升级就要两个小时。好慢的。
安装nodejs会提示安装gcc版本低,所以首先要进行gcc升级
1 | wget http://gcc.skazkaforyou.com/releases/gcc-4.9.1/gcc-4.9.1.tar.gz |
编译安装之后,默认的gcc库还是没有替换的,所以要手动替换一下1
2
3
4
5
6strings /usr/lib/libstdc++.so.6 | grep GLIBCXX
find / -name "libstdc++.so.6"
cp /usr/local/src/gcc-4.9.1/gcc_temp/stage1-i686-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6 /usr/lib
64位的操作系统,文件是不一样的 /usr/lib64
strings /usr/lib/libstdc++.so.6 | grep GLIBCXX
node安装1
2
3
4
5
6
7
8
9$ cd /usr/src/
$ wget https://nodejs.org/dist/v6.9.1/node-v6.9.1.tar.gz
$ tar zxvf ./node-v6.9.1.tar.gz
$ cd ./node-v6.9.1
$ mkdir /usr/local/node
$ ./configure --prefix=/usr/local/node
$ make && make install
node环境配置1
2
3
4
5
6#set for nodejs
$ export NODE_HOME=/usr/local/node
$ export PATH=$NODE_HOME/bin:$PATH
$ source /etc/profile
$ node –v