技术控

    今日:36| 主题:49507
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] The Perfect Web Development Environment for Your New Mac

[复制链接]
胭脂ㄨ 发表于 2016-9-30 21:24:25
108 4

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
This version of the tutorial works with macOS Sierra (10.12), OS X El Capitan (10.11), OS X Yosemite (10.10), or Mavericks (10.9) and uses Homebrew as a package manager. I streamlined this tutorial in August 2014 to make it even easier to set up your development environment. I’ve archived theoriginal version. In January 2016, I added support for xip.io , which is a DNS redirecting service. This allows you to access your local sites from any device on your network.
  I’ve been using this particular configuration, or one quite like it, for several years, but when I picked up a new laptop recently, I decided to start from scratch. There were a ton of settings, scripts, and programs installed on my old machine that I no longer used, and I wanted them gone.
  Feel free to use this guide on any Mac, but you may find that there are differences on your machine if it’s not a fresh install of OS X. These are the exact steps I used to get things running on my machine, and it’s been tested on many machines.
  Why Not Just Use MAMP?

   MAMP is a package that will install MySQL, PHP, and Apache on your Mac all with one download, and a quick install. It’s a great option and MAMP Pro, the paid version, will provide most of the features you need to run multiple web sites on your machine. I don’t use it because most of what it offers is already a part of OS X, and I prefer to customize my environment beyond what MAMP provides out of the box. If I’m already going to be playing around with the config files, I may as well go the distance. The main benefit of MAMP is that it leaves all your default system settings alone, sandboxing your development environment. I don’t get any benefit out of that. It also allows you to easily turn on and off services. I don’t ever turn them off, so that’s not any help to me either.
  Housekeeping

   Mac OS X  is a great operating system for developers, but many of the features important to us are turned off to make the OS more easy to use for everyday tasks, and more secure. Many of the configuration files we need to edit are hidden away in directories that do not show up in the Finder by default. I’m not going to tell you how to edit files here. Some people prefer command-line tools like Vim or Pico . For most of my code editing needs, I use Sublime Text . It’s not free, but I find the features well worth the price. If you’re going to be using a text editor every day, you’re going to want to pay for a good one. Sublime Text can open files like any other GUI text editor, and can also be invoked from the command line . Make sure you’re familiar with editing config files in the text editor of your choice before continuing.
  Everything we’ll be installing here is free, and you can certainly go a long way without having to pay a cent for any of your software. However, don’t be afraid to pay actual money for great apps. If you’ve bought a Mac, you already understand that spending money on a well designed product usually saves you time in the long run. Software works the same way. Below are some of the programs I use regularly.
     
The Perfect Web Development Environment for Your New Mac-1 (latex,newenvironment,newenvironment,give,me,your,perfect,your,perfect,right,baby,your,perfect)
        CodeKit (Front End Toolbox)
     Coda / Sublime Text / Atom (Great IDEs / Text Editors)
     Navicat (MySQL GUI)
           Transmit (The best FTP program ever made)
     Tower (Git Manager)
       Xcode

   First, you need to have Xcode (Apple’s development bundle) installed for a few of these tools to work. You can get by without it if you try really hard, but if you’re a developer, you’re probably going to need to have it at some point. It’s massive, so start downloading it now. Grab it from the App Store, and then grab a coffee or play with your kid or dog.
   For OS X 10.9 (Mavericks) and up, the developer command line tools can be installed by running the following command within terminal.
  [code]xcode-select --install[/code]   This will trigger a software update dialog box. Click install and wait for it to complete. If this does not work, download the installation package from Apple . You will need an Apple developer account to do this.
  Once Xcode is installed, start it up. The tools we need will not work unless the app has run once, and you’ve accepted the licence agreement. You don’t need to do anything with the app. Just start it up (It can take a while to run the first time, even on a fast machine) click agree, and shut it down.
  Homebrew

   Homebrew is a popular and amazing package manager for OS X. Package managers keep all the big and small tools that we need to install on our machines tidy and up-to-date. It could not be easier to install. Switch over to your terminal, and type in this one command:
  [code]ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"[/code]  It can take a while for the install, but that one command is all you need for Homebrew. Really.
  MySQL

   This is optional. You may prefer another kind of database, or no database at all. Feel free to skip this if you don’t need it, but really, you probably do. MySQL no longer comes pre-installed as of Mountain Lion (10.8) as it did with previous versions or OS X. Download it here . You can try the latest version of MySQL for the latest version of OS X. The latest version is currently for 10.11. Choose the 64bit “DMG Archive” one.

The Perfect Web Development Environment for Your New Mac-2 (latex,newenvironment,newenvironment,give,me,your,perfect,your,perfect,right,baby,your,perfect)

  dnsmasq

  This is a great little tool to that allows us to use wildcard subdomain names.
  With the default apache settings, you can add as many sites as you like in subfolders of the web root. You can have sites like this:
  http://home.dev/client1
  http://home.dev/client2
  http://home.dev/client3
   However, that creates a problem. When you have each site in a folder, it’s more difficult to manage the settings for each site. Each one must then have a different absolute root . The solution is to create a subdomain for each site, and use URLs like these:
  http://client1.dev
  http://client2.dev
  http://client3.dev
   We can accomplish this by placing all three sites in our /private/etc/hosts file, but then we need to keep adding entries every time we add a new site. dnsmasq allows us to do this by interrupting each request that ends with .dev and forwarding it to a designated IP address (127.0.0.1 in our case).
  To install dnsmasq, we use the previously installed Homebrew. The following commands will install dnsmasq, configure it to point all requests to the .dev top-level domain to our local machine, and make sure it starts up and runs all of the time.
  [code]brew install dnsmasq
cd $(brew --prefix)
mkdir etc
echo 'address=/.dev/127.0.0.1' > etc/dnsmasq.conf
sudo cp -v $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
sudo mkdir /etc/resolver
sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/dev'[/code]  We’re now done with dnsmasq, and if all goes well, you’ll never need to think about it again. Now, to get Apache going.
  Your Local Web Root

   Apache has a default location for storing website files, but I prefer to create my own web root that is independent of Apache. You can place your files anywhere you wish, but I prejust put them in a directory called /www on my main hard drive. Put yours wherever you wish. In that folder, I have a few subfolders. /www/home is a main website that I use to list all my local sites (I’ll show you how to make that site dynamic later on).   /www/sites is the folder in which I place each of my other sites. Each of those site folders has a webroot ( /www/sites/client1/wwwroot ), and an assets folder ( /www/sites/client1/assets ), where I keep source files or other documents related to the site.
  Apache

  Step one is easy. It’s actually almost done. Mountain Lion (10.8) was the first version of OS X without Apache in the “sharing” section of the preferences pane. No big deal though, since you just need to start it up once using the terminal. Open up the Terminal app, and enter the following command. You’ll be asked for your administrator password.
  [code]sudo apachectl start[/code]   That’s it. Test it out by visiting http://localhost in your browser. You should see a simple page that says “It Works”. Apache is up and running, and is ready to serve your sites. It will stay on until you turn it off (I never turn it off), and will start up automatically each time you start your computer. Don’t worry about taxing your computer’s resources by running Apache. It won’t be a problem.
   You should also try http://home.dev , which should work since dnsmasq is pointing all *.dev domains to the local IP. You can try  http://ANYTHING.dev as well.
   Apache will serve up sites as is, but there are a few quick changes we need to make to the configuration files before we are ready to go. Using your favorite text editor, open up /private/etc/apache2/httpd.conf
  If you’re going to be using PHP, you need to tell Apache to use the PHP module to handle .php files. On line 169 (line 117 before 10.10 (Yosemite) but could be different on your system), you need to uncomment this line (remove the “#”)
  [code]168  #LoadModule perl_module libexec/apache2/mod_perl.so
169  #LoadModule php5_module libexec/apache2/libphp5.so
170  LoadModule hfs_apple_module libexec/apache2/mod_hfs_apple.so[/code]  becomes
  [code]168  #LoadModule perl_module libexec/apache2/mod_perl.so
169  LoadModule php5_module libexec/apache2/libphp5.so
170  LoadModule hfs_apple_module libexec/apache2/mod_hfs_apple.so[/code]     Yosemite, El Capitan, & Sierra Only
   Starting with OS X 10.10 (Yosemite), Apple moved from Apache 2.2 to Apache 2.4, and that means there are a few additional changes we need to make. First, there is a directive that helps secure your machine by denying access to the entire file system by default. I’ll show you how to remove this directive, since I find that easier on a machine meant for development. The section of code runs from line 220 through 223. You can comment out (place ‘#’ in front of each line) or just remove this section.
   [code]220
221     AllowOverride none
222     Require all denied
223
[/code]    Then, the mod_vhost_alias module needs to be activated. We must uncomment line 160, so:
   [code]159  #LoadModule dav_lock_module libexec/apache2/mod_dav_lock.so
160  #LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
161  LoadModule negotiation_module libexec/apache2/mod_negotiation.so[/code]   becomes
   [code]159  #LoadModule dav_lock_module libexec/apache2/mod_dav_lock.so
160  LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
161  LoadModule negotiation_module libexec/apache2/mod_negotiation.so[/code]    and on line 509 (line 500 in Yosemite and El Capitan, and line 477 before Yosemite), in order to allow us to add multiple websites to Apache:
  [code]508  # Virtual hosts
509  #Include /private/etc/apache2/extra/httpd-vhosts.conf
510[/code]  becomes
  [code]ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"0[/code]   This tells apache to load the information in the httpd-vhosts.conf file in the /private/etc/apache2/extra/ directory. We need to edit that file. You can delete or comment out everything in that file, and replace it with the following:
  [code]ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"1[/code]  Then run the following to force Apache to load your new config files:
  [code]ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"2[/code]   This configuration allows you to use the URL http://client1.dev on your local machine with your site files stored in /www/sites/client1/wwwroot . It also allows you to use the service xip.io to use the URL http://client1.[LOCAL IP].xip.io to access your sites from another machine (or device) on your local network. So, if your machine’s local IP address (not your public IP address), is 192.168.1.10, the URL for a site might be http://client1.192.168.1.10.xip.io . You can find your local IP address in your network preferences.
   Xip.io is offered for free by Basecamp and provides one of the simplest services on the internet. They run a simple DNS server that redirects all traffic to *.xip.io back to the IP address indicated by the subdomain.
  Now you don’t need to update config files every time you add a new site. Simply add the necessary folders to your “sites” directory, and the site will work locally with its own subdomain.
  A Custom Home Page

  Now that you have a bunch of local sites running on your machine, you can bookmark them all, or you could do something fancy, and create your own custom home page that lists all the sites currently available on your machine.
12下一页
友荐云推荐




上一篇:使用 iOS 10 的 Speech 框架构建语音转文本应用
下一篇:Unit testing React Native with Jest
酷辣虫提示酷辣虫禁止发表任何与中华人民共和国法律有抵触的内容!所有内容由用户发布,并不代表酷辣虫的观点,酷辣虫无法对用户发布内容真实性提供任何的保证,请自行验证并承担风险与后果。如您有版权、违规等问题,请通过"联系我们"或"违规举报"告知我们处理。

yrgd 发表于 2016-10-1 04:14:56
不错 支持下
回复 支持 反对

使用道具 举报

莪依旧凄凉 发表于 2016-10-2 20:49:16
最伤人的话,总出自最温柔的嘴。
回复 支持 反对

使用道具 举报

刘述平 发表于 2016-10-8 17:21:12
嘘,低调。
回复 支持 反对

使用道具 举报

Finale 发表于 2016-11-20 06:14:04
有钱的捧个钱场,没钱的回家拿钱捧个钱场。
回复 支持 反对

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表手机版
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )|网站地图 酷辣虫

© 2001-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表