Installing Nginx With PHP5 (And PHP-FPM) And MySQL Support On Ubuntu 11.10 - Page 2
This tutorial exists for these OS versions
- Ubuntu 24.04 (Noble Numbat)
- Ubuntu 22.04 (Jammy Jellyfish)
- Ubuntu 20.04 (Focal Fossa)
- Ubuntu 20.04 (Focal Fossa)
- Ubuntu 18.04 (Bionic Beaver)
- Ubuntu 16.04 (Xenial Xerus)
On this page
6 Getting MySQL Support In PHP5
To get MySQL support in PHP, we can install the php5-mysql package. It's a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:
apt-cache search php5
Pick the ones you need and install them like this:
apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
Now restart PHP-FPM:
/etc/init.d/php5-fpm restart
Now reload http://192.168.0.100/info.php in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module:
7 Making PHP-FPM Use A Unix Socket
By default PHP-FPM is listening on port 9000 on 127.0.0.1. It is also possible to make PHP-FPM use a Unix socket which avoids the TCP overhead. To do this, open /etc/php5/fpm/pool.d/www.conf...
vi /etc/php5/fpm/pool.d/www.conf
... and make the listen line look as follows:
[...] ;listen = 127.0.0.1:9000 listen = /tmp/php5-fpm.sock [...] |
Then restart PHP-FPM:
/etc/init.d/php5-fpm restart
Next go through your nginx configuration and all your vhosts and change the line fastcgi_pass 127.0.0.1:9000; to fastcgi_pass unix:/tmp/php5-fpm.sock;, e.g. like this:
vi /etc/nginx/sites-available/default
[...] location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/tmp/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } [...] |
Finally reload nginx:
/etc/init.d/nginx reload
8 CGI/Perl Scripts
If you want to serve CGI/Perl scripts with nginx, please read this tutorial: Serving CGI Scripts With Nginx On Debian Squeeze/Ubuntu 11.04
The recommended way is to use fcgiwrap (chapter 4).
9 Links
- nginx: http://nginx.net/
- nginx Wiki: http://wiki.codemongers.com/Main
- PHP: http://www.php.net/
- PHP-FPM: http://php-fpm.org/
- MySQL: http://www.mysql.com/
- Ubuntu: http://www.ubuntu.com/
About The Author
Falko Timme is the owner of Timme Hosting (ultra-fast nginx web hosting). He is the lead maintainer of HowtoForge (since 2005) and one of the core developers of ISPConfig (since 2000). He has also contributed to the O'Reilly book "Linux System Administration".