PHP and Apache Environment configuration

Source: Internet
Author: User

Recently want to know something about the background of the web, looking at Luke Welling,laura Thomson's "PHP and MySQL Web development", the book Environment configuration part is very complex, the various courses on the web is also very messy, engaged in an afternoon finally succeeded! Keep a record here.

I. INTRODUCTION

First of all, php:php is a server-side scripting language designed specifically for web design, where PHP code can be embedded in an HTML page that executes every time the page is accessed. The implementation of Dynamic Web pages is implemented. You might ask, can JavaScript not also turn HTML static pages into dynamic interactions? The role of the two is different, PHP every time you refresh the page on the server side, and can connect to the database, the contents of the database display, and JS is executed in the browser script language, you can directly manipulate the page, the user interface is more friendly, interactive more powerful.

Simply installing a PHP interpreter does not run the Web page, because PHP runs on the server side and the browser cannot explain it, so it is necessary to build a server on your computer first. The usual is Apache.

Two. Environment configuration

 Environmental information: Install Apache2 and PHP5 under ubuntu14.10

1.APACHE2 Installation

command line input sudo apt-get install apache2

after installation, enter sudo service apache2 restart Restart server

Enter 127.0.0.1 or localhost in the browser to detect if the Web server is working properly, and the IP and corresponding names are stored in/etc/hosts

If you can successfully display the page, (title may be Apache2 Ubuntu Default page) Description of the installation success ~

the file displayed is the default path for the Apache server to run the file/var/www/html/ The index.html file is run by default when the file name is not given

The configuration information for the path is stored in the/etc/apache2/sites-available/000-default.conf

We create a simple HTML file under/var/www/html, such as the name test.html

  

 <  html  >  <  body     >  <  h1  >  Hello</ h1  >  </ body  >  </ html  >   

Then entering 127.0.0.1/a.html in the browser will show hello. (Note that only the root permission is writable in this directory, you need to add sudo to the command, or modify the user's permissions)

2.PHP Installation

Command line input sUdo apt-get install php5 PHP Interpreter

Input sudo apt-get install libapache2-mod-php5 installation apache2 support module for PHP5

Then we create a new file under the directory/var/www/html/test.php

Phpinfo ();?>

Open the browser, input 127.0.0.1/test.php will display information about PHP, the environment configuration is complete ~^v^

Three. Create more servers

To create a new server, create a new directory to hold the Web page, and create new configuration information to point to the directory.

1. Create a Directory

sudo mkdir-p/var/www/demo.local/public_html Create subfolders under the www/directory demo.local

This directory currently only has write permission for root, and we want to assign permissions to normal users

2. Assigning Permissions

  sudo chown-r $USER: $USER/var/www/demo.local/public_html

Where the "$USER" variable points to the current logged-on user

sudo chmod-r 755/var/www/ enables users to have R,X permissions on this directory and its subdirectories

3. Create a home page

sudo gedit/var/www/demo.local/public_html/index.html

< HTML > < Body >    < H1 > Demo! </ H1 > </ Body > </ HTML >

4. Create a configuration file

We only need to copy the 000-default.conf file and make a simple modification to configure the server's path

sudo cp/etc/apache2/sites-available/000-default.conf/etc/apache2/sites-available/demo.local.conf

sudo gedit/etc/apache2/sites-available/demo.local.conf

Change serveradmin to [email protected]

Change DocumentRoot to/var/www/demo.local/public_html

5. Start the server

sudo a2disite 000-defalut.conf Disabling the default server

sudo a2ensite demo.local.conf enable the server you just created

sudo service apache2 Restart Restart the server for the changes to take effect

At this point, enter in the browser 127.0.0.1 will find that the page appears a large "Demo", change the server success ~

Reference: http://os.51cto.com/art/201406/441909.htm

PHP and Apache Environment configuration

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.