How to setup Nginx, My SQL, PHP enabled on Centos 6.7
How to setup Nginx, My SQL, PHP enabled on Centos 6.7
1. Update the yum
repository as the Nginx is not directly available from Centos
# yum install
epel -release
2. Install MySQL
with dependencies
# yum install
mysql-server
3. Once the MySQL
installation is completed start the MySQL services.
# service mysqld start
# sudo
/etc/init . d/mysqld restart
4. We can secure MySQL by running this command, we can
alse setup root password for the MySQL
#
/usr/bin/mysql_secure_installation
Enter current password
for root (enter for none):
OK, successfully used
password, moving on...
Since we have installed the MySQL just now we dont have
the password for root, Just press Enter key
By default, a MySQL
installation has an anonymous user, allowing anyone
Remove anonymous
users? [Y/n] y
... Success!
Normally, root should
only be allowed to connect from 'localhost '.
This
Disallow root login
remotely? [Y/n] y
... Success!
By default, MySQL
comes with a database named 'test' that anyone can
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
Reload privilege
tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps,
your MySQL
Installation should
now be secure.
Thanks for using
MySQL!
5. Make the MySQL start by it self on time of booting
# chkconfig mysqld on
6. Install the Nginx and dependencies using this command
# yum install nginx
7. Once the nginx is installed it wont start itself start
the Nginx server
# service nginx start
8. Making Nginx start by it self at the time of boot
# chkconfig nginx on
9. We can check the working status of nginx by pointing
the browser to our own server IP
# ifconfig eth0 | grep
inet | awk '{ print $2 } '
Open any browser and check https://your-ip-address
10. Installing PHP, the php -fpm package is localted in
REMi repositoty .
# yum install php -fpm
php -mysql
11. Configure the PHP
# vi /etc/php /ini
If this number is kept as a 1, the php interpreter will
do its best to process the file that is as near to the requested file as
possible. This is a possible security risk. If this number is set to 0,
conversely, the interpreter will only process the exact file path—a much safer
alternative. Save and Exit.
12. configure the nginx
# vi
/etc/nginx/ngin . conf
Raise the number fo worker process to 4 the save, exit
the file.
# vi
/etc/nginx/conf. d/default. conf
The sample config files looks like this
#
# The default server
#
server_name example.com;
}
error_page
404 /404.html;
}
error_page
500 502 503 504 /50x.html;
}
# pass the PHP scripts to FastCGI server
listening on 127.0.0.1:9000
#
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
These are the
details of the changes:
Add index.php within the index line.
Change the server_name to your domain name or IP address
(replace the example.com in the configuration)
Change the root to /usr/share/nginx/html;
Change the root to access the actual document root,
/usr/share/nginx/html;
Change the fastcgi_param line to help the PHP interpreter
find the PHP script that we stored in the document root home.
Save and Exit
13. Open the /etc/php -fpm. d/www/conf
# sudo vi
/etc/php-fpm.d/www.conf
Replace the apache
in the user and group with nginx
[...]
; Unix user/group of
processes
; Note: The user is
mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache Choosed
to be able to access some dir as httpd
; RPM: Keep a group
allowed to write in log dir .
[...]
14. Finish by restarting php -fpm .
# sudo service php -fpm
restart
# chkconfig php -fpm on
Checking the Nginx and PHP configuration
15. To check the configuration create file
/usr/share/nginx/html/info.php
# sudo vi
/usr/share/nginx/html/info.php
Add in the following lines in the info.php file:
<? php
?>
Then Save and Exit.
Restart nginx so that all of the changes take effect:
# sudo service nginx
restart
Keywords, LAMP, Nginx, SQL, PHP, PHP-mysql, Webserver, Nginx Webserver
Comments
Post a Comment