How to install LNMP (Nginx + PHP + MySQL) on CentOS 7)

Source: Internet
Author: User
Tags file info

How to install LNMP (Nginx + PHP + MySQL) on CentOS 7)

Nginx is a free, open-source, and efficient HTTP server. Nginx is known for its stability, rich functions, simple structure, and low resource consumption. This tutorial demonstrates how to install Nginx and PHP (via php-fpm) and MySQL (MariaDB) on the CentOS 6.5 server (for CentOS 7 ).

 

-------------------------------------- Split line --------------------------------------

Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL

Install the LAMP \ Vsftpd \ Webmin \ phpMyAdmin service and settings in Ubuntu 13.04

Build and install the LNMP production environment in CentOS 6.4

Practical Production Environment-LNMP architecture compilation and installation + SSL encryption implementation

LNMP full-featured compilation and installation for CentOS 6.3 notes

Install LNMP in CentOS 6.3 (PHP 5.4, MyySQL5.6)

Nginx startup failure occurs during LNMP deployment.

Ubuntu install Nginx php5-fpm MySQL (LNMP environment setup)

-------------------------------------- Split line --------------------------------------

1 first

The host name used in this article is server1.example.com and IP Address: 192.168.1.105. These may be different from your computer. Be sure to modify them.

2. Use an external warehouse

Nginx is not installed from the official CentOS library. We will install it from the nginx project installation library and modify the source:

Vi/etc/yum. repos. d/nginx. repo

Change to [nginx] name = nginx repo baseurl = http://nginx.org/packages/centos/?releasever/#basearch/ gpgcheck = 0 enabled = 1
3. Install MySQL

Install MariaDB first. A free MySQL branch. Run the following command:

Yum install mariadb-server net-tools

Then we create the MySQL system startup Link (so when MySQL is automatically started, the system starts) to start the MySQL server:

Systemctl enable mariadb. service
Systemctl start mariadb. service

Check whether the network is enabled. Run

Netstat-tap | grep mysql

It should display the following content:

[Root @ example ~] # Netstat-tap | grep mysql
Tcp 0 0 0.0.0.0: mysql 0.0.0.0: * LISTEN 10623/mysqld

 

Run

Mysql_secure_installation

Set the root password for the user (otherwise, anyone can access your MySQL database !) :

[Root @ example ~] # Mysql_secure_installation
/Usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: running all parts of this script is recommended for all MariaDB
Servers in production use! Please read each step carefully!

In order to log into MariaDB to secure it, we'll need the current
Password for the root user. If you 've just installed MariaDB, and
You haven't set the root password yet, the password will be blank,
So you shoshould just press enter here.

Enter current password for root (enter for none ):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
Root user without the proper authorisation.

Set root password? [Y/n] <-enter
New password: <-enter the ROOT password
Re-enter new password: <-enter the ROOT password again
Password updated successfully!
Reloading privilege tables ..
... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
To log into MariaDB without having to have a user account created
Them. This is intended only for testing, and to make the installation
Go a bit smoother. You shoshould remove them before moving into
Production environment.

Remove anonymous users? [Y/n] <-enter
... Success!

Normally, root shoshould only be allowed to connect from 'localhost'. This
Ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] <-enter
... Success!

By default, MariaDB comes with a database named 'test' that anyone can
Access. This is also intended only for testing, and shocould be removed
Before moving into a production environment.

Remove test database and access to it? [Y/n] <-enter
-Dropping test database...
... Success!
-Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
Will take effect immediately.

Reload privilege tables now? [Y/n] <-enter
... Success!

Cleaning up...

All done! If you 've completed all of the above steps, your MariaDB
Installation shoshould now be secure.

Thanks for using MariaDB!
[Root @ example ~] #

[Root @ server1 ~] # Mysql_secure_installation

4. Install Nginx

Nginx can be installed from nginx.org as a package and run:

Yum install nginx

Then the system we created starts the nginx link and starts it:

Systemctl enable nginx. service
Systemctl start nginx. service

Sometimes, you will get an error, such as port 80 is in use, and the error message will be like this

[Root @ server1 ~] # Service nginx start
Starting nginx: [emerg] bind () to 0.0.0.0: 80 failed (98: Address already in use)
Nginx: [emerg] bind () to 0.0.0.0: 80 failed (98: Address already in use)
Nginx: [emerg] bind () to 0.0.0.0: 80 failed (98: Address already in use)
Nginx: [emerg] bind () to 0.0.0.0: 80 failed (98: Address already in use)
Nginx: [emerg] bind () to 0.0.0.0: 80 failed (98: Address already in use)
Nginx: [emerg] still cocould not bind ()
[FAILED]
[Root @ server1 ~] #

This means that the Apache service is sometimes running. Stop the service and start the service nginx as follows:

Systemctl stop httpd. service
Yum remove httpd
Systemctl disable httpd. service

Systemctl enable nginx. service
Systemctl start nginx. service

Ports in the open HTTP and HTTPS firewalls

Firewall-cmd-permanent-zone = public-add-service = http
Firewall-cmd-permanent-zone = public-add-service = https
Firewall-cmd-reload

The output shell result will look like this:

[Root @ example ~] # Firewall-cmd-permanent-zone = public-add-service = http
Success
[Root @ example ~] # Firewall-cmd-permanent-zone = public-add-service = https
Success
[Root @ example ~] # Firewall-cmd-reload
Success
[Root @ example ~] #

Enter the IP address or host name of your Web server in the browser (such as HTTP: // 192.168.1.105). You should see the nginx welcome page.

5. Install PHP5

We can make nginx PHP5 work via PHP-FPM (FastCGI Process Manager) is an alternative to PHP FastCGI to execute some additional features that support any size, especially for busy sites ). We can install php-fpmtogether with PHP-CLI and some PHP5 modules, such as PHP, MySQL, you need, if you want to use MySQL PHP Command as follows:

Yum install php-fpm php-cli php-mysql php-gd php-ldap php-odbc php-pdo php-pecl-memcache php-pear php-mbstring php-xml php-xmlrpc php-mbstring php-snmp php-soap

APC is a free and open PHP operation code to cache and optimize PHP intermediate code. It is similar to other PHP operation codes cachers, such as eAccelerator and XCache. We strongly recommend that you have these installations to speed up your PHP page.

I will install APC from the PHP PECL library. PECL requires the CentOS development tool beinstalled to compile the APC package.

Yum install php-devel
Yum groupinstall 'development tool'

Install APC

Pecl install apc

[Root @ example ~] # Pecl install apc
Downloading APC-3.1.13.tgz...
Starting to download APC-3.1.13.tgz (171,591 bytes)
................. Done: 171,591 bytes
55 source files, building
Running: phpize
Processing ing:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
Enable internal debugging in APC [no]: <-press ENTER
Enable per request file info about files used from the APC cache [no]: <-press ENTER
Enable spin locks (EXPERIMENTAL) [no]: <-press ENTER
Enable memory protection (EXPERIMENTAL) [no]: <-press ENTER
Enable pthread mutexes (default) [no]: <-press ENTER
Enable pthread read/write locks (EXPERIMENTAL) [yes]: <-press ENTER
Building in/var/tmp/pear-build-rootVrjsuq/APC-3.1.13
......

Then open/etc/php. ini and set cgi. fix_pathinfo = 0:

Vi/etc/php. ini

[...]; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.; http://www.php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfocgi.fix_pathinfo=0[...]

And Add rows:

[...]extension=apc.so

In the/etc/php. ini file.

In addition, to avoid time zone errors:

[21-July-2014 10:07:08] PHP Warning: phpinfo (): It is not safe to rely on the system's timezone settings. you are * required * to use the date. timezone setting or the date_default_timezone_set () function. in case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. we selected 'Europe/berline' for 'cest/2.0/DST 'instead in/usr/share/nginx/html/info. php on line 2

... In/var/log/php-fpm/www-error.log when you call a PHP script in your browser, you should set date. timezone in/etc/php. ini:

[...][Date]; Defines the default timezone used by the date functions; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezonedate.timezone = "Europe/Berlin"[...]

You can run the correct time zone to support your system:

Cat/etc/sysconfig/clock

[Root @ server1 nginx] # cat/etc/sysconfig/clock
ZONE = "Europe/Berlin"
[Root @ server1 nginx] #

Next, create a PHP-FPM for the system boot link and start it:

Systemctl enable php-fpm.service
Systemctl start php-fpm.service

The PHP-FPM is a daemon (using the init script/etc/init. d/php-fpm) that runs on the FastCGI server on port 9000.

For more details, please continue to read the highlights on the next page:

 

  • 1
  • 2
  • Next Page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.