Linux install PHP7+NGINX small white tutorial

The server is like another computer, and we can access it through its public IP or domain name, but what you download on your computer stays on your computer forever, it is impossible to find on the server! The system you just bought or installed on your virtual machine does not have a development environment and needs to be installed by yourself. You might want to install the integrated environment directly or yum install the integrated development environment directly, but as the environment changes it is better to install the latest version of the development environment. Here are some installation tutorials and FAQ

Installing PHP

Install dependence first, I feel more appropriate

yum install gcc gcc++ libxml2-devel cmake ncurses-devel perl-Data-Dumper boost boost-doc boost-devel libaio
Copy the code

Then we can go to the PHP official website (baidu, suggested to choose Hong Kong server) to download, here I use PHP7.0.22, should be close to the version can be used, sometimes the version difference will cause this tutorial is not available.

cd /usr/local/ wget - no - check - certificate http://hk1.php.net/get/php-7.0.22.tar.gz/from/this/mirror tar - ZXVF mirrorCopy the code

If you don’t have the file name that you downloaded, you can just change it and then install PHP, and just to avoid future trouble, we’ll just compile a lot of libraries directly into it

cdPHP - 7.0.22. / configure -- prefix = / usr /local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization  \ --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex \ --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo \ --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf \ --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig \ --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml \ --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir  --with-xsl --enable-zip --enable-mysqlnd-compression-support \ --with-pear --enable-opcache --enable-maintainer-zts --enable-tsrm-pthreads --disable-fileinfo make make installCopy the code

Make: *** [sapi/cli/PHP] Error 1

vim Makefile
Copy the code

Add -liconv to EXTRA_LIBS in 100 + lines and press ESC and colon to enter wq to save and exit

make
make install
Copy the code

Now that it’s installed, let’s do a test to see if it works, but just so we can configure its PATH,

Vim /etc/profile Write PATH= on the last line$PATH:/usr/local/php/bin/; Save and exitsource /etc/profile
php -v
php -m
Copy the code

Let’s write a PHP file to test the run

cd /usr/local/ vim test.php <? php phpinfo(); php test.php rm test.phpCopy the code

If the printing is successful, it is correct

Install NGINX

First we download and install a PCRE, or re

cd /usr/localWget - no - check - certificate tar ZXVF - ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz Pcre - 8.39. Tar. GzcdPcre - 8.39. / configure -- prefix = / usr /local/ pcre - 8.39 make make installCopy the code

/usr/local/pcre-8.39 is used when installing nginx. Then we install nginx. We go to the nginx website and click on a Stable version

cd /usr/localWget - no - check - certificate http://nginx.org/download/nginx-1.12.1.tar.gz tar - ZXVF nginx - 1.12.1. Tar. GzcdNginx - 1.12.1. / configure -- prefix = / usr /local/nginx --with-pcre=/usr/local/ pcre - 8.39 make make installCopy the code

Now that we have nginx installed, you need to shut down Apache before starting it

ps aux | grep httpd
kill-9 Process 1 Process 2 ··· vim /etc/profile PATH=$PATH:/usr/local/nginx/sbin/;

source /etc/profile
nginx
Copy the code

At this point we can go to the GUI to check, visit the nginx home page http://localhost/ can open (if there is no GUI server, Http://public IP (or domain name) can be accessed locally. If this page is displayed successfully, then we need to make Nginx and PHP work together

cd /usr/local/php7/etc/
ll
mv php-fpm.conf.default php-fpm.conf
cd php-fpm.d
ll
mv www.conf.default www.conf 
/usr/local/php7/sbin/php-fpm
ps aux | grep php-fpm
Copy the code

If it runs successfully, we add its PATH to PATH

vim /etc/profile

PATH=$PATH:/usr/local/php7/sbin/;

source /etc/profile
Copy the code

Finally, let’s configure nginx

cd /usr/local/nginx/conf
ll
vim nginx.conf
Copy the code

in

location / {
            root   html;
            index  index.html index.htm;
        }
Copy the code

The following add

Location ~ \.php {fastcgi_pass 127.0.0.1:9000; fastcgi_index /index.php; include /usr/local/nginx/conf/fastcgi_params;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
Copy the code

Finally, let’s test whether PHP and Nginx work together

nginx -s reload
cd ../
ll
cdhtml vim index.php <? php phpinfo();Copy the code

Then we visit http://localhost/index.php to print a phpinfo () interface PHP and nginx can work together, remember to open the nginx every time after restart the system, and PHP – FPM service

nginx
php-fpm
Copy the code

The attached

  1. In the directory- 7.0.22 / usr/local/PHP/ext /There are a number of extensions that can be used, usually directly after the CD goes in
phpize
./configure
make
make install
Copy the code

You can also find their own Baidu expansion so installed, but some expansion may also need other dependence, that Baidu.

  1. PHP./configureConfiguration can be done in the/ usr/local/PHP - 7.0.22 / MakefileFound in the