Home  >  Article  >  Backend Development  >  Apache deploys local PHP project virtual address

Apache deploys local PHP project virtual address

WBOY
WBOYOriginal
2016-07-28 08:26:32826browse

I recently learned PHP by myself. Here I will briefly explain how to access PHP projects using a computer browser.

I use a mac system, and the development tool is Zend Studio, Apache/2.4.18.

For example, we want to set the virtual domain name of this machine to my.com

1. First find the installation directory of Apache: mine is in /private/etc/apache2

Find the file httpd.conf in this directory. There are the following two lines in the middle of the file content:

# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf

Release the second line, that is, delete it#

# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

When saving, If it cannot be saved, copy a copy to the desktop. After modification, copy the file over to overwrite the previous file.

2. Find the file released in the previous step. The location is: /private/etc/apache2/extra/httpd-vhosts.conf

Open the file, follow the prompts in the file, add the following code at the bottom and save:


DocumentRoot "/Users/Xiang/Zend/ workspaces/MyPHP"
ServerName my.com
ErrorLog "/private/var/log/apache2/bweb-com-error_log"
CustomLog "/private/var/log/apache2/bweb-com-access_log " common

# AllowOverride All # Deprecated
# Order Allow,Deny # Deprecated
# Allow from all​​ #Deprecated
# --New way of doing it
Require all granted


Note: DocumentRoot "/Users/Xiang/Zend/workspaces/MyPHP" and are the paths where the project is located. ServerName my.com is the local domain name to be added, and others No modifications are required.

3. Find the hosts file in the /private/etc directory

Add a line at the end of the file and save it:

127.0.0.1 my.com

4. Finally restart Apache

sudo apachectl restart

will ask you to enter the password, which is the computer power-on password.

At this point, open the browser of your local computer and enter http://my.com/index.php, and you can see the content of index.php I wrote in the MyPHP project.

The above introduces the Apache deployment of local PHP project virtual address, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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