Configure the APACHE+PHP5.3+MYSQL environment in your Mac, modify the hosts

Source: Internet
Author: User
Tags fpm install brew phpinfo

As is known to all, the MAC has its own Apache


Here are a few commands about Apache.

sudo apachectl start open

sudo apachectl restart restart

sudo apachectl stop stop

sudo apachectl-v view native Apache version


The following is the path to the Apache configuration file

/etc/apache2/httpd.conf


In theory, enter sudo apachectl start in the terminal and enter the password. Enter localhost in the browser to display the It work! Words

Apache's Web server root directory is in/library/webserver/documents.

You can use Ln-s to create soft links on the desktop ~ similar to shortcuts in Windows


In Mac OS a class already has PHP, just add Apache to PHP support is OK

Edit http.conf configuration file sudo vim/etc/apache2/http.conf


Press ESC to enter VIM's command mode, enter: php5/s can find content about PHP5

Find #LoadModule php5_module libexec/apache2/libphp5.so, remove the front #

Restart Apache

sudo apachectl restart


Write a phpinfo.php file in the root directory and write a phpinfo () function, so you can see the PHP version and related data.


The version you see is built into the max system, and if you need to install a different version of PHP, you can use the Brew command


First, enter the following in the terminal to install brew

ruby-e "$ (curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/install)"


Continue Typing

Brew Update
Brew Tap Homebrew/dupes
Brew Tap homebrew/php
Brew Tap josegonzalez/homebrew-php


Installing PHP53

Brew Install PHP53


Installed php53 configuration file in/usr/local/etc/php/5.3/php.ini


Since the Mac comes with PHP and PHP-FPM, you need to add the system environment variable path instead of the PHP version:


echo ' Export path= ' $ (brew--prefix homebrew/php/php53)/bin: $PATH "' >> ~/.bash_profile #for php
echo ' Export path= ' $ (brew--prefix homebrew/php/php53)/sbin: $PATH "' >> ~/.bash_profile #for php-fpm
echo ' Export path= '/usr/local/bin:/usr/local/sbin: $PATH ' >> ~/.bash_profile #for other brew install soft
SOURCE ~/.bash_profile #更新配置


Test to see the PHP version
$ php-v


$ php-fpm-v


At this point, if the phpinfo () function is displayed, the version shown is not php53, because the PHP module in the Apache configuration file is pointing or the original one, now change the path


First, or open the config file. sudo vim/etc/apache2/http.conf

ESC then go to command line mode, enter:/PHP5 Find the PHP module, change the content as follows

LoadModule php5_module/usr/local/opt/php53/libexec/apache2/libphp5.so


Restart Apache, and then the phpinfo display is 5.3.


Next install MySQL, this can be installed by the MySQL official website is very convenient.


Next, set up the virtual host so that you can enter a virtual URL to access the project under the root directory.


sudo vim /etc/apache2/httpd.confOpen Apche configuration file in Terminal input

Find "" In httpd.conf #Include /private/etc/apache2/extra/httpd-vhosts.conf , remove the previous "" , save and exit.

然后重启Apache

Enter sudo vi /etc/apache2/extra/httpd-vhosts.conf the Configure virtual host file to open

There are two examples in the file that you can comment on


And then add

< VirtualHost *:80>      DocumentRoot "/Library/WebServer/Documents"#根目录      ServerName localhost      ErrorLog "/private/var/log/apache2/localhost-error_log"      CustomLog "/private/var/log/apache2/localhost-access_log" common </ VirtualHost > < VirtualHost *:80>      DocumentRoot "/Library/WebServer/Documents/test"#路径改成你的项目文件,以test为例
     ServerName www.test.com   #虚拟域名,以www.test.com为例
     ErrorLog "/private/var/log/apache2/sites-error_log"      CustomLog "/private/var/log/apache2/sites-access_log" common      < Directory />                  Options Indexes FollowSymLinks MultiViews                  AllowOverride None                  Order deny,allow                  Allow from all        </ Directory > </ VirtualHost >


Save exit.


Then modify the Hosts file, Windows words under System32

输入sudo vi /etc/hosts", open the hosts configuration file and join 127.0.0.1 www.test.com


Save and restart Apache

This will enable the browser to enter www.test.com access to the project under/library/webserver/documents/test.



Configure the APACHE+PHP5.3+MYSQL environment in your Mac, modify the hosts

Related Article

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.