search
HomeOperation and MaintenanceNginxHow to install PHP and Nginx on Centos7

How to install PHP and Nginx on Centos7

May 14, 2023 pm 03:37 PM
phpnginxcentos7

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

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

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
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
Using NGINX Unit: Deploying and Managing ApplicationsUsing NGINX Unit: Deploying and Managing ApplicationsApr 22, 2025 am 12:06 AM

NGINXUnit can be used to deploy and manage applications in multiple languages. 1) Install NGINXUnit. 2) Configure it to run different types of applications such as Python and PHP. 3) Use its dynamic configuration function for application management. Through these steps, you can efficiently deploy and manage applications and improve project efficiency.

NGINX vs. Apache: A Comparative Analysis of Web ServersNGINX vs. Apache: A Comparative Analysis of Web ServersApr 21, 2025 am 12:08 AM

NGINX is more suitable for handling high concurrent connections, while Apache is more suitable for scenarios where complex configurations and module extensions are required. 1.NGINX is known for its high performance and low resource consumption, and is suitable for high concurrency. 2.Apache is known for its stability and rich module extensions, which are suitable for complex configuration needs.

NGINX Unit's Advantages: Flexibility and PerformanceNGINX Unit's Advantages: Flexibility and PerformanceApr 20, 2025 am 12:07 AM

NGINXUnit improves application flexibility and performance with its dynamic configuration and high-performance architecture. 1. Dynamic configuration allows the application configuration to be adjusted without restarting the server. 2. High performance is reflected in event-driven and non-blocking architectures and multi-process models, and can efficiently handle concurrent connections and utilize multi-core CPUs.

NGINX vs. Apache: Performance, Scalability, and EfficiencyNGINX vs. Apache: Performance, Scalability, and EfficiencyApr 19, 2025 am 12:05 AM

NGINX and Apache are both powerful web servers, each with unique advantages and disadvantages in terms of performance, scalability and efficiency. 1) NGINX performs well when handling static content and reverse proxying, suitable for high concurrency scenarios. 2) Apache performs better when processing dynamic content and is suitable for projects that require rich module support. The selection of a server should be decided based on project requirements and scenarios.

The Ultimate Showdown: NGINX vs. ApacheThe Ultimate Showdown: NGINX vs. ApacheApr 18, 2025 am 12:02 AM

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX in Action: Examples and Real-World ApplicationsNGINX in Action: Examples and Real-World ApplicationsApr 17, 2025 am 12:18 AM

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINX Unit: Supporting Different Programming LanguagesNGINX Unit: Supporting Different Programming LanguagesApr 16, 2025 am 12:15 AM

NGINXUnit supports multiple programming languages ​​and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.

Choosing Between NGINX and Apache: The Right Fit for Your NeedsChoosing Between NGINX and Apache: The Right Fit for Your NeedsApr 15, 2025 am 12:04 AM

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools