List

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Posts

1 2 3 4
February 28th, 2018

Concluding the February Challenge

Writing every day for the month of February has been an experience, and has changed my perspective on writing tremendously. […]

February 27th, 2018

Cloudflare2DB

Cloudflare stats are very useful, but they expire and can’t be tracked over a long period of time. That’s why […]

February 26th, 2018

Nightly Database Backups to Google Drive

If you have a Google Apps account (a business account with more than 5 users or one provided by your […]

February 25th, 2018

Sublime Text

Sublime Text is a really powerful text editor and includes tons of functionality relevant to programming. I will dive into […]

February 24th, 2018

Great Resources for Student Developers

Being enrolled in a university comes with its pros and cons (a topic itself worthy of many other blog posts), […]

February 23rd, 2018

What is MVC?

MVC is a term thrown around lots of software development projects. Laravel, Zend, CodeIgniter, Ruby on Rails, Django, iOS, and […]

February 22nd, 2018

Getting Started With Phalcon PHP

To get started with Phalcon, I already have my server stack setup with Ubuntu 16.04, Percona MySQL, Nginx, and PHP […]

February 21st, 2018

What is Phalcon?

Phalcon is a modern PHP framework with the typical feature set you’d expect. Database ORM, error handling, MVC architecture, and […]

February 20th, 2018

Setting Up a PHP Development Environment

If you do PHP development, moving to a PHP IDE is extremely beneficial especially when debugging. PHPStorm is a great […]