PHPStorm is one of the best IDE’s to develop in PHP. I recently came across tons complex php cli scripts and needed a way to debug them.
Most important things to configure are
- Set up xdebug correctly on the remote server. Dont use xdebug.remote_connect_back. Instead use xdebug.remote_host
- Xdebug must be set up for php cli – check with the command php -i | grep xdebug and you should see many entries
- Set up deployment path mapping correctly in your project settings – a lot of people miss this and wonder why debug is not working
- Check your firewalls on both machines, make sure required ports are open, especially port 9000
- Check debugger settings in phpstorm and make sure you have break at first line set up
In the PHPStorm tutorial, it asks you to set up SSH tunnel. If you are not doing tunneling, you should set these environment variables on the remote server
Eg, if my remote server is centos, i will set these 2 variables
export XDEBUG_CONFIG="idekey=PHPSTORM"; export PHP_IDE_CONFIG="serverName=myDeploymentServerName";
serverName is the name of the server you set up for deployment in phpstorm deployment settings
these variables are valid for the session, if you logout and log in, you have to set them again.
You can add these to your .bashrc file in your home folder to make them permanent
In case you want to use xdebug.remote_connect_back, you might have to run your php scripts on the command line with additional args like this
php -dxdebug.remote_enable=1 -dxdebug.remote_host=10.0.1.2 -dxdebug.remote_connect_back=0 /path-to-php-script
I am doing this on
- VirtualBox 5.0.12
- Windows 8.1 64 bit Host
- CentOS 7 server 64 bit guest up to date
- Start CentOS 7 guest
- From the Devices Menu,go to Optical Drives and remove previous CD/DVD using the Remove Disk from VirtualDrive
- Then click on Devices and select Insert Guest AdditionsCD Image.
- This will put the Guest addition cd into /dev/cdrom in CentOS
- SSH into CentOS and mount the cdrom with the command
mount /dev/cdrom /mnt
- Install required libraries
sudo yum install bzip2 gcc kernel-devel dkms
- install the guest addition, nox11 is to indicate that we dont have a GUI
bash /mnt/VBoxLinuxAdditions.run --nox11
- It will install and finally give some messages like below
Verifying archive integrity... All good. Uncompressing VirtualBox 5.0.12 Guest Additions for Linux............ VirtualBox Guest Additions installer Removing installed version 5.0.12 of VirtualBox Guest Additions... Removing existing VirtualBox DKMS kernel modules[ OK ] Removing existing VirtualBox non-DKMS kernel modules[ OK ] Copying additional installer modules ... Installing additional modules ... Removing existing VirtualBox DKMS kernel modules[ OK ] Removing existing VirtualBox non-DKMS kernel modules[ OK ] Building the VirtualBox Guest Additions kernel modules[ OK ] Doing non-kernel setup of the Guest Additions[ OK ] You should restart your guest to make sure the new modules are actually used Installing the Window System drivers Could not find the X.Org or XFree86 Window System, skipping.
- Shutdown the CentOS VM and add shared folders and select Auto Mount
- Start the CentOS VM and the shared folder should be available at /media on CentOS
In CentOS, the default system editor is VI
If you want to edit the crontab with crontab -e command, the text editor that opens up is VI
In order to change the system wide default text editor to nano, edit /etc/bashrc and put the below line in it at the bottom
Exit and login again for the changes to take effect
Security-Enhanced Linux (SE Linux) is a Linux kernel security module that provides a mechanism for supporting access control security policies. It controls which applications can access what directories in the system
For example, the default rules for apache is to only be allowed to access /var/www and /var/logs/httpd and some other configuration directories. If apache tries to access any other directory, then SELinux will not permit it if it is enabled.
Example, default web root for apache is /var/www, if you change it to /home/code, then SELinux will not allow apache to access files in /home/code and the application will fail to load on the web page
You have 2 options,
- manually add the new location to SELinux apache rules by giving appropriate groups ( recommended )
- disable SELinux permanently
Similary if you change the data directory for mysql, you will come across this issue
Sometimes you need a quick fix and might need to disable SELinux
This is not recommended on production systems. Do it on your own risk.
Command to check if SELinux is active is sestatus
[root@ip-172-30-0-220:/]$ sestatus SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode: enforcing Mode from config file: enforcing Policy MLS status: enabled Policy deny_unknown status: allowed Max kernel policy version: 28
Current Mode is set to enforcing, which means SELinux is active
Temporarily Disabling SELinux
To temporarily disable SELinux, use the command
sudo setenforce 0
Then check with sestatus and Current Mode should be permissive. This will revert back on boot to enforcing
To enable SELinux again, use
Permanently Disabling SELinux
change SELINUX=enforcing to SELINUX=disabled
restart the server and check with sestatus command
Doing this on CentOS 7 64 bit and MySQL 5.6 community edition
Sometimes it is better to put mysql in a separate partition than its regular location
Typically the mysql database are located in /var/lib/mysql
I want to change it to /var/data/mysql
Modify the paths as required in the below commands
systemctl stop mysqld.service
create new mysql data directory
modify /etc/my.cnf and point to new data directory – add the client section to the top
[client] port=3306 socket=/var/data/mysql/mysql.sock [mysqld] datadir=/var/data/mysql socket=/var/data/mysql/mysql.sock
copy all files from /var/lib/mysql to the new directory /var/data/mysql
cp -r /var/lib/mysql/* /var/data/mysql
permissions for the new directory
chown -R mysql /var/data/mysql; chgrp -R mysql /var/data/mysql; chmod -R g+rw /var/data/mysql;
also modify SELINUX settings to allow mysql to use the different path
# add context and make it permanent semanage fcontext -a -s system_u -t mysqld_db_t "/var/data/mysql(/.*)?" restorecon -Rv /var/data/mysql
systemctl start mysqld.service
MySQL should start cleanly.
You can verify the change by creating a test database.
Then go to /var/data/mysql and you should be able to see the new database there
Some times, when we generate self signed certificates, some libraries need it to be a part of the operating systems trusted certificates
I am doing this on CentOS 7 and for openSSL
This will only work for apps/libraries that use OpenSSLs trusted certificate list
I already have my self signed certificate in /etc/pki/tls/certs/my-self-signed-cert.crt
cp /etc/pki/tls/certs/devinviteright.crt /etc/pki/ca-trust/source/anchors sudo update-ca-trust
Putty is a versatile tool for remote SSH access – however the color schemes are not too impressive. The blue especially is really bad. You can change the blue color in the settings but what if you already have a ton of putty Saved Sessions. You will have to painfully modify each. There is a better way by directly modifying the registry entry for all sessions at once.
I am doing this on Windows 7.
A word of caution, we will be modifying registry entries. I have done this many times without problems, however I will still say, do it at your own risk.
Right, lets get to it then.
Press Windows Key + R to get the Run prompt
Enter regedit and press Ok. This will open the registry editor
Navigate to HKEY_CURRENT_USER -> Software -> Simontatham -> PuTTY
Expand Sessions and you should see all your Saved Sessions listed there
Right Click on Sessions and select Export
Save the file as putty-original.reg somewhere where you can locate it
Dont modify this file, this is your backup file
If something goes wrong or you dont like the changes, you re-import this file and you are back where you started
Make a copy of the file call it putty-new.reg
Open putty-new.reg in your text editor ( i am using notepad++ or sublime )
This will have color value blocks for all your Saved Sessions.
You have to replace the entire color block with the new color block
Replace the color blocks with this new color block – do this for all color blocks
"Colour0"="217,230,242" "Colour1"="217,230,242" "Colour2"="14,27,48" "Colour3"="14,27,48" "Colour4"="14,27,48" "Colour5"="217,230,242" "Colour6"="0,0,0" "Colour7"="46,46,46" "Colour8"="215,49,64" "Colour9"="223,100,112" "Colour10"="80,194,54" "Colour11"="128,202,105" "Colour12"="215,184,54" "Colour13"="223,194,105" "Colour14"="58,91,199" "Colour15"="97,127,204" "Colour16"="206,49,199" "Colour17"="216,100,207" "Colour18"="71,194,189" "Colour19"="122,202,200" "Colour20"="211,211,211" "Colour21"="255,255,255"
Once you have replaced blocks for all sessions in the file, save putty-new.reg
Double click on putty-new.reg to import the new settings.
Windows will ask for permissions and display warnings, go ahead click ok
Exit out of your current putty sessions and re connect.
You should see the new colors and color scheme.
If something went wrong, or you did not like the color scheme, double click putty-original.reg to get back to your old settings.
Keep putty-original.reg safely.
There are many links on the web which will let you build your own color schemes – try them
This color scheme I found here