How to install and configure nginx and PHP under CentOS7
Installation and configuration of nginx and PHP under CentOS7
Download Nginx
1. Create a new folder on the server /home/soft/ ;
2.cd /home/soft/ => Execute the command to download Nginx wget http://nginx.org/download/nginx-1.7.4.tar.gz ;
3. Unzip the downloaded compressed package to /opt/software/ => tar -zvxf nginx-1.7.4.tar.gz -C /opt/software/ ;
4.cd /opt/software/nginx-1.7.4/ => ./configure --prefix=/usr/local/nginx/ ;
5.make && make install ;
6. Start nginx => /usr/local/nginx/sbin/nginx
7. Open the browser to access the IP of this machine. If the browser displays Welcome to nginx!, it means that Nginx has been installed and run successfully.
8. Restart:/usr/local/nginx/sbin/nginx –s reload
Stop:/usr/local/nginx/sbin/nginx –s stop
Test whether the configuration file is normal:/usr/local/nginx/sbin/nginx –t
Force shutdown: pkill nginx
Download php
1. cd /home/soft/ Download php: wget https://www.php.net/distributions/php-7.2.25.tar.gz;
2. Unzip php-7.2.25.tar.gz => tar -zvxf php-7.2.25.tar.gz -C /opt/software/ ;
3. cd /opt/software/php-7.2.25/;
4. First install the dependencies required for php:
Yum update
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel MySQL pcre-devel
yum -y install curl-devel
yum -y install libxslt-devel
yum install openssl openssl-devel
5. ./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos - -with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear - -with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native -ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable -zip
6. make && make install
7. PHP configuration information:
cp /opt/software/php-7.2.25/php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp -R /opt/software/php-7.2.25/sapi/fpm/php-fpm /etc/init.d/php-fpm
* It should be noted that the www.conf configuration file in php7 configures the port number and other information of phpfpm. If you modify the default 9000 port number, you need to change it here, and then change the nginx configuration
Ngin parses php:
1. Change the nginx configuration file => vim /usr/local/nginx/etc/nginx/nginx.conf
Location ~ \.php$ {
root /usr/share/nginx/html; #Specify the root directory of php
fastcgi_pass 127.0.0.1:9000; #The default port of php-fpm is 9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #Path
include fastcgi_params;
}
2.php configuration to start automatically at boot:
vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=php
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
ExecStop=/bin/pkill -9 php-fpm
PrivateTmp=true
[Install]
WantedBy=multi-user.target
3. killall /etc/init.d/php-fpm
4. Start php
systemctl restart php-fpm.service
systemctl enable php-fpm.service
The above is the detailed content of How to install and configure nginx and PHP under CentOS7. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Steps to start Nginx in Linux: Check whether Nginx is installed. Use systemctl start nginx to start the Nginx service. Use systemctl enable nginx to enable automatic startup of Nginx at system startup. Use systemctl status nginx to verify that the startup is successful. Visit http://localhost in a web browser to view the default welcome page.

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

The server does not have permission to access the requested resource, resulting in a nginx 403 error. Solutions include: Check file permissions. Check the .htaccess configuration. Check nginx configuration. Configure SELinux permissions. Check the firewall rules. Troubleshoot other causes such as browser problems, server failures, or other possible errors.

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

In Linux, use the following command to check whether Nginx is started: systemctl status nginx judges based on the command output: If "Active: active (running)" is displayed, Nginx is started. If "Active: inactive (dead)" is displayed, Nginx is stopped.

There are two ways to solve the Nginx cross-domain problem: modify the cross-domain response header: add directives to allow cross-domain requests, specify allowed methods and headers, and set cache time. Use CORS modules: Enable modules and configure CORS rules that allow cross-domain requests, methods, headers, and cache times.

How to fix Nginx 403 Forbidden error? Check file or directory permissions; 2. Check .htaccess file; 3. Check Nginx configuration file; 4. Restart Nginx. Other possible causes include firewall rules, SELinux settings, or application issues.
