profile配置

1
2
3
4
5
6
7
8
9
PS1='[\u@\H] \W \[\033[012;36m\]\$\[\033[00m\] '

export LS_OPTIONS='--color=auto' # 如果没有指定,则自动选择颜色
export CLICOLOR=1 #是否输出颜色
# export LSCOLORS='Exfxcxdxbxegedabagacad'
export LSCOLORS='dxfxcxdxgxegedabagacad'

alias ll='ls -l'
alias lal='ls -al'

MAC安装Pygame

  1. 安装pygame依赖包:brew install hg sdl sdl_image sdl_ttf,如果想启动更高级的功能,如在游戏中包含声音,可安装下面的两个额外的库:brew install sdl_mixer portmidi
  2. 安装Pygame:pip3 install --user hg+http://bitbucket.org/pygame/pygame,如果报错可以尝试:pip3 install pygame
  3. 验证 Pygame 是否安装成功,可以启动一个Python终端,输入:import pygame

mac下php版本切换

brew安装php-version

1
2
3
4
5
6
7
# brew install php56
# brew install php70
# brew install php-version
# source $(brew --prefix php-version)/php-version.sh

# php-version
# php-version 5.6.5

php开机启动

1
2
3
4
# mkdir -p ~/Library/LaunchAgents
# cp /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/
# launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
# launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

切换本机php版本

1
2
3
// 先确认phpinfo里面的php版本,先卸载5.6的plist,在加载7.1的plist
# launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
# launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist

添加php额外配置,引入php扩展

phpinfoScan this dir for additional .ini files 配置参数是php扩展配置路径。

你可以在该路径下,配置文件结尾为.ini的文件作为你的额外配置参数。

我们可以利用它来更好的管理我们php的扩展的相关配置:

引用pdo_pgsql扩展
extension="/usr/local/opt/php71-pdo-pgsql/pdo_pgsql.so"

PHP扩展安装

  1. brew、yum或者apt-get安装

  2. 使用pecl安装

    mac安装pecl

    1. 下载pecl curl -O https://pear.php.net/go-pear.phar

    2. 安装pecl

      1
      2
      3
      4
      5
      6
      php -d detect_unicode=0 go-pear.phar

      执行以上命令后会进行安装过程,会有一些配置选项:
      输入 1,将安装根目录修改为 /usr/local/pear;
      输入 4,将命令安装到 /usr/local/bin 目录;
      回车两次,其他让其默认,安装完成
    3. 检测是否安装成功 pear version

    pecl安装扩展

    1. pecl install mongodb
    2. 配置php.ini,通过运行 php --ini查找php.ini文件位置,然后在文件中添加extension=memcached.so
  3. phpize安装

    phpize运行可能需要安装autoconf:brew install autoconf

    1. 下载PHP扩展包:pecl库搜索

    2. 解压缩并进入扩展包目录

      1
      2
      tar -xzvvf redis-4.0.0.tgz
      cd redis-4.0.0
    3. 执行phpize phpize

    4. 执行./configure ./configure --with-php-config=/usr/bin/php-config

    5. make && make install,如果出现error: Cannot find OpenSSL's <evp.h>,可以尝试加上 --with-openssl-dir=/usr/local/opt/openssl@1.1

    6. 将生成的so文件复制到目录 /usr/local/opt/php@7.2/lib/php/20170718/

    7. 在php配置目录/usr/local/etc/php/7.2/conf.d,添加ini配置文件加入扩展配置

    8. 重启phpbrew services restart php@7.2

lnmp环境搭建

CentOS6.5

1.查看环境

1
# cat /etc/redhat-release

2.关掉防火墙

1
# chkconfig iptables off

3.配置CentOS 6.0 第三方yum源

1
2
3
# wget http://www.atomicorp.com/installers/atomic
# sh ./atomic
# yum check-update

4.安装开发包和库文件

1
# yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel

5.卸载已安装的apache、mysql、php

1
2
3
# yum remove httpd
# yum remove mysql
# yum remove php

6.安装nginx

1
2
3
4
# yum install nginx
# service nginx start
# chkconfig --levels 235 nginx on
//设2、3、5级别开机启动

7.安装mysql

1
2
3
4
5
6
7
8
9
10
11
12
# yum install mysql mysql-server mysql-devel
# service mysqld start
# chkconfig --levels 235 mysqld on

登陆MySQL删除空用户,修改root密码
mysql>select user,host,password from mysql.user;

mysql>drop user ''@localhost;

mysql>update mysql.user set password = PASSWORD('*********') where user='root';

mysql>flush privileges;

8.安装php

1
2
3
4
5
# yum install php lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap

# yum install php-tidy php-common php-devel php-fpm php-mysql
# service php-fpm start
# chkconfig --levels 235 php-fpm on

9.配置nginx支持php

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
在 /etc/nginx 下添加文件夹vhost,修改nginx.conf,在最后添加 “include vhost/*.conf;”

在vhost里面添加新增的配置

test.conf 如下:
server {
listen 80;
server_name test.local;

charset utf-8;
access_log /usr/local/var/log/nginx/test.local.access.log;
error_log /usr/local/var/log/nginx/test.local.error.log;

root /Users/vin/Code/test;

location / {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
try_files $uri $uri/ /index.php?$args;
index index.html index.htm index.php;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /Users/vin/Code/test$fastcgi_script_name;
include fastcgi_params;
try_files $uri =404;
}
}

10.重启nginx php-fpm

1
2
# service nginx restart
# service php-fpm restart

Ubuntu

1
# sudo apt-get update // 更新apt-get

1.Nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# sudo apt-get install nginx
// 启动nginx
# sudo /etc/init.d/nginx start
# sudo service nginx start

// 用socket进行通讯
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
}

// 然后再修改 PHP-FPM的配置文件 /etc/php/7.1/fpm/pool.d
; 与 Nginx监听同一个 sock
listen = /run/php/php7.1-fpm.sock

2.安装 PHP 7.1 与 PHP7.1-FPM

1
2
3
4
5
6
# sudo apt-add-repository ppa:ondrej/php   //使用PPA ppa:ondrej/php 库
# sudo apt-get update
# sudo apt-get install php7.1 php7.1-fpm

// php必备模块
# apt-get install php7.1-curl php7.1-xml php7.1-mcrypt php7.1-json php7.1-gd php7.1-mbstring

3.安装Mysql

1
# sudo apt-get –y install MySQL-server mysql-client php7.1-mysql

Mac

1.安装Homebrew

1
2
// 需要客户端安装ruby
# ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2.安装 Nginx 服务器

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
# brew install nginx

// 需要安装其他版本的nginx可以用以下命令来修改内容
# brew edit nginx

// 启动 nginx服务
# sudo nginx

// 重新加载配置|重启|停止|退出 nginx
# nginx -s reload|reopen|stop|quit

// 测试配置是否有语法错误
# nginx -t

// 指定某个配置文件启动
# nginx -c /usr/local/etc/nginx/nginx.conf

// 开机自启动nginx服务设置
# mkdir -p ~/Library/LaunchAgents
# cp /usr/local/Cellar/nginx/1.10.0/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
# launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

// 权限
# sudo chown root:wheel /usr/local/Cellar/nginx/1.10.0/sbin/nginx
# sudo chmod u+s /usr/local/Cellar/nginx/1.10.0/sbin/nginx

3.安装和配置 MySQL 服务器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# brew install mysql

// 配置命令
# mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql
# mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

// 启动
# ps -ef | grep mysql
# /usr/local/Cellar/mysql/5.7.12/bin/mysqld
# which mysqld

// 开机启动
# mkdir -p ~/Library/LaunchAgents/
# cp /usr/local/Cellar/mysql/5.7.12/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
# launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

// 停止服务
# launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

4.安装 PHP56 和 PHP-fpm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# brew install php56 --with-imap --with-tidy --with-debug --with-pgsql --with-mysql --with-fpm
# brew install php70 --with-imap --with-tidy --with-debug --with-pgsql --with-mysql --with-fpm

# export PATH="$(brew --prefix php56)/bin:$PATH"

// php-fpm开机启动 能在安装信息找到
# mkdir -p ~/Library/LaunchAgents
# cp /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/
# launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

// php版本切换
# brew install php-version
# source $(brew --prefix php-version)/php-version.sh
# php-version //查看版本
# php-version 5.6.5 //切换版本

// php扩展

# brew install php56-apcu php56-intl php56-redis php56-uuid php56-zookeeper
php56-thrift php56-solr php56-ssh2 php56-gmagick php56-kafka php56-libevent
php56-imagick php56-msgpack php56-geoip php56-mcrypt php56-swoole
php56-scrypt php56-xdebug php56-yaf php56-yaml php56-xhprof
php56-memcache php56-memcached php56-gearman