If you do PHP development, moving to a PHP IDE is extremely beneficial especially when debugging. PHPStorm is a great IDE for PHP development and has tons of support for various frameworks and from the community. In this post, I will walk through the steps to setup and configure a PHP development environment on Ubuntu using Percona MySQL, Nginx, PHP 7, XDebug, and PHPStorm.
To get started we need to add the repos for our software.
Add the repo for NGINX stable from nginx.org.
wget https://nginx.org/keys/nginx_signing.key sudo apt-key add nginx_signing.key sudo add-apt-repository "deb http://nginx.org/packages/ubuntu/ $(lsb_release -sc) nginx" rm nginx_signing.key
Add repo for Percona Server for MySQL 5.7 from www.percona.com. I recommend Percona over stock MySQL and over MariaDB due to better performance and stability, (more on this in an upcoming blog post).
wget https://repo.percona.com/apt/percona-release_0.1-4.$(lsb_release -sc)_all.deb dpkg -i percona-release_0.1-4.$(lsb_release -sc)_all.deb rm percona-release_0.1-4.$(lsb_release -sc)_all.deb
Install the packages. You may also want to include any other PHP extensions you might need.
sudo apt update sudo apt install git nginx hhvm percona-server-server-5.7 php7.0-fpm php7.0-cli php7.0-xdebug php7.0-curl
We will also install Composer to easily add packages to our PHP apps.
curl -sS https://getcomposer.org/installer | php
Move composer to bin.
sudo mv composer.phar /usr/local/bin/composer
Now is the time to install PHPStorm from the JetBrains website.
With the essentials installed, it’s time to configure it.
sudo mkdir -p /var/www/dev/public/
nano /etc/nginx/conf.d/default.conf
server { listen 127.0.0.1:80; root /var/www/dev/public; index index.php; server_name localhost; location ~ \.(php)$ { fastcgi_keep_conn on; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } client_max_body_size 2M; location / { try_files $uri $uri/ /index.php$is_args$args; } }
sudo service nginx restart
Time to enable XDebug for our PHP server. (NOTE: Do not do this on a production server.) To enable this for the CLI, make the same file inside
/etc/php/7.0/cli/conf.d/20-xdebug.ini
sudo nano /etc/php/7.0/fpm/conf.d/20-xdebug.ini
zend_extension=xdebug.so xdebug.remote_enable=1 xdebug.remote_host="localhost" xdebug.remote_handler=dbgp xdebug.remote_port=9000 xdebug.remote_autostart=1
We are now ready to setup PHPStorm. Open up the IDE, and add your /var/www/dev/ directory as your project folder. Out of the box, PHPStorm’s debugger attached for me, but if you are having issues, try the PHPStorm docs or leave a comment. =)
You now should have a full PHP development environment, time to get cracking on that app!
Leave a Reply