Servers

How to Find Apache Error Log Path and Fix Issues

If your Apache server is not loading a webpage at all or giving an error, you’ll have to troubleshoot it. As always, first, try restarting the service and rebooting the machine. If it still fails, use the steps below to find the cause of the issue.

How to Find the Error Log Path

Run these commands in order to diagnose and fix Apache configuration issues. It’s assumed you have root privileges if you don’t, add sudo at the front. Instead of httpd you may also use apachectl which is a wrapper command around httpd.

First, test if there are issues with the configuration.

httpd -t

If you see any issues there, fix them first.

If not, then check your server error and custom logs. You can use httpd to find your error log locations.

httpd -D DUMP_INCLUDES

Then for each of the config files, find where the log files are located.

cat /usr/local/etc/httpd/httpd.conf | grep -E "ErrorLog|CustomLog"

If the above fails, try to locate the file with the locate command.

locate error_log

Read the Last Log Messages

Note the log file paths mentioned in the result. (Ignore the commented lines with #. Most of the errors will be written to error_log or access_log files. You can read the log, or use tail command to read the last lines.

tail /usr/local/var/log/httpd/error_log

You can increase the output lines with -n flag. For example, output last 50 lines.

tail -n 50 /usr/local/var/log/httpd/error_log

Other Possible Causes for Apache Server Restart Failures

Apache might sometimes leave a corrupt Process ID file, which might cause it to fail. If that happens, you may have to manually delete the file.

apachectl stop
rm /usr/local/var/run/httpd/httpd.pid
apachectl start

Or use all 3 commands in one line.

apachectl stop && rm /usr/local/var/run/httpd/httpd.pid && apachectl start

The pid file is genrally located in your httpd folder. If it’s a custom path, it will be listed on your httpd.conf file as a `PidFile variable.

Example (in httpd.conf)

PidFile /yourpathto/httpd.pid

MacOS · Technical · Today I Learned

Terminal Commands to Improve Productivity on Mac

Open any IntelliJ Idea editor from current folder. (Change PhpStorm to your editro’s name)

open -a PhpStorm ./

GIT – Reset uncommitted changes and files

git reset --hard && git clean -fd

Sublime Text – Create a CLI launcher

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl

Save Aliases

If you don’t want to remember these, you can add these to your ~/.bashrc or ~/.zshrc file.

# edit hosts file
alias edithosts='subl /etc/hosts'

# reset git folder
alias nah='git reset --hard && git clean -fd'

# open current folder in idea editor
alias storm='open -a PhpStorm .'

# clear DNS history
alias cleardns='sudo killall -HUP mDNSResponder'

# NPM install
alias ni='npm install'

After you update ~/.bashrc or ~/.zshrc, run the applicable command in terminal to load the changes.

source ~/.bashrc
// OR
source ~/.zshrc
MacOS · Today I Learned

Monosnap for Mac won’t Start? Here’s How to Fix

Monosnap is a great tool to take screenshots and annotate for Mac and Windows. With MacOS updates, sometimes it may not start. You can try reinstalling it, but it may not solve the problem.

Then you need to try removing all files created from it.

Open Terminal in Mac, and run these commands.

rm -rf ~/Library/Application\ Scripts/com.monosnap.monosnap
rm -rf ~/Library/Containers/com.monosnap.monosnap
rm -rf ~/Library/Application\ Scripts/com.monosnap.MonosnapLauncher

If you need to see if any crash reports were generated, run this.

ls ~/Library/Application\ Support/CrashReporter/Monosnap_*.plist

To delete the crash reports,

rm ~/Library/Application\ Support/CrashReporter/Monosnap_*.plist

After that, reinstall Monosnap, and the icon should showup in your menubar.

MacOS · Technical

New Terminal Setup Steps for MacOS

Here are the shortcuts and Terminal setup commands I used with MacOS.

Create a command to open Sublime from CLI.

sudo mkdir /usr/local/bin

sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

Edit the `~/.bash_profile` file, and include the following.

alias edithosts='subl /etc/hosts'

Update the `/etc/hosts` file to block unwanted sites. Use this example hosts file.

Install Homebrew

Install homebrew by following instructions on brew.sh

Use Homebrew Apache

sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

Install Homebrew Apache

brew install httpd
sudo brew services start httpd

Configure Apache Defaults

Before using apache, you need to edit the default config. You can find the default config location with the command `httpd -V

Open the file listed for the SERVER_CONFIG_FILE parameter, and make the following changes. (Usually, this will be your httpd.conf file)

# Comment out the default 8080 port if required.
# Listen 8080
# Open a new port
Listen 80

.....

# Uncomment mod_rewrite module
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so

.....

# You may want to switch the default user/group on a local dev machine
User your_local_username
Group staff

....

# Change the default document root if required
DocumentRoot "/usr/local/var/www"

# In the following <Directory> block, change AllowOverride to let .htaccess make changes
    AllowOverride All

# Uncomment vhosts config
Include /usr/local/etc/httpd/extra/httpd-vhosts.conf

Update Virtual Hosts

VirtualHosts are typically located in extras/httpd-vhosts.conf file relative to the above file. Following is the minimum code block you need to include in vhosts.conf file.

<VirtualHost *:80>
    ServerName mytestsite.test
    DocumentRoot "/Users/shane/mytestsites/public"
</VirtualHost>

For other sites, you can duplicate the above block.

Update hosts file

Your hosts file is located at /etc/hosts. For the test domains to work, you must add a new entry in a hosts file. (The local domain name used here, comes from ServerName used above.

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost

127.0.0.1 mytestsite.test

Restart Apache

After saving all files, check if the Apache config is having any issues with the command httpd -t. If not, restart Apache with brew services restart httpd.

Now you can visit the tset domain in a browser and see the domain. If you get any errors, check the logs for any errors. The default error logs are in the paths below. You can check the latest errors with the tail command.

tail /usr/local/var/log/httpd/error_log

Installing PHP (via Homebrew)

-- Install PHP
brew install php@8.0

After an installation, you’ll see instructions similar to this.

To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php8_module /usr/local/opt/php@8.0/lib/httpd/modules/libphp8.so

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/8.0/

php@8.0 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have php@8.0 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/php@8.0/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/usr/local/opt/php@8.0/sbin:$PATH"' >> ~/.zshrc

For compilers to find php@8.0 you may need to set:
  export LDFLAGS="-L/usr/local/opt/php@8.0/lib"
  export CPPFLAGS="-I/usr/local/opt/php@8.0/include"


To have launchd start php@8.0 now and restart at login:
  brew services start php@8.0
Or, if you don't want/need a background service you can just run:
  php-fpm

So you need to make above changes.

  • Open httpd.conf and add LoadModule line.
  • Add <FilesMatch> block.
  • Change DirectoryIndex line.

Consider installing these packages, as they’re commonly used.

-- imagemagick
brew install pkg-config imagemagick
pecl install imagick
-- if required, restart apache
brew services restart httpd

-- youtube-dl
brew install youtube-dl

Then update PATH as mentioned above, and start the service.

Change default settings

-- Set the git merge strategy
git config --global pull.ff only

Other Commonly Used Packages

Common Errors for Troubleshooting

Q: Apache log error message client denied by server configuration

A: Check your DocumentRoot and <Directory> paths. Probably it’s incorrect.

Q: MySql Connections fails with an error mysql the server requested authentication method unknown to the client

A: This is probably because of an authentication plugin system change with MySQL 8+. For local development, you may change the root password to solve this. This must not be done on non-local machines.

First, login as the root from CLI.

mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';  

On the example above, change new_password to your new root password.

Uncategorised

How to Delegate for Results

Delegation is essential for faster growth and to make the most of your time. Often, delegation has been made unnecessarily complicated than it should be.

People don’t like to delegate stuff, because they believe “if it should be done right, I need to do it”. This is often a result of poor delegation skills combined with the wrong person assigned to the task.

Here are the steps you should follow to delegate effectively.

1. Eliminate:

Before you delegate, see if your task needs to be done at all. If the end result you’re after is not going to change anything, or if it’s going to improve a vanity metric, just ignore the task. Delegating a worthless task to someone else doesn’t make it more worthy.

2. Pick the Person:

Have a baseline criteria on how you select people for tasks. When there are multiple candidates, often you’ll be better off picking the person who does satisfactory work faster, rather than who does perfect work unreliably.

3. Define Clearly:

Clearly define the task on how it should be done. Understand that you already have a lot of background information about the task in your head, which the other person doesn’t have access to. So you have to put the task, in writing, because if you just say it, people can forget. Also having written instructions is good for the other person to refer if they get lost.

Here are some points you should cover.

  1. What’s the end outcome you’re after.
  2. What steps (if any) that MUST be followed.
  3. What should NOT be done.
  4. When you expect a response and how
  5. When you expect the task (or milestones) to be completed
  6. How the task and milestones to be delivered.
  7. What to do when there are questions about the task.
  8. How and when you expect to be kept updated.
  9. Give diagrams, designs, and other visual elements to ensure the task is properly understood by both parties.

4. Give Authority:

If you need something to be done, you need to give that person authority and access to all the required information. Don’t let them come back to you seeking parts of information, because that will just delay the process.

The level of authority can be:

Level 1: Inform – Just get the information and do the work

Level 2: Initiate – Progress and do the task within the given boundaries.

Level 3: Act – Do the task by any means and any costs. At this level, the person will have the full authority to get the task done, at any means, and at any cost – which means they’ll pay expenses out of pocket and will expect you to reimburse later.

5. Supervise at Checkpoints:

After a task is delegated, you must supervise it at set intervals.

In the beginning, you must supervise at regular intervals to ensure the task is on the right track after you’ve verified it, you can lengthen the checkpoint intervals.

Follow a Fibonacci Sequence to make this process easier. 0, 1, 1, 2, 3, 5, 8….

Example:

Follow up on Days 1, 1, 2, 3, 5, 8, 13, 21

However, if you see a task going off the rails at some point, then you have to stop and start the sequence from that point again.

6. Debrief:

After a task is done, hold a debrief session to see what worked and what didn’t. Get the learnings, and improve the system again, to prevent any issues which may have happened.