How to Install Lighttpd With PHP5 FastCGI And MySQL on openSUSE 12.1
Security, speed, compliance, and flexibility — all of these describe lighttpd (pron. lighty) which is rapidly redefining efficiency of a webserver; as it is designed and optimized for high performance environments. With a small memory footprint compared to other web-servers, effective management of the cpu-load, and advanced feature set (FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting and many more) lighttpd is the perfect solution for every server that is suffering load problems. And best of all it’s Open Source licensed under the revised BSD license.
Here i will explain you the installation of Lighttd with PHP and MySQL on openSUSE 12.1.
To start off we will install Lighttpd.
Open up the Terminal and Swicth to root user.
[[email protected]~/]$ su
Type following Command on the Terminal and then press enter.
[[email protected]~/]# zypper in lighttpd
Start the Lighttpd by using the following command.
[[email protected]~/]# systemctl start lighttpd.service
To make the apache to start during the every boot, Type the following on terminal and hit Enter.
[[email protected]~/]# systemctl enable lighttpd.service
To make sure everything installed correctly we will now test Lighttpd to ensure it is working properly. Open up any web browser and then enter the following into the web address:
http://localhost/ or http://your.ip.addr.ess
You will get the web page saying “404 – Not Found” due to unavailability of index.html file in default document root, lighttpd’s default document root is /srv/www/htdocs on openSUSE; the configuration file is /etc/lighttpd/lighttpd.conf and additional configurations are stored in the /etc/lighttpd/conf.d/ directory.
Next is the installation of MySQL server, MySQL is available on openSUSE package; so just issue the following command to install it.
[[email protected]~/]# zypper in mysql-community-server mysql-community-server-client php5-mysql
Start MySQL server.
[[email protected]~/]# systemctl start mysql.service
To make the MySQL to start during the every boot, Type the following on terminal and hit Enter.
[[email protected]~/]# systemctl enable mysql.service
Next is to make the MySQL secure by using the mysql_secure_installation command.
This program enables you to improve the security of your MySQL installation in the following ways:
- You can set a password for
- You can remove
rootaccounts that are accessible from outside the local host.
- You can remove anonymous-user accounts.
- You can remove the
testdatabase (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with
[[email protected]~/]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): <– ENTER
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] <– ENTER
New password: <– yourrootsqlpassword
Re-enter new password: <– yourrootsqlpassword
Password updated successfully!
Reloading privilege tables..
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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
Remove anonymous users? [Y/n] <– ENTER
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] <– ENTER
By default, MySQL 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] <– ENTER
– Dropping test database…
– Removing privileges on test database…
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] <– ENTER
All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Next is to install PHP 5 on openSUSE with FastCGI, openSUSE provides a FastCGI-enabled PHP5 package. We can install by issuing the following command.
[[email protected]~/]# zypper in php5-fastcgi
Configuring PHP 5:
To enable PHP5 in Lighttpd, you will have to modify the configuration file /etc/php5/fastcgi/php.ini and uncomment the line cgi.fix_pathinfo=1:
[[email protected]~/]# vi /etc/php5/fastcgi/php.ini
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
To enable the FastCGI we need to edit the following file.
[[email protected]~/]# vi /etc/lighttpd/modules.conf
Uncomment the line [Line No:132].
Create and Enable the permission to run Lighttpd.
[[email protected]~/]# mkdir /var/run/lighttpd [[email protected]~/]# chown lighttpd.lighttpd /var/run/lighttpd
Edit the following file to configure FastCGI.
[[email protected]~/]# vi /etc/lighttpd/conf.d/fastcgi.conf
Add the following lines at the end of the file.
fastcgi.server = ( ".php" => ( "localhost" => ( "socket" => "/var/run/lighttpd/php-fastcgi.socket", "bin-path" => "/usr/bin/php-cgi", "max-procs" => 5, "bin-environment" => ( "PHP_FCGI_CHILDREN" => "16", "PHP_FCGI_MAX_REQUESTS" => "10000" ), "broken-scriptfilename" => "enable" ) ) )
Now restart all the required services.
[[email protected]~/]# systemctl restart lighttpd.service [[email protected]~/]# systemctl restart mysql.service
For testing the PHP, Place one PHP file on to the default directory of the Lighttpd. The document root of the default web site is /sr/www/htdocs. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.
In the terminal copy/paste the following line:
[[email protected]~/]# vi /sr/www/htdocs/info.php
This will open up a file called info.php.
Copy/Paste this line into the phpinfo file:
Save and close the file. use Esc + ;wq for saving the file.
Now open you’re web browser and type the following into the web address:
http://localhost/info.php or http://your.ip.add-ress/info.php
The page will look like below:
Scroll down the browser to modules section to check the support for the MySQL. you will get the screen like below.
Thanks to Christian Foronda for providing the FastCGI configuration.