How to install PHP and Nginx on 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:
php version list
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:
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!

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

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

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

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

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.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.
