Build lamp under Mac

Build lamp under Mac

Mac comes with Apache and supports PHP environment by default. You only need to configure Apache and PHP to use it. The mysql server needs to be installed separately.

  • Apache basic configuration
  • Apache supports PHP configuration
  • Apache virtual host configuration
  • *Mysql installation configuration

Apache basic configuration

  1. Backup configuration files
sudo cp  /etc/apache2/httpd.conf  /etc/apache2/httpd.conf.bak
  • 1
  1. Modify website directory
sudo vim /etc/apache2/httpd.conf
#搜索DocumentRoot,把 DocumentRoot "/Library/WebServer/Documents"中的目录修改为自己的网站目录
DocumentRoot "/Users/apple/Sites"
#把 <Directory "/Library/WebServer/Documents"]] > 改为 <Directory "/Users/apple/Sites"]] >
#修改运行Apache的用户和用户组,搜索Group和User
Group www
User www
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  1. Set site directory permissions and groups
chmod 755 -R /Users/apple/Sites
Chown www:www -R /Users/apple/Sites
  • 1
  • 2

Apache supports PHP configuration

  1. apache supports PHP
sudo vim /etc/apache2/httpd.conf
#找到 #LoadModule php5_module libexec/apache2/libphp5.so删除行首的 # 让服务器启动时加载php模块
#重启apache
sudo apachectl -k restart
  • 1
  • 2
  • 3
  • 4

Mysql installation configuration

  1. Install using brew: How brew install mysql 
    to use brew
  2. Restart mysql:sudo apachectl -k restart
  3. Write in the root directory of the Apache website, visit whether the PHP info page appears
<?php
    phpinfo();
?>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325521846&siteId=291194637