4 Easy Steps To Run a Localhost on macOS Catalina 2020 Without MAMP

Saturday 1 August 01:21

Localhost on macOs latest Catalina complete step by step guide, not using MAMP

Time needed: 15 minutes.

Facing issues with MAMP on MacOS Here is a guide setting up your own localhost on mac Catalina (latest), Takes around 15 Minutes. So let’s Begin!

Tool Needed: Mac, Supply: MacOs

  1. Setting up Apache Server & Loading inbuilt PHP 7

    Starting up the inbuilt Apache

    Once the Terminal opens you see a Window like this

    You can always modify the colour of your terminal window, whatever suits you best.

    Also, if you want to increase the font size, press Command and + to increase the font size of the terminal.

    For the Pro’s, I am just starting up in minor details so that anyone who is a beginner joining here on the post can understand easily.

    So let’s begin quickly setting up localhost on mac.

    After this command terminal would ask for a password, that’s your default one for MacOs it would just start the inbuilt Apache.

    You may Copy / Paste the commands to make sure no errors occur in the setup.

    sudo apachectl start

    Editing the httpd.conf file

    sudo nano /etc/apache2/httpd.conf

    Again enter the password and the file httpd.conf opens, if you are not a pro to Shell commands, don’t touch anything in the editor be careful not to press any key by mistake, if done press control + “x” key to exit without saving.

    its more than 500+ lines, we need to jump on some exact code and edit and exit so best is to use Control + “W” to find the Code

    Searching the Code
    Now, this will appear like this Search: and Paste, i.e., Control+W and Copy Below Line and Command +V (Paste)

    Editing the httpd File

    LoadModule php7_module
    Enabling PHP modules, Including Virtual hosts, and other important edits.
    Now this will take you directly to the line where you need to uncomment the “#.”

    So I uncommented other modules as well :

    LoadModule deflate_module libexec/apache2/mod_deflate.so
    LoadModule expires_module libexec/apache2/mod_expires.so
    LoadModule rewrite_module libexec/apache2/mod_rewrite.so

    LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so

    These are basic things you may need to set up a server or installing a CMS like a WordPress Blog on the localhost.



    For getting localhost on mac (Important) :

    Uncomment and Include these :
    Include /private/etc/apache2/extra/httpd-userdir.conf
    Include /private/etc/apache2/extra/httpd-vhosts.conf

    Directory Structure :

    Change this, Find with Control + W and change, as mentioned above.

    DocumentRoot "/Library/WebServer/Documents"
    <Directory "/Library/WebServer/Documents">

    to

    DocumentRoot "/Users/YourName/Sites/"
    <Directory "/Users/YourName/Sites/">

    NOTE: YourName is “The Folder of Your Home Directory in Mac” this is Simply
    if you go to Desktop and see under Go > Home

    Change YourName With whatever your default name you want.

    Next Find (ctrl+W) and change :

    AllowOverride None

    to :

    AllowOverride All
    (for .htaccesss usage later)

    So by now, we have Enabled PHP & rewrites module, have changed the default location for our future dev sites and enabled .htaccess,

    Now let’s get ahead with MySQL, Editing some more files, and setting up the Virtual Hosts, and taking this further in setting up a WordPress Blog on the new local webserver.

    Saving the file safely on Terminal
    Press Control + “O” to write out the change made Press Enter

    Then press Control + “X” to Exit safely
    Restarting apache
    sudo apachectl restart

    Done! PHP 7 is now Loaded

  2. Download MySql and linking it to PHP Socket

    Download the latest Package from here official website.

    Installation is the same as any app you download on your Mac.

    Making a Link between the PHP & APACHE

    sudo mkdir /var/mysql ln -s /tmp/mysql.sock /var/mysql/mysql.sock

    This would simply create a link between both.

  3. Making The Virtual Hosts

    Editting httpd-userdir.conf

    Once the server has started.

    sudo nano /etc/apache2/extra/httpd-userdir.conf

    As in the screenshot above edit the file uncomment :

    #Include /private/etc/apache2/users/*.conf ( To use user configuration files )
    also, UserDir, as seen above, this is where the website files go.

    Sites – the default folder you already have.

    By this time we have PHP, Apache running, and MySql as a database now we have to set up the ” Virtual Hosts,” e.g.:

    https://www.yourname.dev

    Setting up localhost on mac without any application is quickly done, and you may use it for development without any internet connection or offline.

    sudo nano /etc/apache2/extra/httpd-vhosts.conf

    To understand we have two ports Port:80 and Port 443, generally port 80 is an HTTP port, and 443 is an HTTPS port or SSL Port,

    While if you are installing a WordPress Locally and using AMP, you may require an SSL to test things I prefer 443 HTTPS port only. (Setting up SSL on localhost is in a Separate Post )
    <VirtualHost *:443>
        DocumentRoot "/Users/yourname/sites"
        ServerName yourname.dev
        SSLEngine on
        SSLCipherSuite #ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    #SSLCertificateFile "/etc/apache2/ssl/localhost.crt"
      #SSLCertificateKeyFile "/etc/apache2/ssl/localhost.key"
       # ErrorLog "/var/log/apache2/localhost-error_log"
    <Directory "/users/yourname/sites">
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>



    <VirtualHost *:80>
        ServerName yourname.dev
        DocumentRoot "/users/yourname/sites"
        <Directory "/Users/yourname/sites">
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>


    I have commented”#” on the SSL usage on Port 443, you may uncomment the same as required.
    If you don’t have a certificate obtained the server would give an error, if we state these links.

    Virtual hosts can be many as per your project need.

    Save this with writing out Ctrl+O and Exit Ctrl+X

  4. Test if everything is OK and Point the Domains to Localhost

    sudo apachectl configtest

    If it returns with Syntax OK everything is perfect, I am doing this practical side by side and making screenshots to avoid any errors to my posts.

    Now lets again restart the apache with

    sudo apachectl restart

    Restarts are good so that the server loads with the changed configurations

    I am also doing this on an AWS EC2 instance with a better User interface my posts about the same are in the Lightsail category of my blog.

    You should always remember some of the basic SSH Commands that would make it easier if you are passionate about developing new things and trying new applications.

    Pointing the Domain or Mapping the Domain to Localhost

    sudo nano /etc/hosts

    This is for pointing 127.0.0.1 ——–> yourname.dev

    it’s an important step as nothing will work if this is not done.

    Again Restart Test Apache & PHP

    sudo apachectl -v

    This will show the server version

    Server version: Apache/2.4.43 (Unix)
    Server built:   Apr  4 2020 01:58:36


    And

    php -v

    Means everything is running fine, a screenshot is attached above.

By Rahul Kharbanda

Hi,
I am Rahul Kharbanda from India. I hope you like all the content I made. Welcome to comment & connect.
I am on Quora , Github , Twitter

Leave a Reply

Your email address will not be published.