Setup PHP for NGINX - charleshross/soarin GitHub Wiki
This guides assumes you have already installed a fresh copy of Debian Linux Wheezy 64bit (https://www.debian.org/distrib/netinst) on your server or virtual machine.
- Words
like thisare commands to run on your server or virtual machine. - The 'pico' text editor used in this documentation comes with Debian and is super simple to use. To open a file just type
pico [location of your file]. Use arrow keys to navigate, and in order press "[CTRL]+[X], [Y], [ENTER]" to save file changes.
To begin installing, SSH into your Linux Debian server as root.
PHP
PHP is a server-side scripting language used in over 240 million websites. This documentation will compile and install PHP-FPM for NGINX. All of the Soarin framework is running PHP at its heart.
Compiling and Installing PHP from Source Code
Install required dependencies
apt-get install libxml2-dev libcurl4-gnutls-dev libpng12-0 libpng12-dev libjpeg62 libjpeg62-dev
Install pspell dependencies
apt-get install aspell libaspell15 libaspell-dev libpspell-dev
If you installed PostgreSQL you need your version of the 'libpq-dev' package. As of this writing the next command was:
Note: If you installed PostgreSQL you need your version of the 'libpq-dev' package. As of this writing the command was:
apt-get install libpq-dev=9.3.2-1.pgdg70+1
Make install directory and move into it
mkdir /opt/php
cd /opt/php
Download latest version of PHP
wget http://us1.php.net/distributions/php-5.5.14.tar.gz
Decompress file
tar -xvf php-5.5.14.tar.gz
Move into PHP source directory
cd php-5.5.14
Run configuration command
./configure \
--prefix=/opt/php \
--with-jpeg-dir \
--with-mysqli \
--with-curl \
--enable-exif \
--with-gd \
--enable-mbstring \
--enable-pdo \
--enable-sockets \
--enable-fpm \
--with-pear \
--with-pspell=/usr \
--with-openssl \
--enable-opcache \
--with-mysql=shared \
--with-pdo-mysql
Note: If you installed vanilla MySQL instead of Percona Server, then change the
--with-mysql=shared \line to--with-mysql=shared,/opt/mysql/server-5.6 \
Note: If you didn't install Percona Server or any MySQL database, then omit the last two lines of the configuration, otherwize it will error.
Note: If you installed PostgreSQL, add the line
--with-pgsql=/var/lib/postgresql/9.3/main --with-pdo-pgsqlto the configuration command
Run make all install
make all install
Note: Be patient this may take a while. If you mess up and have to re-compile run:
make cleanmakeandmake install
Create new user group php
groupadd php
Add new user to php group
useradd -r -g php php
Copy over PHP-FPM configuration file
cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf
Open the /opt/php/etc/php-fpm.conf file with a text editor
pico /opt/php/etc/php-fpm.conf
change the line:
;pid = run/php-fpm.pid
to this:
pid = /opt/php/var/run/php-fpm.pid
and change these lines:
user = nobody
group = nobody
to:
user = php
group = php
Copy over php.ini file
cp /opt/php/php-5.5.14/php.ini-development /opt/php/lib/php.ini
Open the /opt/php/lib/php.ini file with a text editor
pico /opt/php/lib/php.ini
Find the 'DYNAMIC EXTENSIONS' listing and add this line to the bottom (you can actually add it anywhere in the file but its more organized if you put it with the rest of the extensions). Adding this line to php.ini activates opcacheing, speeding up your PHP scripts in the background.
zend_extension=opcache.so
Save and close the file
Note: If you installed regular MySQL, you may need to provide the location of your MySQL socket. Modify the line
mysqli.default_socket =tomysqli.default_socket = /opt/mysql/server-5.6/mysql.sock. For PDO make sure to also modifypdo_mysql.default_socket=topdo_mysql.default_socket=/opt/mysql/server-5.6/mysql.sock
Copy PHP startup script to init.d
cp /opt/php/php-5.5.14/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
Set permissions for PHP script
chmod +x /etc/init.d/php-fpm
Start PHP service up
service php-fpm start
Set PHP service to boot
update-rc.d -f php-fpm defaults
PHP should now be installed and will broadcast on reboot to localhost:9000 by default
Note: If you're having a problem with port 9000 (because a lot of other programmers like to use it) you can use another port and then specify it in your NGINX server config.
Adding PHP extension ability
Install PHP Extension dependencies
apt-get install autoconf git
Adding binaries to bash
Add PHP binaries to your bash, edit your .bashrc file
pico ~/.bashrc
Add :/opt/php/bin to the end of your path line
PATH=$PATH:/opt/php/bin
Reset bash
source ~/.bashrc