Develop faster in Fedora with a local LAMP

Are you a web developer or designer? Do you want a local LAMP server for all your building and experimenting needs? Do you often use WordPress but up until now all your work has been done online, tying you down to the speed of your internet connection to get work done? Well no more!

Why install a Fedora LAMP server on your desktop?

  • Save you upload and general waiting time every change you make while developing themes and plugins
  • Allow you to test new themes and plugins safely without the worry of messing up actual websites
  • Let you experiment with more than just WordPress – remember other CMS are available!
  • Give you the chance the say the word flamp…

Ok so really there are only three reasons to do this but they’re pretty important! Anything that saves you time is a blessing (it potentially saves you money) and frees you up to test new things without the immediate worry of errors or downtime.

And who knows for sure about the last reason anyway…

Now you’re totally sold on setting this up let’s get started.

Light the Lamp: Installation

Start by installing your LAMP server (Linux Apache Mysql PHP) and PHPMyAdmin so we can work on our mysql databases in browser.

Firstly, lets get root and I prefer su to sudo. I think it saves time when you’ve got a few commands to use. Type in the following then enter your root password (note: for the command below you enter your root password, not your password)

su -

Now we’re root we can get cracking!

yum install httpd mysql mysql-server php php-mysql phpmyadmin

Now you’re Lamp server is installed we need to start it, and tell it to start at boot from now on. Again an easy few commands. First lets start apache (or the http demon) and mysql.

systemctl enable httpd.service && systemctl start httpd
systemctl enable mysqld.service && systemctl start mysqld

The first have of these commands “systemctl enable httpd.service” creates a symlink which will start this service at boot from now on. Changing enable to disable will remove it. The second half saves us the need to reboot at starts the service right away.

Now lets check how we’re doing. Go to http://localhost in your browser, if the page you see looks something like below congratulations – you’ve got apache running!

Fedora LAMP welcome page

Let’s check mysql too. Open up a terminal and punch in the following:

mysqladmin version status

If all is well the reponse will look something like this:

LAMP Mysql status

Set mysql root password

Before we go any further we need to set a root password for mysql. Don’t panic, it’s quite easy:

Go into the mysql command line to set the root password.

mysql -u root

Set the password of the root user in mysql at the mysql prompt. Do not forget to end your mysql command with a semicolon:

mysql> SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘yourpassword’);

If it is successful, this message appears:

Query OK, 0 rows affected (0.00 sec)

Exit the mysql prompt

mysql> quit

Now you should be able to go to http://localhost/phpmyadmin and login as root with the password you just set.

Right, we have everything installed and running. Now time to make it workable for us and install wordpress itself.

/home isn’t where your root is

I’ve read a lot of forum posts about people trying to serve web files from their home directory.. It always seems to go badly if at all. Daft when it’s so easy to add yourself to the web server’s group (cunningly named apache) and then mod the /var/www/html files a little.

So first, add yourself to the apache group with the following command, changing bdavis to whatever your username is. Don’t forget we’re still root, otherwise these commands need ‘sudo’ before them.

usermod -a -G apache bdavis

Now logout.

And back in again.

We now need to set your document root directory as accessible by you. Again, a simple set of commands to do this:

chown apache:apache /var/www/html
chmod -R 775 /var/www
chmod -R g+s /var/www

Now you can edit and create in your document root to your hearts content! So lets put wordpress in it!

Installing WordPress

Kudos here goes to the lovely people at WordPress for making it so ridiculously easy to install wordpress. So little faffing is required it’s brilliant.

Firstly you’ll need the latest version of WP from wordpress.org. Download it and save it somewhere sensible.

Open up your saved zip (or taf.gz) and extract it to your /var/www/html folder. I’d recommend you change the name of the wordpress folder to wp just to keep things short and simple.

Screenshot from 2015-04-01 16:15:53
Now, before we run the WP setup we need to setup a database for wordpress to use so. So fire up a new browser tab and go to http://localhost/phpmyadmin. Login as root (with the password you set earlier. Once logged in create a new database by clicking new in the top left as shown below:

Screenshot from 2015-04-01 16:33:12

 

Make yourself a new database, in the interests of simplicity I am just going to call mine wordpress:

Screenshot from 2015-04-01 16:36:39

Click the create button and voila – you made a database! Now we’re reading to crack on with the wordpress install.

In your browser go to http://localhost/wp (or whatever you named your wordpress folder) and click the button to get started. Once you’ve done that you should see a page like this:

Screenshot from 2015-04-01 16:39:21

Rather helpfully most of the values are already there for you. All you need to change is the password to match the mysql password you set earlier then press Submit. I won’t go over all the rest of setting up wordpress, it’s pretty easy and there are already great sources of information to help you ou online. One thing I will say though is make sure you untick the “Allow google to index your site” caveat during installation. You don’t want to advertise your own hosted blog do you?

There is one last thing I can recommend you do before I can call this setup finish. Allow uploads – specifically for theme installations and plugins. Fedora’s SELinux is quite protective so you need to tell it what’s allowed. Enter this in a terminal (matching the location to wherever you’ve got your web files) to stop SELinux having a hissy fit every time you want to install a new plugin or theme:

setsebool -P httpd_builtin_scripting on
setsebool -P allow_httpd_sys_script_anon_write on

Now the slightly ball-breaking bit, you need to allow each directory access to upload and extract to. I’d focus on just themes and plugins for now, remember to change the location to fit your chosen locations:

semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/wp/wp-content/themes'
restorecon -v '/var/www/html/wp/wp-content/themes'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/wp/wp-content/plugins'
restorecon -v '/var/www/html/wp/wp-content/plugins'

And finally you’re good to go! Your LAMP is setup and secure and ready for some development.

I hope you’ve found this useful and will enjoy developing and designing to your hearts content.


Leave a reply