Upgrading and Downgrading PHP 5.6 and 7.0

Followed the instructions
https://askubuntu.com/questions/761713/how-can-i-downgrade-from-php-7-to-php-5-6-on-ubuntu-16-04#answer-762161

Possible Errors

If you need to install a new fresh apache2
https://askubuntu.com/questions/451674/cant-install-apache2-again#answer-451679

If you come across an error similar to below when running
$ systemctl status apache2.service

ERROR:
 *** Restarting web server apache2                                                                                                                                          [fail]
 * The apache2 configtest failed.
Output of config test was:
apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/php7.load: Cannot load /usr/lib/apache2/modules/libphp7.so into server: /usr/lib/apache2/modules/libphp7.so: cannot open shared object file: No such file or directory
Action 'configtest' failed.
The Apache error log may have more information.**

Solution:
$ sudo apt-get install libapache2-mod-php7.0
https://askubuntu.com/questions/536128/apache2-start-error-when-using-php5-module-ubuntu-server#answer-536141

If error “AH00534: httpd: Configuration error: More than one MPM loaded”

Solution:
Disable all apache2/mods-enabled/mpm* except for mpm_prefork
https://stackoverflow.com/questions/24060620/error-starting-apache-httpd-configuration-error-more-than-one-mpm-loaded#answer-25447262
http://www.mylinuxguide.com/apache-is-running-a-threaded-mpm-but-your-php-module-is-not-compiled-to-be-threadsafe/

tags:
php5.6
php7.0

Laravel Homestead Vagrant windows setup

video notes:
9:35 editing hosts files
6:13 putty ssh to vagrant server

# start vagrant
# inside C:\Users\username\Desktop\vagrant\Code
$ vagrant up

# the url will be http://homestead.app:8000/

# vagrant for public access
# http://stackoverflow.com/questions/18051760/how-to-access-vagrant-box-in-public-network#answer-18068143

config.vm.network :public_network, ip: "192.168.1.21"

# to allow symbolic links, ln -s
# in windows 7 you need to run the terminal as administrator
https://github.com/cityindex-attic/logsearch/issues/7#issuecomment-19054050

xdebug setup

Quick way

sudo apt-get install php5.6-xdebug

Long Way


http://xdebug.org/wizard.php

copy output of
$ php -i | xclip
or
<?php phpinfo(); ?>

paste into
http://xdebug.org/wizard.php

Follow the instructions on that site after you submit

$ wget http://xdebug.org/files/xdebug-2.2.4.tgz
$ tar -xvzf xdebug-2.2.4.tgz
$ cd xdebug-2.2.4
# install apt-get install php5-dev for phpize to work
$ phpize
$ ./configure
$ make
$ cp modules/xdebug.so /usr/lib/php5/20090626+lfs

or one command setup
$ sudo pecl install xdebug

Edit /etc/php5/apache2/php.ini or /etc/php5/apache2/conf.d/xdebug.ini
Edit /etc/php5/cli/php.ini (for phpstorm interpreter)

paste
[xdebug]
zend_extension= [extension provided in xdebug.org]
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.show_local_vars=1

for phpstorm interpreter to work you need to determine what is the “Loaded Configuration File” and paste the [xdebug] code in aswell (Loaded Configuration File => /etc/php5/cli/php.ini)
$ php -i | grep php.ini

restart webserver

https://forums.netbeans.org/post-114142.html#114142
if using port 9003 because I believe fastCGI is using 9000


PHPSTORM 7 setup
Firefox add-on:
The easiest Xdebug
JetBrains Firefox extension 0.6.0

File -> Settings -> PHP

File -> Settings -> PHP -> … (next to the interpreter input)
(debugger will only show if you edit the /cli/php.ini)

File -> Settings -> PHP -> Servers

File -> Settings -> PHP -> Servers -> Validate Remote Environment

File -> Settings -> PHP -> Debug

Run -> Edit Configurations

Create javascript debug

Make sure the listener is on

Run the javascript debugger then its going to ask to install the firefox add-on but it will only work after you restart your computer.

Also make sure you set a break point and that break point is at a point in page it can arrive because if an error the page will terminate without arriving at the break point.

Went to
http://www.jetbrains.com/phpstorm/marklets/
Generated xdebug bookmarklets with idekey in the site as PHPSTORM
added to firefox bookmark ‘start debugger’
click on the bookmarklet ‘start debugger’ while in my ‘localhost’ site

WORKED

resources:
http://ubuntuforums.org/showthread.php?t=525257

Laravel blade not compiling or showing in browser.

I was having an issue that when I saved a file using winscp to laravel4 the view in the browser would not change. I figured out that laravel view blades caches to app/storage/view and the way it knows whether to recompile it is by the dates the view blade file was changed and the cache file was created. In winscp the cache file was off by an hour ahead.

The way I fixed this was by changing winscp login environment settings to “Preserve Remote Timestamp”

and also adjusting my server time to match the actual time on my other computer.

The server time has to be an earlier time than your computer

Also this was a fix to the issue with sublimetext sftp package sync funcitonality.

Resources:
http://forums.laravel.io/viewtopic.php?id=2550

Optimizing PHP by minimize the request to the database

Optimizing PHP by minimize the request to the database by putting into a array

The array key is a hash and the value is the id. The reason you hash the key is because your looking up more than one field such as the first_name, last_name and company. Instead of putting this all together into a long string you can hash it into 8 characters and when your going to run the database check the array first to see if the query was already ran if not run the sql and append it to the array. It’s a cache.

	function get_user($first_name, $last_name, $company) {
		$hash = hash('crc32', $first_name . $last_name . $company);

		if (array_key_exists($hash, $this->users_cache)) {
			echo 'from cache';
			$ownerID = $this->users_cache[$hash] ;
		}
		else{
		
			$ownerID = db_lookup("SELECT userID
				FROM `users`
				WHERE `last_name` = '" . trim($last_name) . "' 
				AND first_name = '" . trim($first_name) ."' 
				AND company LIKE '%". $company ."%'"
			);

			$this->users_cache[$hash] = $ownerID;

		}

		return $ownerID;
	}

OwnCloud Server

ownCloud is a software suite that provides a location-independent storage area for data

Have php and webserver installed. (I’m using ubuntu 11.10)
$ sudo apt-get install apache2 php5 mysql-server php5-mysql phpmyadmin

Install ownCloud
$ sudo wget http://mirrors.owncloud.org/releases/owncloud-4.5.7.tar.bz2
$ sudo bunzip2 owncloud-4.5.7.tar.bz2
$ sudo tar -xvf owncloud-4.5.7.tar
$ sudo mv owncloud/ /var/www/
$ sudo chown -R www-data:www-data /var/www/owncloud/

Done. Now go to localhost/owncloud
Make ownCloud accessible outside your home network.

You may receive this error:
Your data directory and your files are probably accessible from the internet. The .htaccess file that ownCloud provides is not working. We strongly suggest that you configure your webserver in a way that the data directory is no longer accessible or you move the data directory outside the webserver document root.

This mean that your .htaccess doesn’t have permission to override the php.ini
You don’t have to change anything to make owncloud work but if you want this feature read “Allow htaccess to override php.ini”

To increase amount of data that can be uploaded.
There’s two options you can edit upload_max_filesize and post_max_size in the /etc/php5/apache2/php.ini file or edit the .htaccess if you did the above configuration.