Unbutu学习记录

来源:互联网 发布:抛硬币实验数据 编辑:程序博客网 时间:2024/06/07 06:53

目录

  • 目录
    • 命令
    • 过程
      • Vim
      • Flash
      • Php
      • Jdk
      • Memcached服务器
      • PHP-Memcached扩展
      • Apache Httpd
      • Httpd 和 Php 结合
      • Httpd 多站点配置
      • 安装 PhpStorm
      • 在 PhpStorm 中配置以 apache 服务器运行
      • PHP-Debug扩展
      • PHP-Pdo-mysql扩展
      • 安装 Sublime
      • PHP-OpenSSL扩展
      • 安装 Composer
      • 安装 Git
      • 安装 Nginx
      • Nginx 和 PHP 结合
    • 快捷键

命令

  • ls:-a / -l
  • cd
  • pwd
  • clear
  • sudo
  • mkdir [dirname]
  • touch [filename]
  • which [file]:查找文件目录
  • apt-get install [soft]
  • apt-cache search [soft]
  • grep [text]
  • ifconfig
  • ps (-e 显示全部 / -f 全格式):显示进程
  • pkill [进程名称]:杀进程

过程

Vim

  • apt-get install vim -y

Flash

  • apt-get install flashplugin-installer

Php

  1. 依赖: apt-get install libxml2-dev -y
  2. 在 php.net 下载 php 到 /usr/txl/DownLoads,打开终端
  3. ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/conf
  4. make & make install

Jdk

  1. apt-get install default-jdk -y
  2. Test:java -showversion

Memcached服务器

  1. 依赖:apt-get install libeventdev -y
  2. 在 memcached.org 下载,打开终端
  3. ./configure --prefix=/usr/local/memcached
  4. make & make install
  5. 运行进程:/usr/local/memcached/bin/memcached -d -m 512 -u txl -l 127.0.0.1 -p 11211 -c 1024 -P /usr/local/memcached/memcached.pid

    -d:以守护进程运行
    -m:分配内存
    -l:连接ip地址
    -p:端口
    -c:并发连接数
    -P:Pid文件

  6. Test:telnent 127.0.0.1 11211
    set key flags 过期时间 bytes
    value
    get key

PHP-Memcached扩展

  • 依赖
    1. autoconf:生成配置脚本工具
      • apt-get install autoconf -y
      • ./configure
    2. phpize:默认在 php/bin 目录下,用于添加扩展
    3. zlib:压缩函数调用库
      • apt-get install zlib1g-dev
  • libmemcached(客户端)
    1. 在 libmemcached.net 下载,解压到 /home/txl/tool 中,打开终端
    2. ./configure
    3. make & make install
  • PHP-Memcached扩展
    1. 安装Git工具:apt-get install git -y
    2. 进入 /home/txl/tool 中,git clone https://github.com/php-memcached-dev/php-memcached.git
    3. 切换到php7分支:git checkout php7
    4. 生成:phpize
    5. ./configure –with-php-config=/usr/local/php/bin/php-config –disable-memcached-sasl
    6. make & make install
  • Php配置文件
    1. 在 php/bin/php-config脚本中找到 –with-config-file-path=/usr/local/php/conf ,说明 php 会在该文件夹下寻找 php.ini
    2. 拷贝模板配置文件到 php 配置文件目录
      cp /home/txl/DownLoads/php7/php.ini-development /usr/local/php/conf/php.ini
    3. 给 php.ini 赋予权限
      sudo chown txl:txl php.ini
    4. 在 php.ini 中添加 memcached 扩展
      echo 'extension="memcached.so"' >> /usr/local/php/conf/php.ini
    5. Test:php -m

Apache Httpd

  1. 依赖
    • PCRE:apt-get install libpcre3-dev -y
    • Libexpat: apt-get install libexpat1-dev
    • APR:在 apr.apache.org 下载,打开终端
      ./configure --prefix=/usr/local/apr
      make & make install
    • APR-Util:在 apr.apache.org 下载,打开终端
      ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  2. 在 httpd.apache.org/download.cgi 下载,打开终端
  3. ./configure --prefix=/usr/local/httpd --with-apr-util=/usr/local/apr-util
  4. make & make install
  5. 启动:/usr/local/httpd/bin/apachectl

Httpd 和 Php 结合

  • 联合Php模块重新编译Apache
    1. 进入 Apache 源代码目录,打开终端
    2. ./configure --prefix=/usr/local/httpd --enable-so --with-apr-util=/usr/local/apr-util
    3. make & make install
  • 安装 libiconv

    1. 在 www.gnu.org/software/libiconv 下载,打开终端
    2. ./configure --prefix=/usr/local
    3. make & make install

      在 Ubuntu16 中编译有可能会出错,解决方案:

      1. 打开 libiconv/srclib/stdio.h
      2. 搜索 gets is a security hole,将这一行替换为:
        #if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
        _GL_WARN_ON_USE(gets, "gets is a security hole - use fgets instead");
        #endif
    4. 安装后的iconv库位置:/usr/local/lib/libiconv.so

    5. 刷新动态链接库缓存:sudo ldconfig
  • 重新编译Php
    1. 进入Php源代码目录,打开终端
    2. ./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/conf –with-apxs2=/usr/local/httpd/bin/apxs –with-iconv-dir=/usr/local/lib
    3. make ZEND_EXTRA_LIBS='-liconv'
    4. make install
  • 修改 Httpd 配置
    1. 安装过程中,系统会自动拷贝 /usr/local/httpd/modules/libphp7.50
    2. 在 httpd.conf 中系统会自动加入 LoadModule php7_module modules/libphp7.50
      手工在下面添加:AddType application/x-httpd-php .php
    3. 重启 httpd:sudo /usr/local/httpd/bin/apachectl restart

Httpd 多站点配置

  1. 修改 httpd.conf,添加Listen 8090
  2. 添加:
<VirtualHost *:8090>    DocumentRoot /home/txl/phpstormProjects/test    ServerName localhost:8090    DirectoryIndex index.php    <Directory "/home/txl/phpstormProjects/test">        Options FollowSymLinks        Require all granted    </Directory></VirtualHost>  
  1. 重启 Httpd

安装 PhpStorm

在 PhpStorm 中配置以 apache 服务器运行

PHP-Debug扩展

  1. git clone git://github.com/xdebug/xdebug.git
  2. phpize
  3. ./configure
  4. make & make install
  5. 在 php.ini 中添加扩展:
zend_extension=xdebug.so xdebug.remote_enable=On xdebug.remote_handler=dbgp xdebug.remote_host=localhostxdebug.remote_port=9000 // 和 PhpStorm 中对应 xdebug.idekey=phpstorm // 和 PhpStorm 中对应
  1. 重启 Apache
  2. 在 Phpstorm 中设置,略

PHP-Pdo-mysql扩展

  1. 进入 PHP 源代码目录,打开终端
  2. make clean
  3. ./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/conf –with-apxs2=/usr/local/httpd/bin/apxs –with-iconv-dir=/usr/local/lib –enable-mysqlnd –with-pdo-
    mysql=mysqlnd
  4. make ZEND_EXTRA_LIBS='-liconv'
  5. make install
  6. 在 php.ini 中添加扩展:extension=pdo_mysql.so
  7. 重启 Apache

安装 Sublime

  1. 在 www.sublimetext.com/3 中下载,打开终端
  2. 安装:sudo dpkg -i xxx.deb
  3. 配置为 php 运行:Tools -> Build System -> new Build System,写入:{"cmd":["/usr/local/php/bin/php", "$file"]}
  4. 运行 ctrl + b,隐藏/显示侧栏:ctrl + k ctrl + b

PHP-OpenSSL扩展

  1. 进入 Php 源码目录 /ext/openssl,打开终端
  2. cp config0.m4 config.m4
  3. phpize
  4. ./configure --with-php-config=/usr/local/php/bin/php-config --with-openssl

    如果报错 configure:error Cannot find OpenSSL’s >evp.h<,解决方案:
    sudo apt-get install openssl
    sudo apt-get install libssl-dev

  5. 在 php.ini 中添加扩展:extension=openssl.so

安装 Composer

  • 下载
    1. wget https://getcomposer.org/composer.phar
    2. mv composer.phar composer
    3. sudo chmod+x composer
    4. mv composer /usr/local/bin
    5. 测试:composer
  • 初始化
    1. 新建 PHP 项目文件夹
    2. 在当前项目文件夹下执行 composer init,根目录会自动生成一个composer.json,大概格式

      ”autoload”:{
      “files”:[“common/function.php”],
      “classmap”:[“C/”]
      }

    3. 在当前文件夹下执行 composer dump-autoload,然后会生成一个vendor文件夹,里面有一个 autoload.php,只需在需要的页面中引入 autoload.php
    4. 安装外部库:在 composer.json 中添加:
      “require”:{
      “vrana/notorm”:”dev-master”
      }
      然后执行:composer install
  • 镜像

    • 安装国内镜像源:进入项目根目录(也就是 composer.json 所在的目录),执行:composer config repo.packagist composer https://packagist.phpcomposer.com,也可以在 composer.json 的末尾手工添加:

      “repositories”: {
      “packagist”: {
      “type”: “composer”,
      “url”: “https://packagist.phpcomposer.com”
      }
      }

    • 官方镜像列表:packagist.org

安装 Git

  • 下载
    1. sudo apt-get install git
    2. 测试:git --version
  • 起始配置

    1. git config --global user.email "1297441127@qq.com"
    2. git config --global user.name "txl"

    –global表示全局配置,任何仓库提交都会使用这个身份来识别

  • 进入项目文件夹

    1. 创建一个空的版本仓库:git init
    2. 加入仓库:git add * 或者 git add xxx.php
    3. 提交:git commit -m "注释内容"
  • 和 github 关联(sssh地址)
    1. git remote add 别名 git@github.com:xxx/xxx.git
    2. 生成密码:ssh-keygen -t rsa -C "1297441127@qq.com"
    3. 查看密码:cat /home/txl/.ssh/id_rsa.pub,在 github 中添加 SSHkeys
    4. git push 别名 master 提交文件
  • 在 PHPStorm 中操作 git,略
  • 在 Packagist.org 中上传代码,略

安装 Nginx

  1. 在 nginx.org 下载 nginx,打开终端
  2. ./configure --prefxi=/usr/local/nginx
  3. make & make install
  4. 配置:/usr/local/nginx/conf/nginx.conf
  5. 运行:sudo /usr/local/nginx/sbin/nginx

Nginx 和 PHP 结合

  1. 进行 php 源码目录,打开终端
  2. make clean
  3. ./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/conf –with-apxs2=/usr/local/httpd/bin/apxs –with-iconv-dir=/urs/local/lib –enable-mysqlnd –with-pdo-mysql=mysqlnd –enable-fpm
  4. make ZEND_EXTRA_LIBS='-liconv'
  5. make install
  6. php/sbin 下会有一个 php-fpm文件
  7. php/etc 下有一个配置文件:php-fpm.conf.default,拷贝出来:cp php-fpm.conf.default php-fpm.conf,修改参数:

    pid=run/php-fpm.pid
    error_log=log/php-fpm.log
    log_level=notice
    daemonize=yes ;以守护进程运行

  8. 进入 php/etc/php-fpm.d,修改 www.conf :

    listen=127.0.0.1:9000
    user=txl
    group=txl

  9. 启动 FPM:进入 php/sbin,执行 sudo ./php-fpm

  10. 修改 nginx/conf/nginx.conf,添加:
location ~*\.php$ {      root   html;      fastcgi_pass 127.0.0.1:9000;      include /usr/local/nginx/conf/fastcgi_params;      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;}

最后重启 nginx:进入 nginx/sbin,执行 sudo ./nginx -s reload

快捷键

  • 终端 (Terminal):ctrl + alt + t
原创粉丝点击