May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

CENTOS 7 LNMP (Nginx -PHP -MySQL)

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

systemctl start nginx.service

systemctl stop httpd.service
yum remove httpd
systemctl disable httpd.service
root@centos71 ~]# systemctl start nginx.service
[root@centos71 ~]# systemctl restart nginx.service
[root@centos71 ~]# systemctl status nginx.service
nginx.service – nginx – high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled)
Active: active (running) since Thu 2014-09-11 14:32:02 SGT; 8s ago
Docs: http://nginx.org/en/docs/
Process: 38314 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
Process: 38319 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Process: 38318 ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 38322 (nginx)
CGroup: /system.slice/nginx.service
??38322 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
??38323 nginx: worker process

Sep 11 14:32:02 centos71.rmohan.com systemd[1]: Starting nginx – high performance web server…
Sep 11 14:32:02 centos71.rmohan.com nginx[38318]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Sep 11 14:32:02 centos71.rmohan.com nginx[38318]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Sep 11 14:32:02 centos71.rmohan.com systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument
Sep 11 14:32:02 centos71.rmohan.com systemd[1]: Started nginx – high performance web server.

Enable Firewall Rule

[root@centos71 ~]# firewall-cmd –permanent –zone=public –add-service=http
success

[root@centos71 ~]# firewall-cmd –permanent –zone=public –add-service=https
success

[root@centos71 ~]# firewall-cmd –reload
success
http://192.168.1.9/
Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.
[root@centos71 ~]# ip addr show eno16777736 | grep inet | awk ‘{ print $2; }’ | sed ‘s/\/.*$//’
192.168.1.9
fe80::20c:29ff:fe7c:a85a

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

Set root password? [Y/n]
New password:
Re-enter new password:
Sorry, passwords do not match.

New password:
Re-enter new password:
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 for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
… Success!

Normally, root should 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] Y
… Success!

By default, MariaDB comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
– 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] Y
… Success!

Cleaning up…

All done! If you’ve completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

[root@centos71 ~]# systemctl enable mariadb.service
ln -s ‘/usr/lib/systemd/system/mariadb.service’ ‘/etc/systemd/system/multi-user.target.wants/mariadb.service’
[root@centos71 ~]# systemctl restart mariadb.service
[root@centos71 ~]# systemctl status mariadb.service
mariadb.service – MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled)
Active: active (running) since Thu 2014-09-11 14:57:59 SGT; 6s ago
Process: 39423 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 39395 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 39422 (mysqld_safe)
CGroup: /system.slice/mariadb.service
??39422 /bin/sh /usr/bin/mysqld_safe –basedir=/usr
??39580 /usr/libexec/mysqld –basedir=/usr –datadir=/var/lib/mysql –plugin-dir=/usr/lib64/mysql/plugin –log-error=/var/log/mariadb/mariadb.log –pid-file=/var/…

Sep 11 14:57:57 centos71.rmohan.com mysqld_safe[39422]: 140911 14:57:57 mysqld_safe Logging to ‘/var/log/mariadb/mariadb.log’.
Sep 11 14:57:57 centos71.rmohan.com mysqld_safe[39422]: 140911 14:57:57 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Sep 11 14:57:59 centos71.rmohan.com systemd[1]: Started MariaDB database server.
[root@centos71 ~]#
[root@centos71 ~]# yum install php php-mysql php-fpm
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: buaya.klas.or.id
* extras: repo.apiknet.co.id
* updates: kartolo.sby.datautama.net.id
Resolving Dependencies
–> Running transaction check
—> Package php.x86_64 0:5.4.16-23.el7_0 will be installed
–> Processing Dependency: php-common(x86-64) = 5.4.16-23.el7_0 for package: php-5.4.16-23.el7_0.x86_64
–> Processing Dependency: php-cli(x86-64) = 5.4.16-23.el7_0 for package: php-5.4.16-23.el7_0.x86_64
–> Processing Dependency: httpd-mmn = 20120211×8664 for package: php-5.4.16-23.el7_0.x86_64
–> Processing Dependency: httpd for package: php-5.4.16-23.el7_0.x86_64
—> Package php-fpm.x86_64 0:5.4.16-23.el7_0 will be installed
—> Package php-mysql.x86_64 0:5.4.16-23.el7_0 will be installed
–> Processing Dependency: php-pdo(x86-64) = 5.4.16-23.el7_0 for package: php-mysql-5.4.16-23.el7_0.x86_64
–> Running transaction check
—> Package httpd.x86_64 0:2.4.6-18.el7.centos will be installed
–> Processing Dependency: httpd-tools = 2.4.6-18.el7.centos for package: httpd-2.4.6-18.el7.centos.x86_64
–> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-18.el7.centos.x86_64
–> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-18.el7.centos.x86_64
–> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-18.el7.centos.x86_64
—> Package php-cli.x86_64 0:5.4.16-23.el7_0 will be installed
—> Package php-common.x86_64 0:5.4.16-23.el7_0 will be installed
–> Processing Dependency: libzip.so.2()(64bit) for package: php-common-5.4.16-23.el7_0.x86_64
—> Package php-pdo.x86_64 0:5.4.16-23.el7_0 will be installed
–> Running transaction check
—> Package apr.x86_64 0:1.4.8-3.el7 will be installed
—> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
—> Package httpd-tools.x86_64 0:2.4.6-18.el7.centos will be installed
—> Package libzip.x86_64 0:0.10.1-8.el7 will be installed
—> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================================================================================
Package Arch Version Repository Size
================================================================================================================================================================================
Installing:
php x86_64 5.4.16-23.el7_0 updates 1.3 M
php-fpm x86_64 5.4.16-23.el7_0 updates 1.4 M
php-mysql x86_64 5.4.16-23.el7_0 updates 96 k
Installing for dependencies:
apr x86_64 1.4.8-3.el7 base 103 k
apr-util x86_64 1.5.2-6.el7 base 92 k
httpd x86_64 2.4.6-18.el7.centos updates 2.7 M
httpd-tools x86_64 2.4.6-18.el7.centos updates 77 k
libzip x86_64 0.10.1-8.el7 base 48 k
mailcap noarch 2.1.41-2.el7 base 31 k
php-cli x86_64 5.4.16-23.el7_0 updates 2.7 M
php-common x86_64 5.4.16-23.el7_0 updates 560 k
php-pdo x86_64 5.4.16-23.el7_0 updates 94 k

Transaction Summary
================================================================================================================================================================================
Install 3 Packages (+9 Dependent packages)

Total download size: 9.3 M
Installed size: 32 M
Is this ok [y/d/N]: y
Downloading packages:
(1/12): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:00
(2/12): httpd-tools-2.4.6-18.el7.centos.x86_64.rpm | 77 kB 00:00:00
(3/12): libzip-0.10.1-8.el7.x86_64.rpm | 48 kB 00:00:00
(4/12): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00
(5/12): apr-1.4.8-3.el7.x86_64.rpm | 103 kB 00:00:01
(6/12): php-5.4.16-23.el7_0.x86_64.rpm | 1.3 MB 00:00:01
(7/12): php-common-5.4.16-23.el7_0.x86_64.rpm | 560 kB 00:00:02
(8/12): php-mysql-5.4.16-23.el7_0.x86_64.rpm | 96 kB 00:00:05
(9/12): php-pdo-5.4.16-23.el7_0.x86_64.rpm | 94 kB 00:00:04
(10/12): php-fpm-5.4.16-23.el7_0.x86_64.rpm | 1.4 MB 00:00:15
(11/12): php-cli-5.4.16-23.el7_0.x86_64.rpm | 2.7 MB 00:00:18
(12/12): httpd-2.4.6-18.el7.centos.x86_64.rpm | 2.7 MB 00:00:24
——————————————————————————————————————————————————————————–
Total 392 kB/s | 9.3 MB 00:00:24
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7.x86_64 1/12
Installing : apr-util-1.5.2-6.el7.x86_64 2/12
Installing : httpd-tools-2.4.6-18.el7.centos.x86_64 3/12
Installing : libzip-0.10.1-8.el7.x86_64 4/12
Installing : php-common-5.4.16-23.el7_0.x86_64 5/12
Installing : php-cli-5.4.16-23.el7_0.x86_64 6/12
Installing : php-pdo-5.4.16-23.el7_0.x86_64 7/12
Installing : mailcap-2.1.41-2.el7.noarch 8/12
Installing : httpd-2.4.6-18.el7.centos.x86_64 9/12
Installing : php-5.4.16-23.el7_0.x86_64 10/12
Installing : php-mysql-5.4.16-23.el7_0.x86_64 11/12
Installing : php-fpm-5.4.16-23.el7_0.x86_64 12/12
Verifying : php-common-5.4.16-23.el7_0.x86_64 1/12
Verifying : php-mysql-5.4.16-23.el7_0.x86_64 2/12
Verifying : apr-1.4.8-3.el7.x86_64 3/12
Verifying : mailcap-2.1.41-2.el7.noarch 4/12
Verifying : php-cli-5.4.16-23.el7_0.x86_64 5/12
Verifying : apr-util-1.5.2-6.el7.x86_64 6/12
Verifying : php-5.4.16-23.el7_0.x86_64 7/12
Verifying : libzip-0.10.1-8.el7.x86_64 8/12
Verifying : php-pdo-5.4.16-23.el7_0.x86_64 9/12
Verifying : httpd-tools-2.4.6-18.el7.centos.x86_64 10/12
Verifying : php-fpm-5.4.16-23.el7_0.x86_64 11/12
Verifying : httpd-2.4.6-18.el7.centos.x86_64 12/12

Installed:
php.x86_64 0:5.4.16-23.el7_0 php-fpm.x86_64 0:5.4.16-23.el7_0 php-mysql.x86_64 0:5.4.16-23.el7_0

Dependency Installed:
apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7 httpd.x86_64 0:2.4.6-18.el7.centos httpd-tools.x86_64 0:2.4.6-18.el7.centos libzip.x86_64 0:0.10.1-8.el7
mailcap.noarch 0:2.1.41-2.el7 php-cli.x86_64 0:5.4.16-23.el7_0 php-common.x86_64 0:5.4.16-23.el7_0 php-pdo.x86_64 0:5.4.16-23.el7_0

Complete!

vim /etc/php.ini
by uncommenting the line and setting it to “0” like this:

cgi.fix_pathinfo=0

vi /etc/php-fpm.d/www.conf
Find the line that specifies the listen parameter, and change it so it looks like the following:

listen = /var/run/php-fpm/php-fpm.sock
systemctl start php-fpm
systemctl restart php-fpm
systemctl status php-fpm
systemctl enable php-fpm.service
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.org
server {
listen 80;
server_name 192.168.1.9;

root /usr/share/nginx/html;
index index.php index.html index.htm;

location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
We will call this script info.php. In order for Apache to find the file and serve it correctly, it must be saved to a very specific directory, which is called the “web root”.

In CentOS 7, this directory is located at /usr/share/nginx/html/.
We can create the file at that location by typing:
sudo vi /usr/share/nginx/html/info.php

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>