Showing posts with label Mac. Show all posts
Showing posts with label Mac. Show all posts

Wednesday, March 22, 2023

How to configure PHP and Apache with Mac OS Monterey and above

 PHP has been removed since Monterey 

So we're going to install latest PHP using Home brew and edit the configuration files of apache web server so PHP web hosting is supported from local machine.

 - If you don't have Homebrew installed , use the below terminal command to set up home brew

     /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

 - Once the brew set up is success , feed the below command in terminal to instal latest PHP 

    brew install php

- start php using below command

   brew services start php

 - create sites directory under current user root directory using below command

     sudo mkdir ~/Sites

- open apache folder and create username.conf using below terminal command

     cd /etc/apache2/users
     sudo nano username.conf

- Feed the below text into the file and press Ctrl+o to save
    
    <Directory "/Users/username/Sites/">
      AllowOverride All
      Options Indexes MultiViews FollowSymLinks 
      Require all granted
    </Directory>

 - Now let's open httpd.conf using the below command
     
     sudo nano /etc/apache2/httpd.conf

- Uncomment the below lines from the above file

   LoadModule authz_core_module libexec/apache2/mod_authz_core.so
   LoadModule authz_host_module libexec/apache2/mod_authz_host.so
   LoadModule userdir_module libexec/apache2/mod_userdir.so
   LoadModule include_module libexec/apache2/mod_include.so
   LoadModule rewrite_module libexec/apache2/mod_rewrite.so

- Add the following lines into the same above file
   
  LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so

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

- Uncomment the below line 

  Include /private/etc/apache2/extra/httpd-userdir.conf

- Search for AllowOverride None in the file and replace with below text

    AllowOverride All

- Save the file by pressing Ctrl+o

- Open one more apache file using below command

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

- Uncomment the below line and save it
  
    Include /private/etc/apache2/users/*.conf

- Restart the apache using below command

   sudo /usr/sbin/apachectl restart

- Check if webserver is running by opening the below url in browser

   http://localhost

- To check if PHP is supported , let's create a php file in webserver directory and try acessing it in the browser

   sudo touch /Library/WebServer/Documents/index.php
   sudo nano /Library/WebServer/Documents/index.php

and enter the below text and save it.

   <?php 
    phpinfo(); 
  ?>

- Check if PHP is supported by opening below url in browser
 
   http://localhost/index.php
 
- If PHP is not signed yet , then you might get an error. Find the exact error message using below command in terminal

 apachectl -t -D DUMP_VHOSTS 

- If you find code signing issue in the above response, then Create a CA for code signing and do code signing

- Now feed below command to sign the php using terminal 

      codesign --sign "your-authority-name" --force --keychain ~/Library/Keychains/login.keychain-db /opt/homebrew/opt/php/lib/httpd/modules/libphp.so

- Open the httpd.conf again and change the uncommented php line with below text

     LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so "your-authority-name"

- Restart the apache again with below command

    sudo /usr/sbin/apachectl restart

- Access the PHP file again through browser, you should be able to see a proper php web page now



Thursday, February 4, 2021

Reclaim your memory from mac SSD without using any third party software

I took following steps and saved over 100GB


1. Opened Devices & simulators from Xcode and removed all the unwanted simulators

2. Cleared all the unwanted simulator runtimes from the below path

    /Library/Developer/CoreSimulator/Profiles/Runtimes

3. Removed all the simulator logs from the below path

     ~/Library/Logs/CoreSimulator/

4. Removed the unwanted device support and all the device logs,derived data and user data from below path

    ~/Library/Developer/Xcode/iOS DeviceSupport

    ~/Library/Developer/Xcode/iOS Device logs

    ~/Library/Developer/Xcode/DerivedData

    ~/Library/Developer/Xcode/UserData

5. Remove the temporary files and caches from the below path

     /private/var/folders/

6. Remove the system caches from the below path

    ~/Library/Caches

FYI:

It's always good to take a back up in time machine before doing , just in case if something goes wrong.

Sunday, November 24, 2019

Uprading to SSD from HDD on mac book pro

Recently my mac book pro has become very slow and found out that my HDD(Hard Disk Drive) has become faulty and that's the reason it's very slow.

I went to apple store to fix it and it was little expensive over there like £230 and they can do only as is replacement for HDD with another HDD and they won't do HDD to SSD(Solid State Drive)

So I went over to third party apple repair shop and they were ready to upgrade my mac book pro with SSD but again it was little expensive like £280.   

So I decided , I would do it myself and fixed it successfully so I thought I would share what I did to do this so that it's helpful for anyone who's looking to do.

1.  Buy the right SSD for your machine. I recommend Cruical.com. Visit this site and it'll ask you to download an app and it'll tell you what are the SSD you can buy for your machine.

2. Buy a Laptop or computer repairing screw driver set. 

3. Remove the screws from lower case.

4. Remove the battery connection cable from the motherboard

5. Remove the battery using pull tab

6. Disconnect the HDD connecting cable

7. Take out the HDD and remove the retaining screws from the side of HDD

8. Attach the retaining screws to SSD 

9. Put the SSD in place of HDD

10.Attach the connecting cable on SSD then attach the battery cable with mother board

11.Put all the screws back

12. Start up your mac and press command + option + R 

13. This will bring internet recovery 

14. After recovery choose disk utility and erase the newly bought SSD with Format: APFS and Partition type: GUID

15. After erasing , choose internet recovery or restore time machine back up

Then follow the normal steps like entering the apple id to sign in once the recovery is over. That's all

Wednesday, January 31, 2018

Easy to use java decompiler

Recently I had to get java class files out of JAR that was provided to me.

I could get easily class files from JAR by renaming the file from myLib.jar to myLib.zip.

But I couldn't find a easy way to decompile .class file (byte code ) back to java.

I found some online services to do that but its not safe and most of them are blocked due to firewall in corporate network.

and doing this manually with javap which is part of JDK is not good as it displays other information than original source code which makes kind of hard to copy and save as java file.

so I thought like I would use a stand alone desktop program.

I found JD GUI good

because it provides good UI(Tree view explorer) for us to see and shows the actuall source code and easy to export as java file

I tried couple of other Stand along programs but it wouldn't support latest mac.


Thursday, March 10, 2016

Show hidden files in mac osx

1.Open the terminal and enter

   defaults write com.apple.finder AppleShowAllFiles YES

2.Relaunch the finder by holding alt/option and rightclick on finder and choose relaunch

The other way is true for hiding the hidden files in finder

Saturday, March 21, 2015

Localhost location in OSX

There are actually two place where where OSx serves website by default:

/Library/WebServer/Documents --> http://localhost