Many tutorials on installing Nginx + PHP in Linux operating systems on the Internet are very old, and various dependencies are confusing for beginners. Therefore, I wrote this blog again, this document describes how to install Nginx + PHP in Linux. this article will be updated frequently to keep pace with the times. if you do not see
Many tutorials on installing Nginx + PHP in Linux operating systems on the Internet are very old, and various dependencies are confusing for beginners. Therefore, I wrote this blog again, this document describes how to install Nginx + PHP in Linux. this article will be updated frequently to keep pace with the times. if you do not see
Many tutorials on installing Nginx + PHP in Linux operating systems on the Internet are very old, and various dependencies are confusing for beginners. Therefore, I wrote this blog again, this document describes how to install Nginx + PHP in Linux.
This article will be updated frequently to keep pace with the times. If you do not see this article on the ideawu.net website, please visit ideawu.net to read the latest version.
Install Ubuntu Server
You may have heard of other Linux releases, but if you are a beginner and do not know about Nginx + PHP installation, I suggest you install Ubuntu Server. please go to Ubuntu official website to download the latest ISO file, I used 12.04.3-server-amd64.iso.
Install dependent Software
To install the software in Ubuntu, run the sudo aptitude command. this is a software similar to the graphic interface. After the software is started, press "/" and enter the software name for search. Then, press "+" and then press "g" to install the software.
The dependent packages to be installed are: libpcre3-dev, libxml2-dev, zlib1g-dev.
Install Nginx with source code to compile Nginx
Download the latest Nginx source code from the official Nginx website. The latest version () is 1.5.6 and will be upgraded in the future. Therefore, the downloaded wget is just an example. You should replace it with the latest version.
wget http://nginx.org/download/nginx-1.5.6.tar.gztar xzf nginx-1.5.6.tar.gzcd nginx-1.5.6./configuremakesudo make install
Nginx will be installed in the/usr/local/nginx directory.
Start Nginx
sudo /usr/local/nginx/sbin/nginx
Stop Nginx
sudo /usr/local/nginx/sbin/nginx -s stop
Verify that Nginx has been started
Open the browser and access http: // 127.0.0.1/To see if the webpage can be opened. If you access it on another machine, change 127.0.0.1 to the IP address of the Ubuntu server, as shown in.
More changes to the Nginx configuration file will be taken into consideration after PHP is installed. Use the default configuration file to run it first. the default configuration file is in/usr/local/nginx/conf/nginx. conf file.
Install PHP fpm fastcgi in source code to compile PHP
Similarly, go to the PHP official website to download the latest PHP source code.
wget http://us1.php.net/get/php-5.5.5.tar.bz2/from/cn2.php.net/mirrortar xjf mirrorcd php-5.5.5./configure --enable-fpmmakesudo make install
PHP executable files (php, php-cgi) will be installed in the/usr/local/bin directory. the configuration file is/usr/local/lib/php. ini, this file is not stored, you need to create it yourself.
Verify that PHP has been installed successfully
php -v
The above command should have version information output.
Create a php. ini configuration file
sudo cp php.ini-production /usr/local/lib/php.ini
However, you still cannot use the file. You can modify the file later.
Modify the Nginx configuration file to support PHP
Compile the Nginx configuration file/usr/local/nginx/conf/nginx. conf, add the following content. the original configuration file contains similar content, which you can add to keep up.
location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;}
Restart Nginx
sudo /usr/local/nginx/sbin/nginx -s reload
At this time, Nginx + PHP is not working yet. You also need to start the php-cgi process.
Start php-cgi
/usr/local/bin/php-cgi -b 9000
Verify that Nginx + PHP is working properly
First, you need to create a PHP script to create a new file/usr/local/nginx/html/index. php with only one line of content:
Then modify its file attributes.
sudo chmod ugo+rwx -R /usr/local/nginx/html
Then, access http: // 127.0.0.1/index. php in a browser and you should be able to see the PHP information, as shown in
Start the php-cgi process in fpm ModeAlthough a line of commands just started php-cgi, Nginx + PHP also works normally, this is not a formal environment approach, but a temporary method. in a formal production environment, you generally use fpm to start php-cgi as the daemon.
The php-fpm program is installed in/usr/local/sbin/php-fpm.
Create php-fpm.confPHP installed a php-fpm.conf.default template file by default and needs to be renamed:
sudo cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
Then modify the/usr/local/etc/php-fpm.conf
;pid = run/php-fpm.pid
Remove the semicolon (comment.
Create a nobody usersudo groupadd nobodysudo useradd -g nobody nobody
Start and Stop php-fpm# Start sudo/usr/local/sbin/php-fpm # Stop sudo kill 'cat/usr/local/var/run/php-fpm.pid'
At this time, php-cgi has been started as a daemon.
Compile and install the PHP module separatelyThe PHP compiled above may not contain some modules you need, but don't worry, you don't have to re-compile the entire PHP, but just compile and install the missing module. this is also the benefit of PHP modularization. the following uses the sockets module for separately installing PHP as an example.
Enter the ext/sockets directory of your PHP source code. The ext directory is the total directory of all modules. Then execute
/usr/local/bin/phpize./configuremakesudo cp modules/sockets.so /usr/local/lib/php/extensions/no-debug-non-zts-20121212/
Modify the php. ini configuration file and find
;;;;;;;;;;;;;;;;;;;;;;; Dynamic Extensions ;;;;;;;;;;;;;;;;;;;;;;;
Add
extension=sockets.so
Then restart php-fpm. In this way, the sockets module has been installed successfully.
Related posts:
- Nginx + PHP configuration and startup script
- Nginx 499 error code and AJAX call failure
- Linux + Keepalived dual-host mutual backup
- Nginx-push-stream-module notes
- Install and configure HBase in Linux
The article you are reading is: how to install Nginx PHP fpm in Linux for beginners
Linode VPS-web hosting in the united states | IT cattle blog website Aggregation