Intro
I’ve seen a lot of people who have been put off getting a VPS or dedicated server because they’re not sure how to set up their website on it without paying extra for a control panel.
This is a quick guide to show how easy it is to get a PHP/MySQL website running on a Debian server with no control panel.
Software
The following software will be installed on your server
- Lighttpd
- PHP
- MySQL
- phpMyAdmin + mcrypt (optional)
You will need the following software on your machine (you can download the portable executable files so you don’t need to install them)
Connecting to your server
After downloading the software, you will need to log into the server via SSH, so open up PuTTY and enter your server IP address in. Leave the port as 22.
You will be prompted with the following text
login as:
so enter root then press enter and enter your password. Press enter again. You will then see the following
root@hostname:~#
Downloading the software
This means you’re logged into your server, via SSH, as the user root. The next step is to update the repositories for APT, which is basically a software package manager, update other packages on the server, and then install the software required, which is Lighttpd, PHP (FastCGI) and MySQL. Enter the following text at the command prompt in PuTTY (to paste in PuTTY, just right-click)
apt-get update && apt-get dist-upgrade && apt-get -y install lighttpd php5-cgi mysql-server php5-mysql
It will update APT, and then download the software (the -y switch is to skip confirmation). When it gets to installing MySQL, it will ask you to enter a password, and then confirm it. Choose something secure!
As soon as this finishes (it should only take a minute or two) your server will already be accessible on the web, but we haven’t configured PHP yet, so don’t upload any PHP files! To see your server, just put the IP address into your web browser (which hopefully will be Firefox!)
Once you’ve done that and been amazed at how easy it is (or just shrugged because you don’t care and just want to get on with uploading your site) we’ll get onto configuring Lighttpd to use PHP.
Configuring Lighttpd to use PHP
You can do the following using nano or some other command-line text editor if you’re familiar with it, but WinSCP is easier if you’re not.
Load up WinSCP (which you downloaded earlier) and enter your IP address, along with root as the username, and your password
Once you’ve logged in, navigate to the following path in the window on the right (using the folder icon with the arrow pointing upwards)
/etc/lighttpd/
In this folder, you will have a file called lighttpd.conf so double click on it, and it will open with Notepad. At the top of the file, you will see the following
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
# "mod_rewrite",
)
Add "mod_fastcgi", above # "mod_rewrite", so it now displays
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
"mod_fastcgi",
# "mod_rewrite",
)
When you’ve done this, scroll to the bottom of the file, copy and paste the following text into the file (right-click in PuTTY to paste)
fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/bin/php5-cgi",
"socket" => "/tmp/php.socket",
"max-procs" => 2,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "16",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"bin-copy-environment" => (
"PATH", "SHELL", "USER"
),
"broken-scriptfilename" => "enable"
)))
After pasting that, save the file by clicking on the floppy disk at the top of Notepad, then close it and go back to PuTTY. Type in the following
/etc/init.d/lighttpd restart
This will restart Lighttpd, and it will now process PHP files.
Testing
You can test this by uploading a PHP file into the public HTML directory in WinSCP. The directory to store your files in is
/var/www/
Create a new file in WinSCP in the folder above called phpinfo.php, and enter the following text inside it
<?php phpinfo(); ?>
Then save and close the file. Open up your web browser (if it wasn’t Firefox before, hopefully you downloaded Firefox and now it is!) and go to the following address
http://your-ip-address/phpinfo.php
You should see a file with loads of text that your probably don’t understand. That is good. If you just see <?php phpinfo(); ?> that isn’t so good, so post a comment on here and I will take a look.
Setting up a database via command-line
The next step is creating a database, which you can either do via command-line (which is very easy) or installing phpMyAdmin (which takes a bit longer but is nice if you’ve just come from a shared hosting environment using cPanel or DirectAdmin and are familiar with it, or you just like doing things through a GUI.
To create a MySQL database via command-line, just type the following into PuTTY
mysqladmin -u root -p create databasename
It will prompt you for your MySQL password, so just enter it and your database will be created!
Setting up phpMyAdmin (optional)
Creating a database through command-line is so easier, but some people might prefer to use phpMyAdmin, so just follow these easy steps.
Go to the phpMyAdmin download pageand download the English version in .tar.gz format, then upload it to /var/www/ using WinSCP, or use wget if know how to get the direct link and are familiar with it. When you have done that, go to PuTTY on your machine, and type the following
cd /var/www/
This will change the directory to your web folder, where you should have the phpMyAdmin file located (phpMyAdmin-3.4.6-english.tar.gz as of writing this). Type the following to extract the folder
tar -zxvf yourfilename.tar.gz
If you install phpMyAdmin, you will also need Mcrypt so type this in as well
apt-get install -y php5-mcrypt
Then, open up WinSCP, and rename the folder to whatever you want. For example, the folder might be called phpMyAdmin-3.4.6-english – you can rename this to phpmyadmin or simply phpma
Finished
That’s it! You’re now ready to upload your scripts to /var/www/ and install them like you would before. If you noticed any errors, or it isn’t working, just leave a comment!