Every young IT person will at last faced with the challenge of creating his own website. It could be a simple static site, managed by some static site generator (like Jekyll, Octopress, Pelican or some others examples). But few proud, claim that it's to easy and they would like to try something more complex like basic PHP CMS similar to , or even use a professional, enterprise-class frameworks like Laravel, Symfony or Zend.
Whatever they choose, they will need some tools to deal with showing to the whole world their new website project.
In this simple article, I'll show you how to build your own simple (and standard in these days) server configuration based on a LAMP, but those tools can be easily replaced with others technologies. For example, if you're interested in Django you could replace PHP language with more mature Python (of course some setting will vary a bit from content presented in this article, but in the end, setup will be made).
I think this is good, start example to play with :) Enjoy.
Or also you can use good, old school daemonsudo /etc/init.d/apache2 restart.
Now we take a peek at our server's version by writing apache2 -v in your console.
Now, if all went well, you could start your web browser with http://localhost/ to check if "It works!" appears to you :)
Add user to www-data group
Now we'd like to add your current user ($USER) to www-data group used by apache server. We will do this to prevent you from some error-access failures like user owner.
To check if your current user belongs to www-data group simply do:
sh
groups $USER
Now add existing user to www-data group.
sh
sudo usermod -a -G $USER www-data
Add a name to the server
Basic Apache configuration does not impose add the server name, but I really don't like to see some text like this below, when I reloading the server.
sh
* Restarting web server apache2AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message ...done.
That's why we will name it :)
sh
echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/servername.conf
Then we enable its name in for apache config by
sh
sudo a2enconf servername
Just restart the server to make sure that all is done correctly.
sh
$ sudo service apache2 restart * Restarting web server apache2 ...done.
...and now full smile should appear on your face :)
MySQL
MySQL is one of the most popular databases on the website market. So we will install it along.
During the installation process program ask you for the root password, so we write it and remember it for later use.
sh
sudo apt-get install mysql-server
Check the installed version
sh
mysql -V
That's it for the database server :)
PHP
Installation of the PHP interpreter isn't hard. One important thing is to install all modules related to our new setup, enable it, and configure to suit your needs. I'll show you most commonly used setup to save your precious time searching it through Internet.
Installation of PHP interpreter
Below we will install all useful modules, and enable them Apache server and PHP.
Into below Apache's PHP configuration file stored at /etc/php5/apache2/php.ini, it is worth to change the default parameters according to those presented below. There are most commonly changed variables for PHP for development purposes.
Next, we need to tell the server to use our new ServerName.
The best solution I know for development purposes involving dnsmasq, which I definitely recommend - you can find how to do it into article How to install dnsmasq or just add the name of the server to the /etc/hosts:
sh
echo "127.0.0.1 blog.loc" | sudo tee /etc/hosts
Then sudo service apache2 reload and open
Creating public_html directory for the user
Some people do not agree with it (mainly by security issues it can cause) but apache also support the old user catalog usually stored at ~/public_html, and it can be working like /var/www/html.
There are 2 different approaches to creating this directory.
First one assumes that User's catalog (~/public_html) should be owned by hir and hir alone, also with files permissions.
The second one presupposes that all files should be owned by www-data user. This solution is a bit better because other files migration not causes the access collisions.
To enable this magical directory we need to edit /etc/apache2/mods-enabled/php5.conf (it may require sudo privileges to save it).
Into this file, we need to comment some lines (##) like in below snippet.
apache
<FilesMatch ".+\.ph(p[345]?|t|tml)$"> SetHandler application/x-httpd-php</FilesMatch><FilesMatch ".+\.phps$"> SetHandler application/x-httpd-php-source # Deny access to raw php sources by default # To re-enable it's recommended to enable access to the files # only in specific virtual host or directory Order Deny,Allow Deny from all</FilesMatch># Deny access to files without filename (e.g. '.php')<FilesMatch "^\.ph(p[345]?|t|tml|ps)$"> Order Deny,Allow Deny from all</FilesMatch># Running PHP scripts in user directories is disabled by default## To re-enable PHP in user directories comment the following lines# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it# prevents .htaccess files from disabling it.##<IfModule mod_userdir.c>## <Directory /home/*/public_html>## php_admin_flag engine Off## </Directory>##</IfModule>
Now we set server so that we can throw files into the ~/public_html directory. It may be necessary to give the appropriate rights for the directory, so we need to take this into consideration as well.
Next we are open the file and we can add our path to public_html inside:
apache
<Directory /home/maciej/public_html/> Options Indexes FollowSymLinks AllowOverride All Require all granted</Directory>
Restart and we are home.
May occur the problem like "index.php not found"
plaintext
Not FoundThe requested URL /index.php was not found on this server.
Probably the cause of that is rewriting the URL into for example:
Joomla: Global config > Adjust rewriting URLs and set for OFF
Problem #1
Once you install the module, the module will be available in the /etc/apache2/mods-available directory. You can use the a2enmod command to enable a module. You can use the a2dismod command to disable a module. Once you enable the module, the module will be available in the /etc/apache2/mods-enabled directory.