Upgraded to Yosemite , great . now lets see how to setup Apache webserver with PHP and MySQL . unlike 10.7 Lion or 10.6 there is no prefrence pane option to turn on Apache . but don’t worry MacOSX Yosemite comes with Apache and you can turn on it using Terminal . Okay lets see how to setup Apache PHP and MySQL setup in Mac OS X Yosemite .
apachectl -v && php -v
setup apache
open terminal and type
sudo apachectl start
now open your favourite browser and browse to http://localhost
you will see default apache page
Lets setup user-dir for per user
I am going to use nano
in this guide feel free to use any of your favourite editor .
- Enable
mod_authz_core, mod_authz_host, mod_userdir
andmod_userdir.so
modules
sudo nano /etc/apache2/httpd.conf
Uncomment These Three Modules For Now ( Remove “#” sign from the starting of line if “#” is present )
LoadModule authn_core_module libexec/apache2/mod_authn_core.so LoadModule authz_host_module libexec/apache2/mod_authz_host.so LoadModule userdir_module libexec/apache2/mod_userdir.so
You can dump list of all Loaded Modules using sudo apachectl -M
command .
Then Navigate to bottom of the file , and uncomment following line
Include /private/etc/apache2/extra/httpd-userdir.conf
then open /etc/apache2/extra/httpd-userdir.conf
sudo nano /etc/apache2/extra/httpd-userdir.conf
and uncomment following line
Include /private/etc/apache2/users/*.conf
Okay Now Setup your user.conf
sudo nano /etc/apache2/users/YOURUSERNAME.conf
<Directory /Users/*/Sites> DirectoryIndex index.html index.php index index.html default.html default.htm AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec <Limit GET POST OPTIONS> Require all granted </Limit> <LimitExcept GET POST OPTIONS> Require all denied </LimitExcept> </Directory>
Now Create Sites
Folder in your Home Director
mkdir Sites
Now test apache config using
Now Create a File inside Sites Directory Name it index.html
Enter Some Plain HTML and save that
Now Let’s Test Apache Configuration
apachectl -t
then restart apache
sudo apachectl restart
then open browser and browse to http://localhost/~yourusername , Note that “~” tilde in url
your will see something like this
Setup PHP
sudo nano /etc/apache2/httpd.conf
and uncomment
LoadModule php5_module libexec/apache2/libphp5.so
and test apache config using apachectl -t
then create a file in your Sites Directory
nano ~/Sites/index.php
then enter simple phpinfo()
in index.php
<?php phpinfo(); ?>
and browse to http://localhost/~username/index.php
you will see phpinfo page
setup MySQL
Download MySQL (Download DMG ) : http://dev.mysql.com/downloads/mysql/
Install that Like another Package of MacOSX there is nothing tricky , install prefPane ( included in DMG )
adding mysql in $PATH
touch ~/.bash_login && echo export PATH=$PATH:/usr/local/mysql/bin | tee ~/.bash_login
above command will create .bash_login
file in your home directory and it will add MySQL in PATH
restart your terminal and start mysql from PrefrencePane
okay now open terminal and type
mysql_secure_installation Aloks-Mac-Pro:~ alok$ mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. Set root password? [Y/n] < ------------------ Press ENTER
Set root password? [Y/n] < ------------- Press Enter
New password: < ------------------ ENETR NEW ROOT PASSWORD Re-enter new password:
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] < ------------------- PRESS ENTER
Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] < ------ PRESS ENTER
By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] < ---------- PRESS ENTER
Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] < ------------- PRESS ENTER
All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL! Cleaning up...
All Done Now MySQL is set up
Now You Have Working APACHE PHP AND MYSQL
ScreenCast
happy Coding 🙂