Now If You are a Developer, designer , Coder or Blah…Blah…Blahh.. WHAT EVER MAY BE.. You need to check, debug, run and test your scripts, design and codes before your put them online. Now this is a very important thing that you will not like to ignorly ignore it.
Now let it be you are a designer, and you have coded a beautiful theme for a WordPress website. You think that everything is working fine, but you don’t have the power of GOD, or you ignored to install a localhost/localserver/webserver on your Mac. You completed the design project and to test it you uploaded it to your wordpress website, went to dashboard> Apperance > Themes > and changed to your that theme. You refreshed the page, and suddenly “BOOM”. all went wrong, you messed your design, time, and hard work, not even this you may even make your website inoperable.
What will Happen Now? OMG
So to be tensionless, and check your work on the go, always want to know what are you doing and what is going to happen with that code. So its time to install the local server software, You can do it using the terminal in Mac, but it is full of risk as you can lost your data or make even Mac inoperable.
So installing local server in the easy way using software.
Why Not Just Use AMPPS or MAMP?
Download any localserver software from Mac Store or from the Internet.
In our case we are going to install the AMPPS from internet,
Open Ampps.dmg or your downloaded software,
open the software and start the services
Services: Apache, PHPMyAdmin, MySql, FileZilla or anything
You are done in installing the local-server in your Mac.
Doing it By Terminal Way?
Now using terminal is something you should have prior knowledge, or atleast you should what are you doing, Mac comes pre-installed with the services like Apache, MySql, PHP, etc. So rather downloading any app which exceeds more than 250MB in size you can just use the pre-installed services.
All you need to start a Terminal with Admin Priviledges, and start copying and pasting this codes.
[Codes marked Green are to be used to start a service, Codes marked Red are to stop a service]
- Open Terminal [ Located under the Applications -> Utilities section ]
- Copy the Below commands and paste and hit enter.
To Start The Apache Service, Type
sudo apachectl start
To Restart the Apache Service
sudo apachectl restart
To stop Apache Service completely
sudo apachectl stop
Activating The PHP Module
Apache service is just for testing static html files or simple static files, it can’t handle complicated files like running a wordpress, or just installing a wordpress. As wordpress is created and based on PHP, you need to run a PHP module to start using PHP service.
Good News is that PHP comes pre-installed in MacOSx, all you need to do just start the module by terminal.
Open terminal as you use to. Type
sudo nano /etc/apache2/httpd.conf
to open Apache config file.
Now find this specified line in the config file
#LoadModule php5_module libexec/apache2/libphp5.so
and replace the sharp ‘#’ tag from it
LoadModule php5_module libexec/apache2/libphp5.so
and save the file. Finally restart the apache service, by typing this command in terminal
sudo apachectl restart
Configuring and Creating Sites folder
Now as Apache and PHP module are configured, all you need is now creating a sites folder where you are going to host all the files and upload you script, so that you can call them from browser. As http://localhost/SITENAME
To configure the site folder you need to follow this steps,
- Open the Finder and browse to your Home folder (Usually the folder with a Home icon with your username).
- Create a new folder and rename it to ‘sites’
- Now go back to terminal and start typing the codes.
sudo nano /etc/apache2/users/ReplaceWithYourusername.conf
ReplaceWithYourusername shoud be replace with your login username.
Now the conf file should be opened, and you should copy the below codes and paste it there
Options Indexes MultiViews
Allow from all
In the first line ” <Directory “/users/username/Sites/”>
Replace the username with your login username for Mac.
Next step is to type this codes in terminal.
Now phpinfo.php will pop open and you should paste the below codes,
Now save the file, After successful save, you should Restart the Apache service again.
Type this code in terminalbelow.
sudo apachectl restart
Now the last step of this lengthy process is visit ” http://localhost/~YourLoginusername/phpinfo.php ” in your favourite browser. If you have done every process correctly then you will see the PHP info of your PHP module.
Setting up MySQL
Unfortunately, mysql is not pre-installed or even included in Mac, So you must download MySql with dmg extension for easier installation and install it on your Mac.
After install, go to System Preferences > MySQL, and start the MySQL instance
Now you need to Setup the MySQLroot password
go to terminal, and type
/usr/local/mysql/bin/mysqladmin -u root password ‘Enteryourpasswordhere’
Now replace Enteryourpasswordhere with your password for MySQl. Don’t get confused, this is not your Mac Account’s password.
Now you again need to run a few command, do it step by step, one line at a time.
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*
After this type clear in your Terminal, and paste this code sudo nano /etc/hostconfig
This will open a file called ” hostconfig ” . Now you need to Edit this and remove the Line MYSQLCOM=-YES- from the file.
The Final Step – Installing PhpMyAdmin
- Download PHPMyAdmin.
- Rename the compressed file to ” phpmyadmin ” and move or copy it to the ” sites ” folder located in your Home folder. Do You Remember.
- Extract the compressed file.
- Now open it [folder] and create a new folder and rename it to ” config “.
- Right click the config folder, and choose – open with > Terminal.
- Run this command – chmod o+w ~/Sites/phpmyadmin/config
- Now open your default browser,
- visit – http://localhost/~username/phpmyadmin/setup
- And click the ” New server ” Button.
- Head over to “Authentication” tab and enter your MySQL root password in the “Password for config auth” field.
- Save it,
- Open Terminal, type this command
- sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
- go to ” http://localhost/~username/phpmyadmin “
- and create your databases.
Ohh.. it was lenghty… Terminal Terminated me..
Using any software do this process, is much simple compared to terminal. Sometime it sucks. We have clearly seen here that software is much much better or its the best things to set up a local web server in Mac Mavericks or any other version.