Home Operation and Maintenance Nginx How to install PHP and Nginx on Centos7

How to install PHP and Nginx on Centos7

May 14, 2023 pm 03:37 PM
php nginx centos7

1. Install PHP

As WeChat became popular in 2013, the use of PHP has become popular again. Many companies on the market choose to use PHP as their application backend. Personally I think the reasons are

1. The cost of PHP is low

2. It’s quick to get started with PHP

3. The development cycle of PHP is relatively short

4. The birth of tp5 has improved the efficiency of PHP interface development. Because there are so many demands, many companies' server configurations need to be able to support the PHP environment to complete project construction. In fact, there are generally two types of centos installation software. The first is quick installation and the second is compilation and installation. I personally recommend compilation and installation. As for the quick installation method, it is simple and fast. Just load it into the corresponding php source and complete it through yum install. For the step-by-step installation process, I will only talk about how to compile and install and the process of compiling and installing.

The first step is to check whether the system has php by default before installation. You can check it by searching for php files or processes. If it is installed and it is not the version we need, you can uninstall the relevant files through the following command. :

yum remove php*

The second step is to install related php dependencies

yum install -y gcc gcc-c libxml2- devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel freetype freetype-devel

The third step is to go to the PHP official website to view the tar.gz link to be downloaded, as shown below Shown:

How to install PHP and Nginx on Centos7

php version list

How to install PHP and Nginx on Centos7

Select the file source of the country you want to download on this page

After selecting the file source, copy the file download link, and download, compile and install it through the wget command in the system. Personally, I am accustomed to operating in the /usr/local directory. The specific steps are as follows:

Enter the operating directory: cd /usr/local

Download the file: wget

Extract the file: tar -zxvf php-7.2.10.tar.gz

Enter the decompressed file directory: cd php -7.2.10.tar.gz

Then compile with the following command:

./configure --prefix=/usr/local/php --with-config-file- path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv --with-zlib -- with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc - -enable-zip --enable-soap --enable-opcache --with-pdo-mysql --enable-maintainer-zts -with-mcrypt=/usr/include --with-mysql=shared,mysqlnd --with- mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --enable-ftp --enable-session --with-gettext --with-jpeg-dir --with-freetype-dir --enable-fastcgi --without-gdbm --disable-fileinfo

Then complete the final compilation and installation through the following command:

make && make install

If the installation process prompts that there are errors or dependencies, it needs to be solved according to the specific situation. At this point, we can use the php -v command to check whether the installation is successful.

Note: If the version you are viewing is inconsistent with the version you installed, you can find the location of the prompted version file and delete it, or you can leave it alone. After that, we point to the file directory we installed by modifying the environment variable. The operation method is as follows:

First edit the environment variable file: vim /etc/profile

Add export path= at the end of the file "/usr/local/php/bin:$path"

where "/usr/local/php/bin" is the specific path of your installation. After saving and exiting, just make the following changes and execute the command:

source /etc/profile

At this time, we use php -v again to view the current version and we can see the version number we installed.

2. Install nginx

nginx is the most mainstream server software besides apache, so installing ngix is ​​also a basic configuration. The compilation and installation methods are similar. :

The first step is to check and install the relevant dependency packages

yum -y install gcc gcc-c++ autoconf automake make

yum -y install zlib zlib-devel openssl 

yum -yinstallopenssl-devel pcre pcre-devel
Copy after login

The second step is to go to the nginx official website and find the link to the version you want to install. The official website address is: as shown in the figure below:

How to install PHP and Nginx on Centos7

nginx version list

Copy the corresponding version link, enter the above operation directory, /usr/local to operate

Enter the directory: cd /usr/local

Download the file: wget

Decompress the file: tar -zxvf nginx-1.8.0.tar.gz

Enter after decompression File directory: cd nginx-1.8.0

Then compile and install through the command:

. /configure 
make && make install
Copy after login

After the installation is completed, there will be an additional nginx folder under the /usr/local folder, which contains conf, html, logs, and sbin files. We only need to run ./sbin/nginx to start the nginx service.

After startup, verify whether the service is really started. Visit the server address with a browser to check whether it is started successfully. I personally like to verify it through the curl method, because if some server providers prohibit 80 or site port, through the browser of the external network It cannot be accessed. Of course, you can also check whether the corresponding service has been started through grep or nstat.

The above is the detailed content of How to install PHP and Nginx on Centos7. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

WordPress site file access is restricted: Why is my .txt file not accessible through domain name? WordPress site file access is restricted: Why is my .txt file not accessible through domain name? Apr 01, 2025 pm 03:00 PM

Wordpress site file access is restricted: troubleshooting the reason why .txt file cannot be accessed recently. Some users encountered a problem when configuring the mini program business domain name: �...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Top 10 PHP CMS Platforms For Developers in 2024 Top 10 PHP CMS Platforms For Developers in 2024 Dec 05, 2024 am 10:29 AM

CMS stands for Content Management System. It is a software application or platform that enables users to create, manage, and modify digital content without requiring advanced technical knowledge. CMS allows users to easily create and organize content

See all articles