Friday, November 9, 2018

Install Apache and PHP on Mac OSX Sierra 10.13.6

Apache comes already installed, below steps to make sure it is running and also have PHP enabled:

1. Get in as root
sudo su

2. 
apachectl start

3. Navigate to http://localhost and confirm it works:
 

4. Let's do some tweaks for optimized usage of Apache and PHP:
Configure User Level Root:

Add  a "user.conf" file under:
/etc/apache2/users/

where user is your OS X user.
cd /etc/apache2/users
touch user.conf 

5. Add the below content to the newly created file - replace user with your real username:

<Directory "/Users/user/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
 
6. Permissions on the file should be:
 
 

7. Edit httpd.conf file

vi /etc/apache2/httpd.conf
 
8. Make sure following modules are loaded - lines are not commented:
LoadModule authz_core_module libexec/apache2/mod_authz_core.so
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule include_module libexec/apache2/mod_include.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so 
LoadModule php7_module libexec/apache2/libphp7.so
 
Uncomment also following line:
Include /private/etc/apache2/extra/httpd-userdir.conf 

9. Uncomment following line:
Include /private/etc/apache2/users/*.conf
 
from the following file: 
/etc/apache2/extra/httpd-userdir.conf
 
10. Being still root, restart Apache:
apachectl restart
 
11. User document root is displayed at:
http://localhost/~user/ 

12. Test PHP by adding a file phptest.php under /Users/user/Sites/ folder with the following text:

 <?php phpinfo(); ?>
 
13. Navigate to this PHP page - Now Apache and PHP works well together
 

No comments:

Post a Comment