Home >php教程 >php手册 >Website Development Series 1 Server Environment Construction

Website Development Series 1 Server Environment Construction

WBOY
WBOYOriginal
2016-07-06 13:30:55970browse

First of all, the audience of this series of articles is those who have just graduated and want to do website development, or are in other development positions and want to learn about introductory tutorials on website development. By default, readers have computer-related professional foundations and will skip a lot of basics. You can Baidu for the details. Or I will add later that the characteristics of the programming language itself will not cover many. Well, let me briefly introduce myself, I am South China Agriculture

First of all, the audience of this series of articles is those who have just graduated and want to do website development, or who want to learn about introductory tutorials for website development in other development positions. By default, readers have computer-related professional foundations and will skip a lot of basics. You can Baidu for the details. Or I will add later that the characteristics of the programming language itself will not cover many.

Well, let me briefly introduce myself. I am a male science and engineering graduate from South China Agricultural University, majoring in software engineering. I worked in a startup company called Kailangao in Guangzhou for more than two years from 2012 to 2014, mainly responsible for Nodejs server development. and technical team management. In August 2014, I tried to start a business for three months but ended in failure. In December 2014, I worked as a front-end developer at Southern Weekend New Media for more than half a year and started to get involved in PHP development. I resigned in August 2015 and have been working in a company since. I am a technical director of a B2B start-up company in a traditional industry. I am still relatively inexperienced, and it is impossible for me to know and understand all programming languages ​​and software thoroughly. Please point out any mistakes I make.

Learning objectives:

  1. Understand the server concept in B/S architecture.
  2. Learn which web servers are available.
  3. By building a hello world website operating environment, I will become familiar with the process of installing software under Linux, understand what information the web server generally needs to configure, and how the web server is connected with the code we write.

Learning process

  • First let’s talk about the goal. Our goal is to create a website, a website that others can access through the website address (URL), so the website must run on a server to provide services for visiting users, then provide this service The machine is also called a web server. How to understand the server? Compared with another noun PC (personal computer), a simple understanding is that a server is a powerful computer used to provide some services, and the software running on this physical machine varies according to the services provided. We are also divided into web servers, database servers, mail servers, cache servers, proxy servers, etc. At this time, the names of web servers also refer to software such as Website Development Series 1 Server Environment Construction and apache.

  • Web server, also known as website server, as the name suggests, provides website access services. So What software can function as a web server? When learning java, we need to install tomcat, when learning .NET, we need to install iis, when learning PHP, we need to install apache or Website Development Series 1 Server Environment Construction, by the way, tomcat, iis, apache or Website Development Series 1 Server Environment Construction is one of the web servers we call. So, what functions do they provide as web servers?

tomcat

iis

apache

Website Development Series 1 Server Environment Construction

Website Development Series 1 Server Environment Construction

  • In order to explain the role of the web server, we should first choose one of the programming languages, configure the operating environment, and be able to access and return data , and then talk about the role of the web server effect. Here, I choose a typical lamp website technology combination to illustrate, and at the same time explain other types of web servers by analogy.

First of all, the simplest hello world website does not actually require a MySQL database, so start with the simplest configuration. You can use wamp directly under windows (http://www.wampserver.com/ ) integration, for this tutorial, I spent 666 oceans to buy Alibaba Cloud’s Linux server, cenos7.0 64-bit .

 1. Download apache, http://httpd.apache.org/, you can download the 2.4.18 version, please refer to the installation process for details Attachment:

After apache is installed, it is installed in /usr/local/apache2 by default, so in order to start it globally, a hard link to httpd is created, ln /usr/local/apache2/bin/httpd /usr/local/bin/ .

 2. The programming language is php, first download php from http://php.net/, the latest version is 7.0.0, but here we take 5.6.16 as an example , Windows has thread-safe and non-thread-safe versions. Download the thread-safe version for now. The specific differences will not be explained for the time being.

After installing php, start php-fpm, temporarily use the default configuration, and use TCP to connect to port 9000. For details, please refer to the attachment.

 3. Then I hope that when accessing the localhost address or 127.0.0.1, the web page returns the hello world string and displays it to the browser, so I write a file named index.php

vim /var/www/test/index.php (the directory does not exist and needs to be created first)

<span style="color: #008080;">1</span> <span style="color: #000000;">php</span>
2 <span style="color: #0000ff;">echo</span> "hello world";

  • Okay, at this point, how to connect these three to achieve web page access?
  1. After installing apache, you need to start the httpd service. Just start httpd directly. At this time, the default page of apache will appear when you access it.
  2. But how to change the default access page to the index.php you just wrote? To modify the configuration, we can look at the existing configuration of apache and understand the part. The original configuration file is in /usr/local/apache2/conf/httpd.conf (if you encounter 403 permission issues, please refer to http://www.th7.cn/system/lin/201507/122784.shtml).
    Listen 80<span style="color: #000000;">(监听端口,可在这里修改)
    
    User daemon(启动使用的用户)
    Group daemon(启动使用的组)
    
    DocumentRoot </span>"/usr/local/apache2/htdocs"(文档根目录,也就是我们访问url为/时指向的文件系统目录,修改为DocumentRoot "/var/www/test"<span style="color: #000000;">)
    
    <directory>"/var/www/test"<span style="color: #000000;">>(设置对应目录的访问权限)
    Options Indexes FollowSymLinks
    
    AllowOverride None
    
    Require all granted
    </span></directory>
    
    <ifmodule dir_module>(设置默认首页)
    DirectoryIndex index.html index.php
    </ifmodule>
    
    ErrorLog </span>"logs/error_log"(错误日志,修改为ErrorLog "/var/log/apache/error_log.log"<span style="color: #000000;">)
    
    LogLevel warn(日志等级)
    
    CustomLog </span>"logs/access_log"(正常访问日志,CustomLog "/var/log/apache/access_log.log")

  3. Create a soft link to the configuration file ln -s /usr/local/apache2/conf/httpd.conf /etc/httpd.conf, restart httpd -f /etc/httpd.conf -k restart, then tail - fn100 /var/log/apache/access_log.log You can see access 200 records.

xxx.xxx.xxx.xxx - - [16/Dec/2015:15:57:51 0800] "GET / HTTP/1.1" 200 26 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit /537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36"

4. The output content is the php file code we wrote, not the execution result. Why? Because php is a scripting language, it requires the previously installed php to interpret the execution output. Therefore, the next step is to add php to the apache configuration. There is more than one mode for apache to run php. The fastcgi mode is used here, and the others will be explained later. Pattern practices and principles. Remove the comments of the following two modules, add the module configuration, and restart the apache server.

LoadModule PRoxy_module modules/mod_proxy.so

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so


 ProxyPass "/" "fcgi://127.0.0.1:9000/var/www/test/index.php" enablereuse=on

Summary:

  1. A server is a powerful computer dedicated to providing one or more services.
  2. Apache, Website Development Series 1 Server Environment Construction, tomcat, iis, etc. are all web servers. They all have similar functions, but they have different implementation principles and programming language support.
  3. The web server listens to a certain port (usually port 80), establishes an HTTP connection, receives and analyzes the data stream, and some servers also use integrated modules to process user-specific logic requests (such as querying the database and returning data ), interpret (scripting languages ​​php, nodejs all fall into this category, like java itself has been compiled into a class file) and execute the code we wrote, and finally return our output to the user's browser as a result.
  4. Server configuration generally includes listening port, access log and error log settings, connection number settings, and request allocation or processing.

Of course, there are still many small problems to be solved in the entire configuration process. While solving these problems, it also forces me to learn and improve myself. If you have any questions, leave a comment and I will try my best to answer them. But in the next issue, I will make a big reversal. 1. I will use Nginx as the reverse proxy server to replace apache and adopt the LNMP architecture; 2. I will configure the Laravel PHP framework and be able to access Laravel's hello world home page, Larevel is also a framework used for website development, rather than building a website from scratch.

Attachment: LAMP environment setup


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Some usages of echoNext article:Some usages of echo