Steps to Install Wordress locally on macOs

You install wordpress in local on your Mac to create an environment development and testing? Not sure which software components you need to install and how to configure them?

Install Wordress locally on macOs
Install Wordress locally on macOs

Then follow me in this article, I will show you which components you will need to install on your mac and how to best configure them to create a local development environment for wordpress.

In the article I’ll show you how to manually configure all the various components you need, mainly using the command line to create a development environment tailored to you and your needs.

The components to be installed

Components software to install and configure to create an environment development and test that is compatible to run in the local of wordpress are as follows:

  • Apache
  • php
  • mySql / mariaDB

Once the development environment has been configured, it will be possible to proceed with the installation of wordpress using the binaries that can be downloaded from the official online repository.

Alternatives to manual configuration

There are alternatives to manually installing the necessary components, these alternatives allow you to configure all the necessary components using preconfigured setups (MAMP / XAMMP) and have a working and tested development environment.

Or you could try with containers and Docker to use an environment outside your local machine and already preconfigured.

In this article, however, I’ll show you how to install the individual components from the command line and set up a working development environment on your mac without the aid of external containers or setups.

The tools you need for setup

To proceed with the setup correctly you must have the following tools at hand:

  • Command execution terminal
  • Administrative password of your machine
  • Homebrew installed on your mac

To launch the command line, search the app for ” terminal “.

How to install wordpress on macOs for local development

So let’s start to see how to proceed with the setup, starting by checking the pre-installed components on your macOs (usually Apache and php )

Check pre-installed components on macOs

To do this pre-check proceed as follows, from the terminal launch the following commands

apachectl -v
php -v

Check the installed versions, you should have a version of Apache 2.4 or higher and a version of php 7.1 or higher; this is because the macOs is released with these software already preconfigured.

As for Apache you will only have to configure it and leave the version installed by default, while for php, in addition to the pre-installed version, you will also have to install versions 7.4 and 8.

Let’s see how to do it together.

Apache configuration

As mentioned the 2.4 version of Apache, pre-installed with the mac, is fine for your purposes, so you will only have to do some small configuration.

The first thing to do is to proceed with a backup of the Apache configuration file

sudo cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf.old

Remember that the default Apache directory for running web pages is ” / Library / WebServer / Documents ”

You can find it in the httpd.conf file on line

DocumentRoot "/ Library / WebServer / Documents"

If you want you can always change it, for example I use the folder ” / opt / apache / wwwroot / “.

Now enable the ” mod_rewrite ” module used by wordpress for rewriting the URL, edit the configuration file with the nano editor :

sudo nano /etc/apache2/httpd.conf

Uncomment (#) the following line

LoadModule rewrite_module libexec / apache2 / mod_rewrite.so

With the nano editor to search in the text you can use the key sequence ” control + W “, while to save the file and then close the sequence ” control + O ” (save) and ” control + X ” (close )

Php installation and configuration

Now that you have made a backup of the apache configuration file you can proceed with the installation of versions 7.4 and 8 of php.

Now you are wondering “ Why do I need to install version 7.4 and version 8 ? 

the answer is given by the fact that at the time of writing this article the version of php with greater compatibility towards wordpress is 7.4, but soon the final and perfectly compatible version will become 8 so you better start mastering the version switch to get you ready.

Proceed as follows:

brew install [email protected] 
brew install [email protected]

Now set php version 7.4 as default

brew unlink php && brew link --overwrite --force [email protected]

And enable the Apache php module, so edit the configuration file:

sudo nano /etc/apache2/httpd.conf

Comment on the following line

#LoadModule php7_module libexec / apache2 / libphp7.so

And add the following line

LoadModule php7_module / usr / local / opt / [email protected] /lib/httpd/modules/libphp7.so

Save and close the file.

Remember that your new php configuration file ( php.ini ) is located in the folder ” /usr/local/etc/php/7.4/php.ini “, it could be used to configure some variables used by wordpress such as  post_max_size and upload_max_filesize

Some programmers also act on the variables max_execution_time , max_input_time , and memory_limit according to the characteristics of the project (eg presence of plugins and particularly heavy themes).

Now restart both php and Apache with the commands:

brew services restart [email protected] 
sudo apachectl restart

and check the Apache and php versions again with

apachectl -v
php -v

You should receive output similar to the following

MySql installation and configuration

Once you have configured Apache and php you can proceed with the setup of mySql, I suggest you install the open version ( mariaDb ) available via Homebrew.

Install mariadb with the command

brew install mariadb

For more information follow the official mariaDb documentation

Start the server with the command

mysql.server start

Then configure mariaDb as an always-on service

brew services start mariadb

Now check that the configuration is correct, run the following command

mysql -u root

and verify that the mySql prompt is activated

Now set a password for the root account and secure the installation with the command:

mysql_secure_installation

When finished, check again that the login works with the password you just set and check the version :

mysql --version

To verify that everything is working.

WordPress installation and configuration locally

Now that you have correctly installed and configured Apache, php and mySql you can proceed with the installation and configuration of wordpress locally to verify that everything works at its best.

Download latest version of wordpress

Download the latest version of wordpress from the following link then unzip the zip in the Apache working directory (e.g. / Library / WebServer / Documents ) for which you should have the following path

/ Library / WebServer / Documents / wordpress

Set folder permissions

Now set the correct permissions to the wordpress folder

sudo chown -R _www: _www / Library / WebServer / Documents / wordpress
cd / Library / WebServer / Documents / wordpress
find. -type d -exec chmod 755 {} \;
find. -type f -exec chmod 644 {} \;

To allow wordpress to access the files necessary for proper operation (eg .htaccess, public, …)

Create the wp-config.php file

Access the wordpress folder and create a copy of the “wp-config-sample.php” file, call it “ wp-config.php “; now edit the file and enter the information relating to the mySql database :

// ** MySQL settings - You can get this info from your web host ** //
/ ** The name of the database for WordPress * /
define ('DB_NAME', ' wordpress ');

/ ** MySQL database username * /
define ('DB_USER', ' root ');

/ ** MySQL database password * /
define ('DB_PASSWORD', ' [LA_TUA_PASSWORD] ');

/ ** MySQL hostname * /
define ('DB_HOST', 'localhost');

Save the file and close it.

Create mysql database for wordpress

Access the mySql shell from the command line and create a new ” wordpress ” database

 mysql -u root -p

Enter the chosen password and log in to the mysql shell, then run the command

create wordpress database;

Check that the db has been created with the command:

show databases;

You should see the list of db present on your Mac.

Launch the wordpress setup

Now that you have created the db, open the browser and launch the following url:

http: // localhost / wordPress

Follow the steps for installing WordPress, starting with the site data locally:

If you have done everything correctly the next step should show you a page “ Congratulations! ”Demonstrating that everything went well

You can then access the wordpress dashboard. and check that everything is ok.

Final setup checks

Once you have accessed the wordpress dashboard I suggest you check that the url rewrite works correctly, that is the rewriting of the url through the Apache module.

To check this, proceed in this way, access the ” Settings – Permalinks ” link and select the ” Article Name ” setting

Save and verify that the .htaccess file is writable if the message appears:

If your file  .htaccess was writable we could have done this automatically, but it wasn’t so these are the mod_rewrite rules you should have in your file  .htaccess. Click in the field and press  CTRL + a to select all.

It means that the .htaccess file is not writable, so you need to check the permissions of the files and folders.

If, on the other hand, the saving does not produce any error messages, it means that everything is fine and you can start working on your new local project.

Conclusions

In this article, I showed you how to install and configure all the software components necessary for wordpress to work locally on your mac.

This way you can create a fully functional development and test environment to work on your new digital project before release to the exercise environment.

What do you think of the tutorial? Have you ever worked with wordpress locally on your mac? Let me know what you think in the comments!

Leave a Reply

Your email address will not be published.