There are no traces about this but the matter of the fact is Apache and PHP comes preinstalled on your OS X. Now the question is, "Where is apache on your OS X partition and how to use it, how to use PHP?".
As always, I would try to share my experience of finding and running Apache and PHP on OS X.
To start Apache Web Server, perform following steps:
- Open "System Preferences". You can do that from Apple Menu or can open it from Applications.
- Locate icon labeled 'Sharing". Click on it.
- Locate "Web Sharing" and select it. This should start up Web Sharing on your machine, which starts the Apache Web Server on your machine. Once the Apache Web Server is started, you can see URLs for "Your computer's web site" and "Your personal web site".
- Your Apache Web Server is running now.
- Start up your browser and open the URL (http://your-ip-address or http://localhost).
- If everything is OK, your web browser should show you Apache default page.
To access your personal web pages, type following URL in your browser:
http://localhost/~username/
You can access your personal web pages at /Users/user-name/Sites/ directory. You can add/delete/modify web pages in this directory to set your personal web-site.
Now that you have your Apache Web Server running, running a PHP script should look trivial, you might have done it before. But it is not so easy on OS X.
By default, along with other features, PHP is disabled on Apache. You will have to enable PHP support in Apache. Follow these steps to enable PHP in your Apache:
- We need to locate httpd.conf file to enable PHP with Apache. Go to /etc/apache2/. Open httpd.conf by typing sudo vi httpd.conf (you need super user privilege to modify this file).
- Type the root password and you should be able to modify httpd.conf file.
- Locate the line LoadModule php4_module or LoadModule php5_module.
- Uncomment the line by removing the hash (#) from the begining of the line.
- Warning! do not relocate the lines in this file.
- Save the file.
- By uncommenting the line LoadModule, you will load PHP module and allow Apache to serve any PHP file.
- Restart Apache by deselcting and selecting "Web Sharing" on System Preferences->Sharing.
< ? php
// Show all information, defaults to INFO_ALL
phpinfo();
?>
Type the following URL in your web browser to check PHP.
http://localhost/~user-name/phpinfo.php
It should display large page with all PHP statistics.
If everything goes as described, you are good to use PHP with your Apache Web Server on your OS X. Remember, we have nothing to install here. Everything is preinstalled on your OS X. What we did is enabled the Web Server and PHP on your machine.
Have a nice day!
No comments:
Post a Comment