LEMP On Fedora 17 with setting up virtual host

Courtesy: http://cdn.farinspace.net/assets/lemp.jpg

Linux, Nginx, MySQL, PHP knows as “LEMP” server. Here, Nginx  is very fast and lightweight web server which is designed to handle high traffic by using low resources. Though most time Nginx is used to serve static contents.. There are two parts of this tutorial. In 1st part , I will show how to configure Nginx with PHP-FPM in latest Fedora 17 and in the 2nd part, I will show how to set up virtual hosts…

Open a terminal and login as root user

su -

Now install Ngix server….

yum install nginx

Create the system startup link and start the server

systemctl enable nginx.service
systemctl start nginx.service

Nginx installing is done. Let’s test it by typing http://localhost in any browser..
So, Nginx server is working properly. Now., I will install Mysql server in Fedora

yum install mysql mysql-server

Again create system startup link and start the mysql

systemctl enable mysqld.service
systemctl start mysqld.service

So, mysql server is done. Finally, install php5  PHP-FPM with other important modules

yum install php php-fpm php-common php-pecl-apc php-cli php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring pphp-mcrypt php-xml

Set your Timezone and other configurations in php.ini which is located at edit /etc/php.ini

date_timezone = "Asia/Dacca"
cgi.fix_pathinfo=0

Now again create startup link for PHP and start the PHP

systemctl enable php-fpm.service
systemctl start php-fpm.service

PHP installation is done. But you will have to configure the configuration file of Nginx server located at vi /etc/nginx/conf.d/default.conf so that it can serve PHP properly. Open configuration with any text editor and make it like following. .

#
# The default server
#
server {
listen 80;
server_name _;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}

error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}

# redirect server error pages to the static page /50x.html

In case, you are having problem in source code, visit this link: https://gist.github.com/3701091
To make sure that PHP is installed and running properly. Type following line..
echo ”<?php phpinfo; ?>” > /usr/share/html/phpinfo.php
Then, open a browser and type http://localhost/phpinfo.php.. You will get something like following picture.

So, PHP  is working in Nginx server. Another important thing is still left for web developing which is setting up virtual hosts.

First you will have to create virtual hosting directories:

mkdir /etc/nginx/sites-available
mkdir /etc/nginx/sites-enabled

Then again you will have to edit the conf file located at r /etc/nginx/nginx.conf. Add following line after the line for “include /etc/nginx/conf.d/*.conf”:
# Load virtual host configuration files.

include /etc/nginx/sites-enabled/*;

Now, You will have to define a virtual host for www.example.com. Create a configuration file.
vi /etc/nginx/sites-available/www.example.com
Now, add the following lines

server {
listen 80;
server_name www.example.com example.com;
#access_log /usr/share/nginx/html/example/logs/access.log;
#error_log /usr/share/nginx/html/example/logs/error.log;

location / {
root /usr/share/nginx/html/example;
index index.html index.htm index.php;
}

location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/example$fastcgi_scr$
}
}

In case, you are having problem in sourcecode, visit this link: https://gist.github.com/3701130
Save and close it. Now create a symbolic link of this configuration file to /etc/nginx/sites-enabled directory in order to enable it

cd /etc/nginx/sites-enabled/
sudo ln -s ../sites-available/www.example.com .

Update the /etc/hosts

127.0.0.1 www.example.com

Create a file called “index.php” in your site’s “example” directory located at /usr/share/nginx/html/example with the following contents:

<!--?php echo 'Everyhting is working well'; ?-->

Visit http://www.example.com/ in your browser, you will get this string “Everything is working well” as output. You can configure more to get maximum performance. Just follow this link: http://www.howtoforge.com/configuring-your-lemp-system-linux-nginx-mysql-php-fpm-for-maximum-performance.
Yes it’s done. 🙂

 

Eftakhairul Islam

Hi, I'm Eftakhairul Islam, a passionate Software Engineer, Hacker and Open Source Enthusiast. I enjoy writing about technical things, work in a couple of startup as a technical advisor and in my spare time, I contribute a lot of open source projects.

 

2 thoughts on “LEMP On Fedora 17 with setting up virtual host

Leave a Reply

Your email address will not be published. Required fields are marked *

 

Read previous post:
My undergrad research paper is published at Journal of Mechanics Engineering and Automation (JMEA)

Yes.. I am a bit happy today. My undergrad research paper is published in the journal: Volume 2, Number 5, 201of...

Close