[Tutorial] Using DEVM to develop a PHP Program (1)

Source: Internet
Author: User
Tags ftp connection php development environment website server filezilla

DEVM (Developer & engineers' Virtual Machine) is a Virtual server image specially designed for website developers and maintenance personnel. Users can use vmplayer to run this image easily to simulate the website server environment, it is easy to develop your own applications.

This article describes in detail how to use DEVM as the PHP development environment. Considering the situation of most users, this article uses Windows7 as the development operating system.

For information about the latest DEVM version, see here: http://www.1308362.com/devm/12.11/release-info

1. Preface

Many programmers who develop PHP programs must be familiar with LAMP, but most PHP programs will be developed on Windows before being deployed on Linux servers due to some objective factors.

Those who develop PHP programs in Windows must be familiar with packages like Wamp/Xampp running AMPApache + Mysql + PHP in Windows. These software packages are easy to use. However, these software packages are not a real LAMP environment. Using these software packages is not conducive to developers to have a thorough understanding of the technical environment for program deployment and operation, therefore, when deploying a PHP system developed in Windows to Linux, you may encounter some problems, such as typical Path Problems and line breaks.

DEVM is a highly integrated Linux virtual machine image that provides a LAMP system that is very close to the real production environment. Devm lamp is composed of the latest gentoo linux, apache, mysql, php (fpm + apc. Since all the software in DEVM is fully customized and compiled, the performance is very powerful. After testing, the performance of DEVM far exceeds the performance gap of some Wamp/Xampp systems running on physical machines by more than 30 times ). With only MB of memory allocated, DEVM can provide a complete LAMP environment.

2. Preparation

If you want to experience DEVM, we need to make some preparations.

First, DEVM is based on vmware Virtual Machine images have kvm version, but not provided separately), so we need to first download a vmplayer to run this image: http://www.vmware.com/go/get-player-cn

Then we download DEVM, the image size after compression is about 270 MB,: http://pan.baidu.com/share/link? Consumer id = 111849 & uk = 3472985267

It takes about 2 GB of hard disk space to decompress DEVM. Because DEVM sets the virtual hard disk size to 8 GB by default, we recommend that you prepare 9 ~ 10 Gb hard disk space to store DEVM.

When developing PHP programs, we often use some commonly used tools. You can choose based on your habits or install the following software based on my suggestions:

  • Secure Shell Client, which facilitates the ssh Client for file exchange with virtual machines
  • Putty, a very useful ssh client
  • FileZilla, ftp client recommended
  • Notepad ++ is a simple and easy-to-use text development tool. It is good to edit PHP files.
  • Dreamweaver, well-known DW.
  • Eclipse + aptana and aptana are very friendly for PHP and website development, and provide ftp clients

If you are in trouble, install notepad ++ and filezilla to start using DEVM to develop php programs.

Dreamweaver and eclipse/aptana can be selected. dreamweaver is always very friendly to ftp-based Remote Server Management, and aptana also provides similar functions.

After preparing these software, we can get started.

3. Our goal

As the first step for everyone to familiarize themselves with PHP applications, many users will choose to install some ready-made open-source PHP systems, such as CMS systems. Therefore, in the following example, we will set the goal of the DEVM environment to two:

  • Install a drupal cms system and use site01.lo as the testing domain name for this system
  • Write a thinkphp-based website and use site02.lo as the testing Domain Name of the system

4. Environment Settings

First, start the DEVM image. After setting the DEVM parameter through vmplayer, you can directly run it.

DEVM can be started only with 1 CPU and 64 MB memory. However, we recommend that you allocate 256 MB or more memory by default, which is MB ). Generally, the memory usage after LAMP is run is about MB.

Remember the Virtual Machine IP address after you start DEVM. You can log on directly in the VM control window or by using ssh. The account used to log on to the DEVM is root and the password is 1308362. After logging on to ifconfig eth0, you can see the IP address. My name is 192.168.58.129.

Set the domain name for testing in Windows. Edit the hosts file under C: \ Windows \ System32 \ drivers \ etc and add two lines:

 
 
  1. 192.168.58.129  site01      site01.lo  
  2. 192.168.58.129  site02      site02.lo 

Edit/etc/hosts in the DEVM and add the two lines above.

The FTP user setting of DEVM supports local user logon. Therefore, you only need to add local users of the virtual machine to use FTP to log on to DEVM.

Command to add a user:

 
 
  1. devm ~# useradd site01 -m -G ftp,apache -s /bin/nologin  
  2. devm ~# passwd site01  
  3. devm ~# chmod a-w /home/site01  
  4. devm ~# mkdir -p /home/site01/wwwroot/{htdocs,cgi-bin}
  5. devm ~# chmod -R 777 /home/site01/wwwroot  
  6. devm ~# chown -R site01:site01 /home/site01 

The reason for chmod a-w is that vsftp does not allow users to write in the root directory, and all the website files to be uploaded are under/home/site01/wwwroot.

If there is a problem with the upload, it is usually the write permission problem. Run chmod-R 777 wwwroot in/home/site01. Of course, the management of read/write execution permissions can be stricter. This article will not go into detail.

The-G parameter is not followed by the users group, and the-s parameter is also followed by/bin/nologin. That is to say, this user is not used for system operations and cannot log on through ssh. If you want this user to log on to the VM,-G ftp, apache, users-s/bin/bash.

As for user site02, repeat the above operations. If you are in trouble, you can write a script named add_ftp_user.sh. The content is similar:

 
 
  1. #!/bin/bash  
  2.  
  3. if [ -z $1 ]; then  
  4.     echo "Warn: must specific a user name!" 
  5. else 
  6.     useradd $1 -m -G ftp,apache -s /bin/nologin  
  7.     passwd $1 
  8.     chmod a-w /home/$1
  9.     mkdir -p /home/$1/wwwroot/{htdocs,cgi-bin}  
  10. chmod -R 777 /home/$1/wwwroot
  11.     chown -R /home/$1 
  12. fi 

Run./add_ftp_user.sh site01;./add_ftp_user.sh site02.

Then we make settings on the client.

Open the site manager on FileZilla and create a site named site01.

General settings

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/12225a144-0.jpg "/>

At this time, we can also set the synchronization mechanism, that is, after the ftp connection, click the local directory, the remote directory will be synchronized and switched, this saves the trouble of manually keeping directories consistent remotely.

Assume that the local Windows Directory of the first website is d: \ devm \ site01. You can select "use synchronous browsing" in the advanced settings of the FileZilla website "):

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/12225921T-1.jpg "/>

After clicking connect, you should

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1222591063-2.jpg "/>

Because the htdocs directory is not created locally, an error is reported when you click the htdocs directory on the server on the right. As long as we create the htdocs directory under the Local site01 directory, we can see the role of synchronous browsing.

Next let's set up apache vhost so that we can access this URL through the http://www.site01.lo.

Since devm 2012.11 was released, I made some apache settings for the new, so you need to first get the latest configuration file on the https://github.com/goldeagle/devm/tree/master/share/profile/etc/apache2, override to/etc/apache2.

The default settings of site01 are provided in the/etc/apache2/vhost. d/directory. If a new vhost is added, you only need:

 
 
  1. <VirtualHost site01.lo:80> 
  2.     ServerName site01.lo  
  3.     ServerAlias www.site01.lo site01.lo site01  
  4.     ServerAdmin 1308362@gmail.com  
  5.     DocumentRoot "/home/site01/wwwroot/htdocs"  
  6.     <Directory "/home/site01/wwwroot/htdocs"> 
  7.         Options All  
  8.         AllowOverride None  
  9.         DirectoryIndex index.php index.html  
  10.     </Directory> 
  11.     ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/home/site01/wwwroot/htdocs/$1  
  12.  
  13.     <IfModule alias_module> 
  14.         ScriptAlias /cgi-bin/ "/home/site01/wwwroot/cgi-bin/"  
  15.     </IfModule> 
  16.  
  17.     <Directory "/home/site01/wwwroot/cgi-bin"> 
  18.         AllowOverride None  
  19.         Options None  
  20.         Require all granted  
  21.     </Directory> 
  22.  
  23.     <IfModule mpm_peruser_module> 
  24.         ServerEnvironment apache apache  
  25.     </IfModule> 
  26. </VirtualHost> 

Restart the apache service/etc/init. d/apache2 restart to take effect.

In windows, we add the index. php file under d: \ devm \ site01 \ htdocs. Edit this file and add:

 
 
  1. <?php  
  2.     phpinfo();  
  3. ?> 

Then connect site01 through FileZilla, switch to the local site's htdocs directory, upload the new index. php file, and then open through the browser: http://www.site01.lo

You can see the following results:

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1222592200-3.jpg "/>

Now, Environment configuration is complete!

We look forward to the second part of this article.

This article from "Dongguan gold sculpture" blog, please be sure to keep this source http://dgoldeagle.blog.51cto.com/6255429/1076231

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.